diff --git a/YAMDCC.GUI/Program.cs b/YAMDCC.GUI/Program.cs index e25a721..bbbc93a 100644 --- a/YAMDCC.GUI/Program.cs +++ b/YAMDCC.GUI/Program.cs @@ -56,74 +56,83 @@ private static void Main() return; } - if (Utils.ServiceExists("yamdccsvc")) + if (!Utils.ServiceExists("yamdccsvc")) { - ServiceController yamdccSvc = new("yamdccsvc"); - - // Check if the service is stopped: - try + if (File.Exists("yamdccsvc.exe")) { - if (yamdccSvc.Status == ServiceControllerStatus.Stopped) + if (MessageBox.Show( + Strings.GetString("svcNotInstalled"), + "Service not installed", + MessageBoxButtons.YesNo, + MessageBoxIcon.Information) == DialogResult.Yes) { - if (MessageBox.Show( - Strings.GetString("svcNotRunning"), - "Service not running", MessageBoxButtons.YesNo, - MessageBoxIcon.Information) == DialogResult.Yes) + if (Utils.InstallService("yamdccsvc")) { - if (!Utils.StartService("yamdccsvc")) + if (Utils.StartService("yamdccsvc")) + { + // Start the program when the service finishes starting: + Application.Run(new MainWindow()); + } + else { MessageBox.Show(Strings.GetString("svcErrorCrash"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; } } else { - return; + MessageBox.Show(Strings.GetString("svcInstallFail"), + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + return; } - catch (Exception ex) + else { - MessageBox.Show( - string.Format(CultureInfo.InvariantCulture, Strings.GetString("svcErrorStart"), ex), + MessageBox.Show(Strings.GetString("svcNotFound"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - finally - { - yamdccSvc.Close(); - } } - else // Service doesn't exist + + // Check if the service is stopped: + ServiceController yamdccSvc = new("yamdccsvc"); + try { - if (File.Exists("yamdccsvc.exe")) + ServiceControllerStatus status = yamdccSvc.Status; + yamdccSvc.Close(); + + if (status == ServiceControllerStatus.Stopped) { if (MessageBox.Show( - Strings.GetString("svcNotInstalled"), - "Service not installed", - MessageBoxButtons.YesNo, + Strings.GetString("svcNotRunning"), + "Service not running", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { - if (Utils.InstallService("yamdccsvc")) - { - MessageBox.Show(Strings.GetString("svcInstallSuccess"), - "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else + if (!Utils.StartService("yamdccsvc")) { - MessageBox.Show(Strings.GetString("svcInstallFail"), + MessageBox.Show(Strings.GetString("svcErrorCrash"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } } + else + { + return; + } } - else - { - MessageBox.Show(Strings.GetString("svcNotFound"), - "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + } + catch (Exception ex) + { + MessageBox.Show( + string.Format(CultureInfo.InvariantCulture, Strings.GetString("svcErrorStart"), ex), + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + finally + { + yamdccSvc?.Close(); + } // Start the program when the service finishes starting: Application.Run(new MainWindow()); diff --git a/YAMDCC.GUI/Strings.resx b/YAMDCC.GUI/Strings.resx index 8b2dfca..67dc35b 100644 --- a/YAMDCC.GUI/Strings.resx +++ b/YAMDCC.GUI/Strings.resx @@ -189,10 +189,6 @@ Details (provide this when reporting bugs): Try running the YAMDCC configurator again, and if the service installation fails again, open a bug report with this error. - - - Service installed successfully! -Please run YAMDCC again to start using it. The YAMDCC Service is not installed.