From 7665e02f2cf038443af3a3b85a0a0b71002161aa Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:01:37 +0100 Subject: [PATCH 1/5] Service installer will now ask to remove old ones --- src/Tgstation.Server.Host.Service/Program.cs | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 9056e67f70..f313cba287 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -118,6 +118,32 @@ namespace Tgstation.Server.Host.Service { if (Uninstall) return; // oh no, it's retarded... + + // First check if the service already exists + foreach (ServiceController sc in ServiceController.GetServices()) + { + if (sc.ServiceName == "tgstation-server" || sc.ServiceName == "tgstation-server-4") + { + DialogResult result = MessageBox.Show($"You already have another TGS service installed ({sc.ServiceName}). Would you like to uninstall it now? Pressing \"No\" will cancel this install.", "TGS Service", MessageBoxButtons.YesNo); + if (result != DialogResult.Yes) + { + Environment.Exit(1); + return; // is this needed after exit? + } + + // Stop it first to give it some cleanup time + if (sc.Status == ServiceControllerStatus.Running) + sc.Stop(); + + // And remove it + using (ServiceInstaller si = new ServiceInstaller()) { + si.Context = new InstallContext($"old-{sc.ServiceName}-uninstall.log", null); + si.ServiceName = ServerService.Name; + si.Uninstall(null); + } + } + } + using (var processInstaller = new ServiceProcessInstaller()) using (var installer = new ServiceInstaller()) { From 48a6e5e8e7a4b3f7145628748fd0c7dcf964b3dd Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:04:07 +0100 Subject: [PATCH 2/5] Style --- src/Tgstation.Server.Host.Service/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index f313cba287..62e4678903 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -136,7 +136,8 @@ namespace Tgstation.Server.Host.Service sc.Stop(); // And remove it - using (ServiceInstaller si = new ServiceInstaller()) { + using (ServiceInstaller si = new ServiceInstaller()) + { si.Context = new InstallContext($"old-{sc.ServiceName}-uninstall.log", null); si.ServiceName = ServerService.Name; si.Uninstall(null); From 6fc13cff70980a4dae1046efaddf7d2f1680a17a Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:36:16 +0100 Subject: [PATCH 3/5] Try this --- src/Tgstation.Server.Host.Service/Program.cs | 34 +++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 62e4678903..40baaadd9d 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -120,27 +120,29 @@ namespace Tgstation.Server.Host.Service return; // oh no, it's retarded... // First check if the service already exists - foreach (ServiceController sc in ServiceController.GetServices()) + if (Environment.UserInteractive) { - if (sc.ServiceName == "tgstation-server" || sc.ServiceName == "tgstation-server-4") + foreach (ServiceController sc in ServiceController.GetServices()) { - DialogResult result = MessageBox.Show($"You already have another TGS service installed ({sc.ServiceName}). Would you like to uninstall it now? Pressing \"No\" will cancel this install.", "TGS Service", MessageBoxButtons.YesNo); - if (result != DialogResult.Yes) + if (sc.ServiceName == "tgstation-server" || sc.ServiceName == "tgstation-server-4") { - Environment.Exit(1); - return; // is this needed after exit? - } + DialogResult result = MessageBox.Show($"You already have another TGS service installed ({sc.ServiceName}). Would you like to uninstall it now? Pressing \"No\" will cancel this install.", "TGS Service", MessageBoxButtons.YesNo); + if (result != DialogResult.Yes) + { + return; // is this needed after exit? + } - // Stop it first to give it some cleanup time - if (sc.Status == ServiceControllerStatus.Running) - sc.Stop(); + // Stop it first to give it some cleanup time + if (sc.Status == ServiceControllerStatus.Running) + sc.Stop(); - // And remove it - using (ServiceInstaller si = new ServiceInstaller()) - { - si.Context = new InstallContext($"old-{sc.ServiceName}-uninstall.log", null); - si.ServiceName = ServerService.Name; - si.Uninstall(null); + // And remove it + using (ServiceInstaller si = new ServiceInstaller()) + { + si.Context = new InstallContext($"old-{sc.ServiceName}-uninstall.log", null); + si.ServiceName = ServerService.Name; + si.Uninstall(null); + } } } } From a68073769bbfa8fffe8f1c8db2b5e00f83cdf2ba Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:07:20 +0100 Subject: [PATCH 4/5] Nits --- src/Tgstation.Server.Host.Service/Program.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 40baaadd9d..33f40c9ba2 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -121,20 +121,19 @@ namespace Tgstation.Server.Host.Service // First check if the service already exists if (Environment.UserInteractive) - { foreach (ServiceController sc in ServiceController.GetServices()) - { if (sc.ServiceName == "tgstation-server" || sc.ServiceName == "tgstation-server-4") { DialogResult result = MessageBox.Show($"You already have another TGS service installed ({sc.ServiceName}). Would you like to uninstall it now? Pressing \"No\" will cancel this install.", "TGS Service", MessageBoxButtons.YesNo); if (result != DialogResult.Yes) - { return; // is this needed after exit? - } // Stop it first to give it some cleanup time if (sc.Status == ServiceControllerStatus.Running) + { sc.Stop(); + sc.WaitForStatus(ServiceControllerStatus.Stopped); + } // And remove it using (ServiceInstaller si = new ServiceInstaller()) @@ -144,8 +143,6 @@ namespace Tgstation.Server.Host.Service si.Uninstall(null); } } - } - } using (var processInstaller = new ServiceProcessInstaller()) using (var installer = new ServiceInstaller()) From f94d04488c594c395b9bf9d67d76317b1b15d826 Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:17:25 +0100 Subject: [PATCH 5/5] I am not smart --- src/Tgstation.Server.Host.Service/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 33f40c9ba2..673accd9a0 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -139,7 +139,7 @@ namespace Tgstation.Server.Host.Service using (ServiceInstaller si = new ServiceInstaller()) { si.Context = new InstallContext($"old-{sc.ServiceName}-uninstall.log", null); - si.ServiceName = ServerService.Name; + si.ServiceName = sc.ServiceName; si.Uninstall(null); } }