More validation

This commit is contained in:
Cj 2024-06-19 15:57:47 -04:00
parent ba5364f12e
commit d87a6d4599
3 changed files with 66 additions and 9 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -18,7 +18,7 @@ public static class DataProvider
public static readonly string ReCodeItProjectsPath = Path.Combine(AppContext.BaseDirectory, "Projects");
public static List<RemapModel> Remaps { get; private set; } = [];
public static List<RemapModel> Remaps { get; set; } = [];
public static Dictionary<string, HashSet<ScoringModel>> 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<RemapModel> LoadMappingFile(string path)
{
if (!File.Exists(path))
{
@ -85,9 +85,9 @@ public static class DataProvider
ScoringModels = [];
Remaps = JsonConvert.DeserializeObject<List<RemapModel>>(jsonText);
var remaps = JsonConvert.DeserializeObject<List<RemapModel>>(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()