Skip to content

Commit

Permalink
More refactors + bug fix
Browse files Browse the repository at this point in the history
- Fix EC-to-Config button not being disabled when no config is loaded

- Rename Constants.cs to Paths.cs and move more commonly used paths to it
  • Loading branch information
Sparronator9999 committed Dec 5, 2024
1 parent 2b5198f commit a96c660
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 55 deletions.
36 changes: 18 additions & 18 deletions YAMDCC.GUI/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 17 additions & 15 deletions YAMDCC.GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,26 @@ private void MainWindow_Load(object sender, EventArgs e)
return;
}

LoadConf(Constants.CurrentConfigPath);
LoadConf(Paths.CurrentConfig);

if (Config is not null && Config.KeyLightConf is not null)
{
SendServiceMessage(new ServiceCommand(Command.GetKeyLightBright, ""));
}

if (File.Exists(Path.Combine(Constants.DataPath, "ECToConfFail")))
if (File.Exists(Paths.ECToConfFail))
{
Utils.ShowError(Strings.GetString("dlgECtoConfError", Constants.LogPath));
Utils.ShowError(Strings.GetString("dlgECtoConfError", Paths.Logs));
}
else if (File.Exists(Path.Combine(Constants.DataPath, "ECToConfSuccess")))
else if (File.Exists(Paths.ECToConfSuccess))
{
MessageBox.Show(Strings.GetString("dlgECtoConfSuccess"),
"Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
try
{
File.Delete(Path.Combine(Constants.DataPath, "ECToConfSuccess"));
File.Delete(Path.Combine(Constants.DataPath, "ECToConfFail"));
File.Delete(Paths.ECToConfSuccess);
File.Delete(Paths.ECToConfFail);
}
catch (DirectoryNotFoundException) { }
}
Expand Down Expand Up @@ -445,13 +445,13 @@ private void tsiProfDel_Click(object sender, EventArgs e)
DelFanProfile();
}

private void tsiGetDefaultCurve_Click(object sender, EventArgs e)
private void tsiECtoConf_Click(object sender, EventArgs e)
{
if (MessageBox.Show(Strings.GetString("dlgECtoConfStart"),
"Default fan profile from EC?", MessageBoxButtons.YesNo,
MessageBoxIcon.Information) == DialogResult.Yes)
{
StreamWriter sw = new(Path.Combine(Constants.DataPath, "ECToConfPending"), false);
StreamWriter sw = new(Paths.ECToConfPending, false);
try
{
sw.Write(1);
Expand Down Expand Up @@ -507,7 +507,7 @@ private void tsiUninstall_Click(object sender, EventArgs e)
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
bool delData = MessageBox.Show(
Strings.GetString("dlgSvcDelData", Constants.DataPath),
Strings.GetString("dlgSvcDelData", Paths.Data),
"Delete configuration data?",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2) == DialogResult.Yes;
Expand All @@ -525,7 +525,7 @@ private void tsiUninstall_Click(object sender, EventArgs e)
// service uninstalled successfully
if (delData)
{
Directory.Delete(Constants.DataPath, true);
Directory.Delete(Paths.Data, true);
}
}
else
Expand Down Expand Up @@ -853,6 +853,7 @@ private void LoadConf(YAMDCC_Config config)

btnProfAdd.Enabled = tsiProfAdd.Enabled = true;
tsiProfRename.Enabled = tsiProfChangeDesc.Enabled = true;
tsiECtoConf.Enabled = true;
cboFanSel.Enabled = true;
cboFanSel.SelectedIndex = 0;
tsiECMon.Enabled = true;
Expand All @@ -863,7 +864,7 @@ private void LoadConf(YAMDCC_Config config)
private void ApplyConf()
{
// Save the updated config
Config.Save(Constants.CurrentConfigPath);
Config.Save(Paths.CurrentConfig);

// Tell the service to reload and apply the updated config
SendServiceMessage(new ServiceCommand(Command.ApplyConfig, null));
Expand Down Expand Up @@ -964,7 +965,7 @@ private void DelFanProfile()

private static string GetLastConfPath()
{
StreamReader sr = new(Constants.LastConfigPath, Encoding.UTF8);
StreamReader sr = new(Paths.LastConfig, Encoding.UTF8);
try
{
string path = sr.ReadLine();
Expand All @@ -978,7 +979,7 @@ private static string GetLastConfPath()

private static void SetLastConfPath(string path)
{
StreamWriter sw = new(Constants.LastConfigPath, false, Encoding.UTF8);
StreamWriter sw = new(Paths.LastConfig, false, Encoding.UTF8);
try
{
sw.WriteLine(path);
Expand Down Expand Up @@ -1043,12 +1044,13 @@ private void DisableAll()
tbKeyLight.Enabled = false;

tsiApply.Enabled = false;
tsiECMon.Enabled = false;
tsiRevert.Enabled = false;
tsiProfAdd.Enabled = false;
tsiProfChangeDesc.Enabled = false;
tsiProfRename.Enabled = false;
tsiProfDel.Enabled = false;
tsiRevert.Enabled = false;
tsiECtoConf.Enabled = false;
tsiECMon.Enabled = false;

for (int i = 0; i < tbFanSpds.Length; i++)
{
Expand Down
33 changes: 33 additions & 0 deletions YAMDCC.GUI/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,33 @@
<metadata name="sep5.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="sep1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="sep2.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="sep3.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tcMain.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tabFanControl.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tabOptions.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tabFanControl.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwFanSelect.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tblFCBottom.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwFanSelect.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand All @@ -156,6 +177,12 @@
<metadata name="tblExtra.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="tblExtra.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwKeyLight.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwKeyLight.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand All @@ -165,6 +192,12 @@
<metadata name="lblKeyLightHigh.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="lblKeyLightLow.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="lblKeyLightHigh.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="flwStats.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand Down
13 changes: 8 additions & 5 deletions YAMDCC.GUI/Constants.cs → YAMDCC.GUI/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

namespace YAMDCC.GUI
{
internal static class Constants
internal static class Paths
{
/// <summary>
/// The path where program data is stored.
/// </summary>
/// <remarks>
/// (C:\ProgramData\Sparronator9999\YAMDCC on Windows)
/// </remarks>
public static readonly string DataPath = Path.Combine(
public static readonly string Data = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"Sparronator9999", "YAMDCC");

Expand All @@ -37,23 +37,26 @@ internal static class Constants
/// <remarks>
/// (C:\ProgramData\Sparronator9999\YAMDCC\Logs on Windows)
/// </remarks>
public static readonly string LogPath = Path.Combine(DataPath, "Logs");
public static readonly string Logs = Path.Combine(Data, "Logs");

/// <summary>
/// The path where the currently applied YAMDCC config is saved.
/// </summary>
/// <remarks>
/// (C:\ProgramData\Sparronator9999\YAMDCC\CurrentConfig.xml on Windows)
/// </remarks>
public static readonly string CurrentConfigPath = Path.Combine(DataPath, "CurrentConfig.xml");
public static readonly string CurrentConfig = Path.Combine(Data, "CurrentConfig.xml");

/// <summary>
/// The path where the path to the last saved YAMDCC config is saved.
/// </summary>
/// <remarks>
/// (C:\ProgramData\Sparronator9999\YAMDCC\CurrentConfig.xml on Windows)
/// </remarks>
public static readonly string LastConfigPath = Path.Combine(DataPath, "LastConfig");
public static readonly string LastConfig = Path.Combine(Data, "LastConfig");

public static readonly string ECToConfSuccess = Path.Combine(Data, "ECToConfSuccess");
public static readonly string ECToConfFail = Path.Combine(Data, "ECToConfFail");
public static readonly string ECToConfPending = Path.Combine(Data, "ECToConfPending");
}
}
6 changes: 3 additions & 3 deletions YAMDCC.GUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static void Main()
// Make sure the application data directory structure is set up
// because apparently windows services don't know how to create
// directories:
Directory.CreateDirectory(Constants.LogPath);
Directory.CreateDirectory(Paths.Logs);

if (!IsAdmin())
{
Expand Down Expand Up @@ -132,7 +132,7 @@ private static void Start()
int rebootFlag = -1;
try
{
StreamReader sr = new(Path.Combine(Constants.DataPath, "ECToConfPending"));
StreamReader sr = new(Paths.ECToConfPending);
if (int.TryParse(sr.ReadToEnd(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int value))
{
rebootFlag = value;
Expand All @@ -150,7 +150,7 @@ private static void Start()
{
try
{
File.Delete(Path.Combine(Constants.DataPath, "ECToConfPending"));
File.Delete(Paths.ECToConfPending);
}
catch (DirectoryNotFoundException) { }
}
Expand Down
2 changes: 1 addition & 1 deletion YAMDCC.GUI/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static class Utils
/// <returns>
/// One of the <see cref="DialogResult"/> values.
/// </returns>
internal static DialogResult ShowError(string message)
public static DialogResult ShowError(string message)
{
return MessageBox.Show(message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down
Loading

0 comments on commit a96c660

Please sign in to comment.