From 11034784f6016bff9e8bfb2b420a6eddf21eac1a Mon Sep 17 00:00:00 2001 From: Sparronator9999 <86388887+Sparronator9999@users.noreply.github.com> Date: Sat, 7 Sep 2024 21:30:50 +1000 Subject: [PATCH] Further changes to service stop/uninstall behaviour - Fail uninstalling the service if it couldn't be stopped first - Add error message to "Stop service" button if service failed to stop --- YAMDCC.GUI/MainWindow.cs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/YAMDCC.GUI/MainWindow.cs b/YAMDCC.GUI/MainWindow.cs index d33b00e..40cacae 100644 --- a/YAMDCC.GUI/MainWindow.cs +++ b/YAMDCC.GUI/MainWindow.cs @@ -361,7 +361,12 @@ private void tsiStopSvc_Click(object sender, EventArgs e) IPCClient.Stop(); Close(); - Utils.StopService("yamdccsvc"); + + if (!Utils.StopService("yamdccsvc")) + { + MessageBox.Show("Failed to stop the YAMDCC service!", + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } @@ -379,24 +384,28 @@ private void tsiUninstall_Click(object sender, EventArgs e) IPCClient.Stop(); Close(); - if (!Utils.StopService("yamdccsvc")) + // Apparently this fixes the YAMDCC service not uninstalling + // when YAMDCC is launched by certain means + if (Utils.StopService("yamdccsvc")) { - MessageBox.Show("Failed to stop the YAMDCC service!", - "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - if (Utils.UninstallService("yamdccsvc")) - { - // Only delete service data if the - // service uninstalled successfully - if (delData) + if (Utils.UninstallService("yamdccsvc")) + { + // Only delete service data if the + // service uninstalled successfully + if (delData) + { + Directory.Delete(DataPath, true); + } + } + else { - Directory.Delete(DataPath, true); + MessageBox.Show("Failed to uninstall the YAMDCC service!", + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { - MessageBox.Show("Failed to uninstall the YAMDCC service!", + MessageBox.Show("Failed to stop the YAMDCC service!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }