Skip to content

Commit

Permalink
More verbose update install status + bug fix
Browse files Browse the repository at this point in the history
- Fix updater crash if there is no "Configs" folder in the YAMDCC install directory (e.g. if the user compiles YAMDCC themselves or deletes/moves the "Configs" folder)
  • Loading branch information
Sparronator9999 committed Feb 19, 2025
1 parent 046ba51 commit 8f3925b
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 120 deletions.
32 changes: 10 additions & 22 deletions YAMDCC.Common/Dialogs/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ protected override CreateParams CreateParams
}
#endregion

public TResult Result { get; set; }
private readonly Timer DisplayTimer = new();

private readonly Func<TResult> DoWork;
public TResult Result { get; set; }

private readonly Timer DisplayTimer = new();
public Func<TResult> DoWork { get; set; }

public string Caption
{
Expand All @@ -49,30 +49,13 @@ public string Caption
}

/// <summary>
/// Initialises a new instance of the <see cref="ProgressDialog"/> class.
/// Initialises a new instance of the <see cref="ProgressDialog{TResult}"/> class.
/// </summary>
/// <param name="caption">
/// The window caption to use.
/// </param>
/// <param name="doWork">
/// The <see cref="Func{T}"/> to run when showing this window.
/// </param>
/// <exception cref="ArgumentNullException"/>
public ProgressDialog(string caption, Func<TResult> doWork)
public ProgressDialog()
{
Opacity = 0;
InitializeComponent();

// sanity check
if (doWork is null)
{
throw new ArgumentNullException(nameof(doWork), "The doWork parameter was null.");
}
DoWork = doWork;

// set title text
Caption = caption;

pbProgress.Style = ProgressBarStyle.Marquee;

DisplayTimer.Interval = 1000;
Expand All @@ -81,6 +64,11 @@ public ProgressDialog(string caption, Func<TResult> doWork)

private async void OnLoad(object sender, EventArgs e)
{
// sanity check
if (DoWork is null)
{
throw new InvalidOperationException("The DoWork property is null.");
}
DisplayTimer.Start();
Result = await Task.Run(DoWork);
Close();
Expand Down
56 changes: 33 additions & 23 deletions YAMDCC.ConfigEditor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ private void MainWindow_Load(object sender, EventArgs e)
IPCClient.Error += new EventHandler<PipeErrorEventArgs<ServiceResponse, ServiceCommand>>(IPCError);
IPCClient.Start();

ProgressDialog<bool> dlg = new("Connecting to YAMDCC service...",
() => !IPCClient.WaitForConnection(5000));
ProgressDialog<bool> dlg = new()
{
Caption = "Connecting to YAMDCC service...",
DoWork = () => !IPCClient.WaitForConnection(5000)
};
dlg.ShowDialog();

if (dlg.Result)
Expand Down Expand Up @@ -527,8 +530,10 @@ private void tsiStopSvc_Click(object sender, EventArgs e)
IPCClient.Stop();
Hide();

ProgressDialog<bool> dlg = new(Strings.GetString("dlgSvcStopping"),
static () =>
ProgressDialog<bool> dlg = new()
{
Caption = Strings.GetString("dlgSvcStopping"),
DoWork = static () =>
{
if (!Utils.StopService("yamdccsvc"))
{
Expand All @@ -537,7 +542,8 @@ private void tsiStopSvc_Click(object sender, EventArgs e)
}
Utils.ShowInfo(Strings.GetString("dlgSvcStopped"), "Success");
return true;
});
}
};
dlg.ShowDialog();

Close();
Expand All @@ -558,32 +564,36 @@ private void tsiUninstall_Click(object sender, EventArgs e)
IPCClient.Stop();
Hide();

ProgressDialog<bool> dlg = new(Strings.GetString("dlgSvcUninstalling"), () =>
ProgressDialog<bool> dlg = new()
{
// Apparently this fixes the YAMDCC service not uninstalling
// when YAMDCC is launched by certain means
if (Utils.StopService("yamdccsvc"))
Caption = Strings.GetString("dlgSvcUninstalling"),
DoWork = () =>
{
if (Utils.UninstallService("yamdccsvc"))
// Apparently this fixes the YAMDCC service not uninstalling
// when YAMDCC is launched by certain means
if (Utils.StopService("yamdccsvc"))
{
// Delete the auto-update scheduled task
Utils.RunCmd("updater", "--setautoupdate false");

// Only delete service data if the
// service uninstalled successfully
if (delData)
if (Utils.UninstallService("yamdccsvc"))
{
Directory.Delete(Paths.Data, true);
// Delete the auto-update scheduled task
Utils.RunCmd("updater", "--setautoupdate false");

// Only delete service data if the
// service uninstalled successfully
if (delData)
{
Directory.Delete(Paths.Data, true);
}
Utils.ShowInfo(Strings.GetString("dlgSvcUninstalled"), "Success");
return true;
}
Utils.ShowInfo(Strings.GetString("dlgSvcUninstalled"), "Success");
return true;
Utils.ShowError(Strings.GetString("dlgUninstallErr"));
return false;
}
Utils.ShowError(Strings.GetString("dlgUninstallErr"));
Utils.ShowError(Strings.GetString("dlgSvcStopErr"));
return false;
}
Utils.ShowError(Strings.GetString("dlgSvcStopErr"));
return false;
});
};
dlg.ShowDialog();
Close();
}
Expand Down
54 changes: 31 additions & 23 deletions YAMDCC.ConfigEditor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,29 @@ private static void Main()
Strings.GetString("dlgSvcNotInstalled"), "Service not installed",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
ProgressDialog<bool> dlg = new(Strings.GetString("dlgSvcInstalling"), () =>
ProgressDialog<bool> dlg = new()
{
if (Utils.InstallService("yamdccsvc"))
Caption = Strings.GetString("dlgSvcInstalling"),
DoWork = () =>
{
if (Utils.StartService("yamdccsvc"))
if (Utils.InstallService("yamdccsvc"))
{
return true;
if (Utils.StartService("yamdccsvc"))
{
return true;
}
else
{
Utils.ShowError(Strings.GetString("dlgSvcStartCrash"));
}
}
else
{
Utils.ShowError(Strings.GetString("dlgSvcStartCrash"));
Utils.ShowError(Strings.GetString("dlgSvcInstallFail"));
}
return false;
}
else
{
Utils.ShowError(Strings.GetString("dlgSvcInstallFail"));
}
return false;
});
};
dlg.ShowDialog();

if (dlg.Result)
Expand Down Expand Up @@ -114,21 +118,25 @@ private static void Main()
Strings.GetString("dlgSvcNotRunning"), "Service not running",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
ProgressDialog<bool> dlg = new(Strings.GetString("dlgSvcStarting"), () =>
{
if (Utils.StartService("yamdccsvc"))
{
return false;
}
else
ProgressDialog<bool> dlg = new()
{
Utils.ShowError(Strings.GetString("dlgSvcStartCrash"));
return true;
}
});
Caption = Strings.GetString("dlgSvcStarting"),
DoWork = () =>
{
if (Utils.StartService("yamdccsvc"))
{
return false;
}
else
{
Utils.ShowError(Strings.GetString("dlgSvcStartCrash"));
return true;
}
}
};
dlg.ShowDialog();

if ((bool)dlg.Result)
if (dlg.Result)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion YAMDCC.ECAccess/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public bool Install()
AdvApi32.ServiceType.KernelDriver,
AdvApi32.ServiceStartType.DemandStart,
AdvApi32.ServiceError.Normal,
DriverPath, null, null, null, null, null);
fullPath, null, null, null, null, null);

if (hSvc == IntPtr.Zero)
{
Expand Down
3 changes: 3 additions & 0 deletions YAMDCC.ECAccess/YAMDCC.ECAccess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugType>none</DebugType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.ServiceProcess" />
</ItemGroup>
<ItemGroup>
<None Update="WinRing0.sys">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
66 changes: 37 additions & 29 deletions YAMDCC.Service/FanControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,45 +86,53 @@ public FanControlService(Logger logger)
#region Events
protected override void OnStart(string[] args)
{
Log.Info(Strings.GetString("svcStarting"));

// Install WinRing0 to get EC access
try
{
Log.Info(Strings.GetString("drvLoad"));
if (!_EC.LoadDriver())
Log.Info(Strings.GetString("svcStarting"));

// Install WinRing0 to get EC access
try
{
throw new Win32Exception(_EC.GetDriverError());
Log.Info(Strings.GetString("drvLoad"));
if (!_EC.LoadDriver())
{
throw new Win32Exception(_EC.GetDriverError());
}
}
}
catch (Win32Exception)
{
Log.Fatal(Strings.GetString("drvLoadFail"));
_EC.UnloadDriver();
ExitCode = 1;
throw;
}
Log.Info(Strings.GetString("drvLoadSuccess"));
catch (Win32Exception)
{
Log.Fatal(Strings.GetString("drvLoadFail"));
_EC.UnloadDriver();
ExitCode = 1;
throw;
}
Log.Info(Strings.GetString("drvLoadSuccess"));

// Load the last applied YAMDCC config.
bool confLoaded = LoadConf();
// Load the last applied YAMDCC config.
bool confLoaded = LoadConf();

// Set up IPC server
Log.Info("Starting IPC server...");
IPCServer.Start();
// Set up IPC server
Log.Info("Starting IPC server...");
IPCServer.Start();

Log.Info(Strings.GetString("svcStarted"));
Log.Info(Strings.GetString("svcStarted"));

// Attempt to read default fan curve if it's pending:
if (CommonConfig.GetECtoConfState() == ECtoConfState.PostReboot)
{
ECtoConf();
}
// Attempt to read default fan curve if it's pending:
if (CommonConfig.GetECtoConfState() == ECtoConfState.PostReboot)
{
ECtoConf();
}

// Apply the fan curve and charging threshold:
if (confLoaded)
// Apply the fan curve and charging threshold:
if (confLoaded)
{
ApplyConf();
}
}
catch (Exception ex)
{
ApplyConf();
Log.Fatal(Strings.GetString("svcException", ex));
throw;
}
}

Expand Down
Loading

0 comments on commit 8f3925b

Please sign in to comment.