Skip to content

Commit

Permalink
Start YAMDCC upon successful service installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparronator9999 committed Sep 7, 2024
1 parent 02ffb4f commit 95dff7c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
83 changes: 46 additions & 37 deletions YAMDCC.GUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 0 additions & 4 deletions YAMDCC.GUI/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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.</value>
</data>
<data name="svcInstallSuccess" xml:space="preserve">
<value>Service installed successfully!
Please run YAMDCC again to start using it.</value>
</data>
<data name="svcNotFound" xml:space="preserve">
<value>The YAMDCC Service is not installed.
Expand Down

0 comments on commit 95dff7c

Please sign in to comment.