From d87a6d4599c453afece2659d61f79bce9bfcb194 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:57:47 -0400 Subject: [PATCH] More validation --- RecodeItGUI/GUI/Main.Designer.cs | 18 ++++++++++-- RecodeItGUI/GUI/Main.cs | 47 +++++++++++++++++++++++++++++-- RecodeItLib/Utils/DataProvider.cs | 10 ++++--- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/RecodeItGUI/GUI/Main.Designer.cs b/RecodeItGUI/GUI/Main.Designer.cs index 6b46bbd..6c9ffa6 100644 --- a/RecodeItGUI/GUI/Main.Designer.cs +++ b/RecodeItGUI/GUI/Main.Designer.cs @@ -148,6 +148,7 @@ partial class ReCodeItForm label4 = new Label(); CCMappingTreeView = new TreeView(); groupBox3 = new GroupBox(); + CCImportMappings = new Button(); CCAutoLoadLastProj = new CheckBox(); CCLoadProjButton = new Button(); CCRemappedOutputButton = new Button(); @@ -1440,7 +1441,7 @@ partial class ReCodeItForm groupBox5.Controls.Add(CCBuildConfiguration); groupBox5.Controls.Add(CrossPatchRemapButton); groupBox5.Controls.Add(CrossPatchRunButton); - groupBox5.Location = new Point(6, 274); + groupBox5.Location = new Point(6, 304); groupBox5.Name = "groupBox5"; groupBox5.Size = new Size(631, 215); groupBox5.TabIndex = 27; @@ -1495,6 +1496,7 @@ partial class ReCodeItForm // // groupBox3 // + groupBox3.Controls.Add(CCImportMappings); groupBox3.Controls.Add(CCAutoLoadLastProj); groupBox3.Controls.Add(CCLoadProjButton); groupBox3.Controls.Add(CCRemappedOutputButton); @@ -1508,11 +1510,22 @@ partial class ReCodeItForm groupBox3.Controls.Add(CCBuildDirText); groupBox3.Location = new Point(6, 30); groupBox3.Name = "groupBox3"; - groupBox3.Size = new Size(631, 238); + groupBox3.Size = new Size(631, 268); groupBox3.TabIndex = 21; groupBox3.TabStop = false; groupBox3.Text = "ReCodeIt Proj Settings"; // + // CCImportMappings + // + CCImportMappings.Font = new Font("Segoe UI", 8F, FontStyle.Regular, GraphicsUnit.Point, 0); + CCImportMappings.Location = new Point(6, 219); + CCImportMappings.Name = "CCImportMappings"; + CCImportMappings.Size = new Size(150, 34); + CCImportMappings.TabIndex = 35; + CCImportMappings.Text = "Import Mappings"; + CCImportMappings.UseVisualStyleBackColor = true; + CCImportMappings.Click += CCImportMappings_Click; + // // CCAutoLoadLastProj // CCAutoLoadLastProj.AutoSize = true; @@ -1869,4 +1882,5 @@ partial class ReCodeItForm private GroupBox groupBox5; private TextBox CCBuildConfiguration; private LinkLabel GithubLinkLabel; + private Button CCImportMappings; } diff --git a/RecodeItGUI/GUI/Main.cs b/RecodeItGUI/GUI/Main.cs index 3cccc96..e08bd02 100644 --- a/RecodeItGUI/GUI/Main.cs +++ b/RecodeItGUI/GUI/Main.cs @@ -48,7 +48,7 @@ public partial class ReCodeItForm : Form { if (CrossCompiler.ActiveProject == null) { - DataProvider.LoadMappingFile(AppSettings.Remapper.MappingPath); + DataProvider.Remaps = DataProvider.LoadMappingFile(AppSettings.Remapper.MappingPath); LoadedMappingFilePath.Text = AppSettings.Remapper.MappingPath; return; } @@ -60,7 +60,7 @@ public partial class ReCodeItForm : Form return; } - DataProvider.LoadMappingFile(AppSettings.Remapper.MappingPath); + DataProvider.Remaps = DataProvider.LoadMappingFile(AppSettings.Remapper.MappingPath); LoadedMappingFilePath.Text = AppSettings.Remapper.MappingPath; } @@ -283,7 +283,7 @@ public partial class ReCodeItForm : Form if (result == string.Empty) { return; } - DataProvider.LoadMappingFile(result); + DataProvider.Remaps = DataProvider.LoadMappingFile(result); AppSettings.Remapper.MappingPath = result; AppSettings.Remapper.UseProjectMappings = false; ActiveProjectMappingsCheckbox.Checked = false; @@ -894,6 +894,47 @@ public partial class ReCodeItForm : Form // TODO } + private void CCImportMappings_Click(object sender, EventArgs e) + { + if (CrossCompiler.ActiveProject == null) + { + MessageBox.Show("No project is loaded to add mappings too."); + return; + } + + var answer = MessageBox.Show( + "'Yes' to Add the items to the existing list, or 'No' to clear the list before adding these.", + "Add Items to existing list?", + MessageBoxButtons.YesNoCancel); + + switch (answer) + { + case DialogResult.Yes: + break; + + case DialogResult.No: + CrossCompiler.ActiveProject.RemapModels.Clear(); + break; + + case DialogResult.Cancel: + return; + + default: + break; + } + + var result = GUIHelpers.OpenFileDialog("Select a mapping file", + "JSON Files (*.json)|*.json|JSONC Files (*.jsonc)|*.jsonc|All Files (*.*)|*.*"); + + if (result == string.Empty) { return; } + + var remaps = DataProvider.LoadMappingFile(result); + + CrossCompiler.ActiveProject.RemapModels.AddRange(remaps); + + ReloadCCRemapTreeView(CrossCompiler.ActiveProject.RemapModels); + } + #endregion CROSS_COMPILER // Reset All UI elements to default diff --git a/RecodeItLib/Utils/DataProvider.cs b/RecodeItLib/Utils/DataProvider.cs index 96e9137..ab436b2 100644 --- a/RecodeItLib/Utils/DataProvider.cs +++ b/RecodeItLib/Utils/DataProvider.cs @@ -18,7 +18,7 @@ public static class DataProvider public static readonly string ReCodeItProjectsPath = Path.Combine(AppContext.BaseDirectory, "Projects"); - public static List Remaps { get; private set; } = []; + public static List Remaps { get; set; } = []; public static Dictionary> ScoringModels { get; set; } = []; @@ -74,7 +74,7 @@ public static class DataProvider //Logger.Log($"App settings saved to {settingsPath}"); } - public static void LoadMappingFile(string path) + public static List LoadMappingFile(string path) { if (!File.Exists(path)) { @@ -85,9 +85,9 @@ public static class DataProvider ScoringModels = []; - Remaps = JsonConvert.DeserializeObject>(jsonText); + var remaps = JsonConvert.DeserializeObject>(jsonText); - if (Remaps == null) { Remaps = []; } + if (remaps == null) { return []; } var properties = typeof(SearchParams).GetProperties(); @@ -103,6 +103,8 @@ public static class DataProvider } Logger.Log($"Mapping file loaded from '{path}' containing {Remaps.Count} remaps"); + + return remaps; } public static void SaveMapping()