From 74473ba7d8f6b78a18411f97bca98185169c7e49 Mon Sep 17 00:00:00 2001 From: Sparronator9999 <86388887+Sparronator9999@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:02:46 +1100 Subject: [PATCH] GUI: minor refactors + move more UI strings to Strings.resx --- YAMDCC.GUI/MainWindow.cs | 49 +++++++++++++++++++++++----------------- YAMDCC.GUI/Strings.resx | 29 ++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/YAMDCC.GUI/MainWindow.cs b/YAMDCC.GUI/MainWindow.cs index f6414d2..e6df95c 100644 --- a/YAMDCC.GUI/MainWindow.cs +++ b/YAMDCC.GUI/MainWindow.cs @@ -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; @@ -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", }; @@ -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", }; @@ -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; @@ -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) { @@ -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 curveCfgList = [.. fanConfig.FanCurveConfs]; - curveCfgList.Add(newCurveCfg); + // Add the new fan profile to the config's list + List 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; @@ -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 curveCfgList = [.. fanConfig.FanCurveConfs]; curveCfgList.RemoveAt(cboProfSel.SelectedIndex); fanConfig.FanCurveConfs = [.. curveCfgList]; @@ -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(); } } @@ -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; diff --git a/YAMDCC.GUI/Strings.resx b/YAMDCC.GUI/Strings.resx index 95d9e9a..297eced 100644 --- a/YAMDCC.GUI/Strings.resx +++ b/YAMDCC.GUI/Strings.resx @@ -295,4 +295,33 @@ Please re-run this program as Administrator The last loaded/saved config is invalid. + + YAMDCC config files|*.xml + + + Are you sure you want to revert to the last loaded/saved config? + + + ERROR: A {0} service command failed to run. + + + WARN: Received an empty response from service. + + + Full Blast toggled successfully! + + + Config applied successfully! + + + Loading config, please wait... + + + Please load a config to start + + + This is a template config. +Template configs are currently a WIP and cannot be used yet. +Please load a different config. + \ No newline at end of file