Skip to content

Commit

Permalink
GUI: minor refactors + move more UI strings to Strings.resx
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparronator9999 committed Oct 27, 2024
1 parent cb0e13b commit 74473ba
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 21 deletions.
49 changes: 28 additions & 21 deletions YAMDCC.GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using YAMDCC.Config;
using YAMDCC.GUI.Dialogs;
Expand Down Expand Up @@ -322,7 +323,7 @@ private void tsiLoadConf_Click(object sender, EventArgs e)
{
AddExtension = true,
CheckFileExists = true,
Filter = "YAMDCC config files|*.xml",
Filter = Strings.GetString("dlgFileFilter"),
Title = "Load config",
};

Expand All @@ -340,7 +341,7 @@ private void tsiSaveConf_Click(object sender, EventArgs e)
SaveFileDialog sfd = new()
{
AddExtension = true,
Filter = "YAMDCC config files|*.xml",
Filter = Strings.GetString("dlgFileFilter"),
Title = "Save config",
};

Expand Down Expand Up @@ -736,10 +737,9 @@ private void LoadConf(YAMDCC_Config config)
{
if (config.Template)
{
MessageBox.Show(
"This is a template config.\n" +
"Template configs are currently WIP and cannot be used yet.\n" +
"Please load a different config.");
MessageBox.Show(Strings.GetString("dlgTemplateConfWIP"), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

tsiSaveConf.Enabled = false;
chkFullBlast.Enabled = false;
cboFanSel.Enabled = false;
Expand Down Expand Up @@ -848,7 +848,7 @@ private void ApplyConf()
private void RevertConf()
{
if (MessageBox.Show(
"Are you sure you want to revert to the last loaded/saved config?",
Strings.GetString("dlgRevert"),
"Revert?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
== DialogResult.Yes)
{
Expand Down Expand Up @@ -906,12 +906,11 @@ private void AddFanProfile()
newCurveCfg.Name = dlg.Result;
newCurveCfg.Desc = $"Copy of {oldCurveCfg.Name}";

// Add the new fan profile to the list
List<FanCurveConf> curveCfgList = [.. fanConfig.FanCurveConfs];
curveCfgList.Add(newCurveCfg);
// Add the new fan profile to the config's list
List<FanCurveConf> curveCfgList = [.. fanConfig.FanCurveConfs, newCurveCfg];
fanConfig.FanCurveConfs = [.. curveCfgList];

// Add the new fan profile to the list and select it:
// Add the new fan profile to the UI's profile list and select it:
cboProfSel.Items.Add(dlg.Result);
cboProfSel.SelectedIndex = cboProfSel.Items.Count - 1;

Expand All @@ -929,7 +928,7 @@ private void DelFanProfile()
{
FanConf fanConfig = Config.FanConfs[cboFanSel.SelectedIndex];

// Remove the fan profile
// Remove the fan profile from the config's list
List<FanCurveConf> curveCfgList = [.. fanConfig.FanCurveConfs];
curveCfgList.RemoveAt(cboProfSel.SelectedIndex);
fanConfig.FanCurveConfs = [.. curveCfgList];
Expand All @@ -946,19 +945,27 @@ private void DelFanProfile()

private static string GetLastConfPath()
{
using (StreamReader sr = new(Path.Combine(DataPath, "LastConfig"), false))
StreamReader sr = new(Path.Combine(DataPath, "LastConfig"), Encoding.UTF8);
try
{
string path = sr.ReadLine();
sr.Close();
return path;
}
finally
{
sr.Close();
}
}

private static void SetLastConfPath(string path)
{
using (StreamWriter sw = new(Path.Combine(DataPath, "LastConfig"), false))
StreamWriter sw = new(Path.Combine(DataPath, "LastConfig"), false, Encoding.UTF8);
try
{
sw.WriteLine(path);
}
finally
{
sw.Close();
}
}
Expand Down Expand Up @@ -1019,23 +1026,23 @@ private void UpdateStatus(StatusCode status, int data = 0)
{
case StatusCode.ServiceCommandFail:
persist = true;
lblStatus.Text = $"ERROR: A {(Command)data} service command failed to run.";
lblStatus.Text = Strings.GetString("statSvcError", (Command)data);
break;
case StatusCode.ServiceResponseEmpty:
lblStatus.Text = $"WARN: Received an empty response from service.";
lblStatus.Text = Strings.GetString("statResponseEmpty");
break;
case StatusCode.NoConfig:
persist = true;
lblStatus.Text = "Please load a config to start";
lblStatus.Text = Strings.GetString("statNoConf");
break;
case StatusCode.ConfLoading:
lblStatus.Text = "Loading config, please wait...";
lblStatus.Text = Strings.GetString("statConfLoading");
break;
case StatusCode.ConfApplySuccess:
lblStatus.Text = $"Config applied successfully!";
lblStatus.Text = Strings.GetString("statConfApplied");
break;
case StatusCode.FullBlastToggleSuccess:
lblStatus.Text = $"Full Blast toggled successfully!";
lblStatus.Text = Strings.GetString("statFBToggled");
break;
default:
persist = true;
Expand Down
29 changes: 29 additions & 0 deletions YAMDCC.GUI/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,33 @@ Please re-run this program as Administrator
<data name="dlgOldConfInvalid" xml:space="preserve">
<value>The last loaded/saved config is invalid.</value>
</data>
<data name="dlgFileFilter" xml:space="preserve">
<value>YAMDCC config files|*.xml</value>
</data>
<data name="dlgRevert" xml:space="preserve">
<value>Are you sure you want to revert to the last loaded/saved config?</value>
</data>
<data name="statSvcError" xml:space="preserve">
<value>ERROR: A {0} service command failed to run.</value>
</data>
<data name="statResponseEmpty" xml:space="preserve">
<value>WARN: Received an empty response from service.</value>
</data>
<data name="statFBToggled" xml:space="preserve">
<value>Full Blast toggled successfully!</value>
</data>
<data name="statConfApplied" xml:space="preserve">
<value>Config applied successfully!</value>
</data>
<data name="statConfLoading" xml:space="preserve">
<value>Loading config, please wait...</value>
</data>
<data name="statNoConf" xml:space="preserve">
<value>Please load a config to start</value>
</data>
<data name="dlgTemplateConfWIP" xml:space="preserve">
<value>This is a template config.
Template configs are currently a WIP and cannot be used yet.
Please load a different config.</value>
</data>
</root>

0 comments on commit 74473ba

Please sign in to comment.