diff --git a/build/package/winget/Tgstation.Server.Host.Service.Wix.Extensions/InstallationExtensions.cs b/build/package/winget/Tgstation.Server.Host.Service.Wix.Extensions/InstallationExtensions.cs index baee0364b0..d6a46b7700 100644 --- a/build/package/winget/Tgstation.Server.Host.Service.Wix.Extensions/InstallationExtensions.cs +++ b/build/package/winget/Tgstation.Server.Host.Service.Wix.Extensions/InstallationExtensions.cs @@ -1,6 +1,7 @@ namespace Tgstation.Server.Host.Service.Wix.Extensions { using System; + using System.IO; using System.ServiceProcess; using Tgstation.Server.Host.Common; @@ -12,6 +13,12 @@ /// public static class InstallationExtensions { + /// + /// Package name + /// + /// As much as I'd like to use Tgstation.Server.Common.Constants.CanonicalPackageName here, attempting to reference it makes Tgstation.Server.Migrator.Comms fail due to referencing the net2.0 version of that library. EVEN THOUGH IT'S A TRANSITIVE DEPENDENCY OF Tgstation.Server.Client!!!!! If that dead-ass tool has been removed, feel free to do this. + const string CanonicalPackageName = "tgstation-server"; + /// /// Attempts to detach stop the existing tgstation-server service if it exists. /// @@ -28,9 +35,6 @@ session.Log("Begin DetachStopTgsServiceIfRunning"); ServiceController serviceController = null; - // As much as I'd like to use Tgstation.Server.Common.Constants.CanonicalPackageName here, attempting to reference it make Tgstation.Server.Migrator.Comms fail due to referencing the net2.0 version of that library. EVEN THOUGH IT'S A TRANSITIVE DEPENDENCY OF Tgstation.Server.Client!!!!! - // If that dead-ass tool has been removed, feel free to do this - const string CanonicalPackageName = "tgstation-server"; session.Log($"Searching for {CanonicalPackageName} service..."); try { @@ -76,5 +80,55 @@ return ActionResult.Failure; } } + + /// + /// Attempts to copy the initial config to the production config if necessary. + /// + /// The installer . + /// The of the custom action. + [CustomAction] + public static ActionResult ApplyProductionAppsettingsIfNonExistant(Session session) + { + if (session == null) + throw new ArgumentNullException(nameof(session)); + + try + { + session.Log("Begin ApplyProductionAppsettingsIfNonExistant"); + var programDataDirectory = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), + CanonicalPackageName); + var initialAppSettingsPath = Path.Combine(programDataDirectory, "appsettings.Initial.yml"); + var productionAppSettingsPath = Path.Combine(programDataDirectory, "appsettings.Production.yml"); + + var initialAppSettingsExists = File.Exists(initialAppSettingsPath); + var productionAppSettingsExists = File.Exists(productionAppSettingsPath); + + if (productionAppSettingsExists) + session.Log("appsettings.Production.yml present"); + else + session.Log("appsettings.Production.yml NOT present"); + + if (!initialAppSettingsExists) + session.Log("appsettings.Initial.yml NOT present!"); + else + { + session.Log("appsettings.Initial.yml present"); + if (!productionAppSettingsExists) + { + session.Log("Copying initial settings to production settings..."); + File.Copy(initialAppSettingsPath, productionAppSettingsPath); + return ActionResult.Success; + } + } + + return ActionResult.NotExecuted; + } + catch (Exception ex) + { + session.Log($"Exception in ApplyProductionAppsettingsIfNonExistant:{Environment.NewLine}{ex}"); + return ActionResult.Failure; + } + } } } diff --git a/build/package/winget/Tgstation.Server.Host.Service.Wix/Package.wxs b/build/package/winget/Tgstation.Server.Host.Service.Wix/Package.wxs index f6897aab0f..95da39d252 100644 --- a/build/package/winget/Tgstation.Server.Host.Service.Wix/Package.wxs +++ b/build/package/winget/Tgstation.Server.Host.Service.Wix/Package.wxs @@ -7,6 +7,7 @@ + @@ -16,6 +17,7 @@ + @@ -79,7 +81,7 @@ - +