From 940381f4236bcfc1ff5d2f93cbf4716ea9ec634f Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:44:47 -0400 Subject: [PATCH] Self saving settings, refactor, and bug fixes --- RecodeItGUI/GUI/Main.Designer.cs | 4 + RecodeItGUI/GUI/Main.cs | 103 ++--- RecodeItLib/Models/AppSettingsModel.cs | 364 ++++++++++++++++-- ...ringExtentions.cs => SysTypeExtentions.cs} | 5 +- 4 files changed, 380 insertions(+), 96 deletions(-) rename RecodeItLib/Utils/{StringExtentions.cs => SysTypeExtentions.cs} (93%) diff --git a/RecodeItGUI/GUI/Main.Designer.cs b/RecodeItGUI/GUI/Main.Designer.cs index 6c9ffa6..a47f0bb 100644 --- a/RecodeItGUI/GUI/Main.Designer.cs +++ b/RecodeItGUI/GUI/Main.Designer.cs @@ -302,6 +302,7 @@ partial class ReCodeItForm RemapperUnseal.TabIndex = 36; RemapperUnseal.Text = "Unseal"; RemapperUnseal.UseVisualStyleBackColor = true; + RemapperUnseal.CheckedChanged += RemapperUnseal_CheckedChanged; // // RemapperPublicicize // @@ -314,6 +315,7 @@ partial class ReCodeItForm RemapperPublicicize.TabIndex = 35; RemapperPublicicize.Text = "Publicize"; RemapperPublicicize.UseVisualStyleBackColor = true; + RemapperPublicicize.CheckedChanged += RemapperPublicicize_CheckedChanged; // // RemapperOutputDirectoryPath // @@ -346,6 +348,7 @@ partial class ReCodeItForm RenamePropertiesCheckbox.TabIndex = 28; RenamePropertiesCheckbox.Text = "Rename Properties"; RenamePropertiesCheckbox.UseVisualStyleBackColor = true; + RenamePropertiesCheckbox.CheckedChanged += RenamePropertiesCheckbox_CheckedChanged; // // OutputDirectoryButton // @@ -386,6 +389,7 @@ partial class ReCodeItForm RenameFieldsCheckbox.TabIndex = 26; RenameFieldsCheckbox.Text = "Rename Fields"; RenameFieldsCheckbox.UseVisualStyleBackColor = true; + RenameFieldsCheckbox.CheckedChanged += RenameFieldsCheckbox_CheckedChanged; // // ConstructorCountEnabled // diff --git a/RecodeItGUI/GUI/Main.cs b/RecodeItGUI/GUI/Main.cs index e08bd02..c3814e2 100644 --- a/RecodeItGUI/GUI/Main.cs +++ b/RecodeItGUI/GUI/Main.cs @@ -84,8 +84,6 @@ public partial class ReCodeItForm : Form } ReloadRemapTreeView(remaps!); - - DataProvider.SaveAppSettings(); } #region BUTTONS @@ -214,7 +212,6 @@ public partial class ReCodeItForm : Form else { DataProvider.Remaps?.RemoveAt(RemapTreeView.SelectedNode.Index); - DataProvider.SaveMapping(); } RemapTreeView.SelectedNode?.Remove(); @@ -265,15 +262,7 @@ public partial class ReCodeItForm : Form private void SaveMappingFileButton_Click(object sender, EventArgs e) { - if (MessageBox.Show( - "Are you sure?", - "Confirmation", - MessageBoxButtons.YesNo, - MessageBoxIcon.Exclamation, - MessageBoxDefaultButton.Button2) == DialogResult.Yes) - { - DataProvider.SaveMapping(); - } + DataProvider.SaveMapping(); } private void LoadMappingFileButton_Click(object sender, EventArgs e) @@ -287,7 +276,6 @@ public partial class ReCodeItForm : Form AppSettings.Remapper.MappingPath = result; AppSettings.Remapper.UseProjectMappings = false; ActiveProjectMappingsCheckbox.Checked = false; - DataProvider.SaveAppSettings(); LoadedMappingFilePath.Text = result; @@ -466,6 +454,7 @@ public partial class ReCodeItForm : Form DataProvider.Settings.AutoMapper.TypesToIgnore.Add(AutoMapperTypesToIgnoreTextField.Text); AutoMapperTypesExcludeBox.Items.Add(AutoMapperTypesToIgnoreTextField.Text); AutoMapperTypesToIgnoreTextField.Clear(); + DataProvider.SaveAppSettings(); } } @@ -476,6 +465,7 @@ public partial class ReCodeItForm : Form { DataProvider.Settings.AutoMapper.TypesToIgnore.RemoveAt(AutoMapperTypesExcludeBox.SelectedIndex); AutoMapperTypesExcludeBox.Items.Remove(AutoMapperTypesExcludeBox.SelectedItem); + DataProvider.SaveAppSettings(); } } @@ -493,6 +483,30 @@ public partial class ReCodeItForm : Form #endregion LISTBOX_BUTTONS + #region CHECKBOX + + private void RemapperUnseal_CheckedChanged(object sender, EventArgs e) + { + AppSettings.Remapper.MappingSettings.Unseal = RemapperUnseal.Checked; + } + + private void RemapperPublicicize_CheckedChanged(object sender, EventArgs e) + { + AppSettings.Remapper.MappingSettings.Publicize = RemapperPublicicize.Checked; + } + + private void RenameFieldsCheckbox_CheckedChanged(object sender, EventArgs e) + { + AppSettings.Remapper.MappingSettings.RenameFields = RenameFieldsCheckbox.Checked; + } + + private void RenamePropertiesCheckbox_CheckedChanged(object sender, EventArgs e) + { + AppSettings.Remapper.MappingSettings.RenameProperties = RenamePropertiesCheckbox.Checked; + } + + #endregion CHECKBOX + #endregion BUTTONS #endregion MANUAL_REMAPPER @@ -520,37 +534,11 @@ public partial class ReCodeItForm : Form private void DebugLoggingCheckbox_CheckedChanged(object sender, EventArgs e) { DataProvider.Settings.AppSettings.Debug = DebugLoggingCheckbox.Checked; - DataProvider.SaveAppSettings(); } private void SilentModeCheckbox_CheckedChanged(object sender, EventArgs e) { DataProvider.Settings.AppSettings.SilentMode = SilentModeCheckbox.Checked; - DataProvider.SaveAppSettings(); - } - - private void RenameFieldsCheckbox_CheckedChanged(object sender, EventArgs e) - { - DataProvider.Settings.AppSettings.RenameFields = RenameFieldsCheckbox.Checked; - DataProvider.SaveAppSettings(); - } - - private void RenamePropertiesCheckbox_CheckedChanged(object sender, EventArgs e) - { - DataProvider.Settings.AppSettings.RenameProperties = RenamePropertiesCheckbox.Checked; - DataProvider.SaveAppSettings(); - } - - private void PublicizeCheckbox_CheckedChanged(object sender, EventArgs e) - { - DataProvider.Settings.Remapper.MappingSettings.Publicize = PublicizeCheckbox.Checked; - DataProvider.SaveAppSettings(); - } - - private void UnsealCheckbox_CheckedChanged(object sender, EventArgs e) - { - DataProvider.Settings.Remapper.MappingSettings.Unseal = UnsealCheckbox.Checked; - DataProvider.SaveAppSettings(); } #endregion CHECKBOXES @@ -560,7 +548,6 @@ public partial class ReCodeItForm : Form private void AutoMapperRequiredMatchesUpDown_ValueChanged(object sender, EventArgs e) { DataProvider.Settings.AutoMapper.RequiredMatches = (int)AutoMapperRequiredMatchesUpDown.Value; - DataProvider.SaveAppSettings(); } #endregion UPDOWNS @@ -615,7 +602,6 @@ public partial class ReCodeItForm : Form { AppSettings.AutoMapper.AssemblyPath = result; TargetAssemblyPath.Text = result; - DataProvider.SaveAppSettings(); } } @@ -627,20 +613,17 @@ public partial class ReCodeItForm : Form { AppSettings.AutoMapper.OutputPath = result; RemapperOutputDirectoryPath.Text = result; - DataProvider.SaveAppSettings(); } } private void AutoMapperRequiredMatchesUpDown_ValueChanged_1(object sender, EventArgs e) { AppSettings.AutoMapper.RequiredMatches = (int)AutoMapperRequiredMatchesUpDown.Value; - DataProvider.SaveAppSettings(); } private void AutoMapperMinLengthUpDown_ValueChanged(object sender, EventArgs e) { AppSettings.AutoMapper.MinLengthToMatch = (int)AutoMapperMinLengthUpDown.Value; - DataProvider.SaveAppSettings(); } private void AutoMapperTokensAddButton_Click(object sender, EventArgs e) @@ -650,8 +633,8 @@ public partial class ReCodeItForm : Form AutoMapperTokensBox.Items.Add(AutoMapperTokensTextField.Text); AppSettings.AutoMapper.TokensToMatch.Add(AutoMapperTokensTextField.Text); - AutoMapperTokensTextField.Clear(); DataProvider.SaveAppSettings(); + AutoMapperTokensTextField.Clear(); } } @@ -659,8 +642,8 @@ public partial class ReCodeItForm : Form { if (AutoMapperTokensBox.SelectedItem != null) { + AppSettings.AutoMapper.TokensToMatch.RemoveAt(AutoMapperTokensBox.SelectedIndex); AutoMapperTokensBox.Items.Remove(AutoMapperTokensBox.SelectedItem); - AppSettings.AutoMapper.TokensToMatch.RemoveAt(AutoMapperTokensBox.SelectedIndex + 1); DataProvider.SaveAppSettings(); } } @@ -672,8 +655,8 @@ public partial class ReCodeItForm : Form AutoMapperFPBox.Items.Add(AutoMapperFPTextField.Text); AppSettings.AutoMapper.PropertyFieldBlackList.Add(AutoMapperFPTextField.Text); - AutoMapperFPTextField.Clear(); DataProvider.SaveAppSettings(); + AutoMapperFPTextField.Clear(); } } @@ -681,8 +664,9 @@ public partial class ReCodeItForm : Form { if (AutoMapperFPBox.SelectedItem != null) { - AutoMapperFPBox.Items.Remove(AutoMapperFPBox.SelectedItem); AppSettings.AutoMapper.PropertyFieldBlackList.RemoveAt(AutoMapperFPBox.SelectedIndex); + AutoMapperFPBox.Items.Remove(AutoMapperFPBox.SelectedItem); + DataProvider.SaveAppSettings(); } } @@ -692,10 +676,11 @@ public partial class ReCodeItForm : Form if (!AutoMapperMethodBox.Items.Contains(AutoMapperMethodTextBox.Text)) { AutoMapperMethodBox.Items.Add(AutoMapperMethodTextBox.Text); + AppSettings.AutoMapper.MethodParamaterBlackList.Add(AutoMapperMethodTextBox.Text); - AutoMapperMethodTextBox.Clear(); DataProvider.SaveAppSettings(); + AutoMapperMethodTextBox.Clear(); } } @@ -703,8 +688,12 @@ public partial class ReCodeItForm : Form { if (AutoMapperMethodBox.SelectedItem != null) { - AutoMapperMethodBox.Items.Remove(AutoMapperMethodBox.SelectedItem); - AppSettings.AutoMapper.MethodParamaterBlackList.RemoveAt(AutoMapperMethodBox.SelectedIndex > 0 ? AutoMapperMethodBox.SelectedIndex : 0); + AppSettings.AutoMapper.MethodParamaterBlackList + .RemoveAt(AutoMapperMethodBox.SelectedIndex); + + AutoMapperMethodBox.Items + .Remove(AutoMapperMethodBox.SelectedItem); + DataProvider.SaveAppSettings(); } } @@ -712,31 +701,26 @@ public partial class ReCodeItForm : Form private void SearchMethodsCheckBox_CheckedChanged(object sender, EventArgs e) { AppSettings.AutoMapper.SearchMethods = AutoMapperSearchMethodsCheckBox.Checked; - DataProvider.SaveAppSettings(); } private void AutoMapperRenameFields_CheckedChanged(object sender, EventArgs e) { AppSettings.AutoMapper.MappingSettings.RenameFields = AutoMapperRenameFields.Checked; - DataProvider.SaveAppSettings(); } private void AutoMapperRenameProps_CheckedChanged(object sender, EventArgs e) { AppSettings.AutoMapper.MappingSettings.RenameProperties = AutoMapperRenameProps.Checked; - DataProvider.SaveAppSettings(); } private void AutoMapperPublicize_CheckedChanged(object sender, EventArgs e) { AppSettings.AutoMapper.MappingSettings.Publicize = AutoMapperPublicize.Checked; - DataProvider.SaveAppSettings(); } private void AutoMapperUnseal_CheckedChanged(object sender, EventArgs e) { AppSettings.AutoMapper.MappingSettings.Unseal = AutoMapperUnseal.Checked; - DataProvider.SaveAppSettings(); } #endregion AUTOMAPPER @@ -760,7 +744,6 @@ public partial class ReCodeItForm : Form if (!File.Exists(ccSettings.LastLoadedProject)) { ccSettings.LastLoadedProject = string.Empty; - DataProvider.SaveAppSettings(); MessageBox.Show("Couldnt find last loaded project"); return; } @@ -791,7 +774,6 @@ public partial class ReCodeItForm : Form if (result != string.Empty) { CCOriginalAssemblyText.Text = result; - DataProvider.SaveAppSettings(); } } @@ -802,7 +784,6 @@ public partial class ReCodeItForm : Form if (result != string.Empty) { CCRemappedOutputText.Text = result; - DataProvider.SaveAppSettings(); } } @@ -814,7 +795,6 @@ public partial class ReCodeItForm : Form if (result != string.Empty) { CCVisualStudioProjDirText.Text = result; - DataProvider.SaveAppSettings(); } } @@ -825,7 +805,6 @@ public partial class ReCodeItForm : Form if (result != string.Empty) { CCBuildDirText.Text = result; - DataProvider.SaveAppSettings(); } } @@ -885,7 +864,6 @@ public partial class ReCodeItForm : Form private void CCAutoLoadLastProj_CheckedChanged_1(object sender, EventArgs e) { AppSettings.CrossCompiler.AutoLoadLastActiveProject = CCAutoLoadLastProj.Checked; - DataProvider.SaveAppSettings(); } // Use the projects remap list on the remap tab @@ -1002,7 +980,6 @@ public partial class ReCodeItForm : Form DataProvider.Settings.Remapper.UseProjectMappings = true; ActiveProjectMappingsCheckbox.Checked = true; - DataProvider.SaveAppSettings(); EditSelectedRemap(this, e, true); } diff --git a/RecodeItLib/Models/AppSettingsModel.cs b/RecodeItLib/Models/AppSettingsModel.cs index 1f8c768..380d71a 100644 --- a/RecodeItLib/Models/AppSettingsModel.cs +++ b/RecodeItLib/Models/AppSettingsModel.cs @@ -1,14 +1,64 @@ -namespace ReCodeIt.Models; +using ReCodeIt.Utils; + +namespace ReCodeIt.Models; /// /// All settings container /// public class Settings { - public AppSettings AppSettings { get; set; } - public RemapperSettings Remapper { get; set; } - public AutoMapperSettings AutoMapper { get; set; } - public CrossCompilerSettings CrossCompiler { get; set; } + private AppSettings _appSettings; + + public AppSettings AppSettings + { + get { return _appSettings; } + set + { + _appSettings = value; + Save(); + } + } + + private RemapperSettings _remapper; + + public RemapperSettings Remapper + { + get { return _remapper; } + set + { + _remapper = value; + Save(); + } + } + + private AutoMapperSettings _autoMapper; + + public AutoMapperSettings AutoMapper + { + get { return _autoMapper; } + set + { + _autoMapper = value; + Save(); + } + } + + private CrossCompilerSettings _crossCompiler; + + public CrossCompilerSettings CrossCompiler + { + get { return _crossCompiler; } + set + { + _crossCompiler = value; + Save(); + } + } + + private void Save() + { + DataProvider.SaveAppSettings(); + } } /// @@ -16,10 +66,34 @@ public class Settings /// public class AppSettings { - public bool Debug { get; set; } - public bool SilentMode { get; set; } - public bool RenameFields { get; set; } - public bool RenameProperties { get; set; } + private bool _debug; + + public bool Debug + { + get { return _debug; } + set + { + _debug = value; + Save(); + } + } + + private bool _silentMode; + + public bool SilentMode + { + get { return _silentMode; } + set + { + _silentMode = value; + Save(); + } + } + + private void Save() + { + DataProvider.SaveAppSettings(); + } } /// @@ -27,27 +101,82 @@ public class AppSettings /// public class RemapperSettings { + private string _assemblyPath; + /// /// Path to the assembly we want to remap /// - public string AssemblyPath { get; set; } + public string AssemblyPath + { + get { return _assemblyPath; } + set + { + _assemblyPath = value; + Save(); + } + } + + private string _outputPath; /// /// Path including the filename and extension we want to write the changes to /// - public string OutputPath { get; set; } + public string OutputPath + { + get { return _outputPath; } + set + { + _outputPath = value; + Save(); + } + } + + private string _mappingPath; /// /// Path to the mapping file /// - public string MappingPath { get; set; } + public string MappingPath + { + get { return _mappingPath; } + set + { + _mappingPath = value; + Save(); + } + } + + private bool _useProjectMappings; /// /// Use the projects mappings instead of a standalone file /// - public bool UseProjectMappings { get; set; } + public bool UseProjectMappings + { + get { return _useProjectMappings; } + set + { + _useProjectMappings = value; + Save(); + } + } - public MappingSettings MappingSettings { get; set; } + private MappingSettings _mappingSettings; + + public MappingSettings MappingSettings + { + get { return _mappingSettings; } + set + { + _mappingSettings = value; + Save(); + } + } + + private void Save() + { + DataProvider.SaveAppSettings(); + } } /// @@ -55,53 +184,158 @@ public class RemapperSettings /// public class AutoMapperSettings { + private string _assemblyPath; + /// /// Path to the assembly we want to remap /// - public string AssemblyPath { get; set; } + public string AssemblyPath + { + get { return _assemblyPath; } + set + { + _assemblyPath = value; + Save(); + } + } + + private string _outputPath; /// /// Path including the filename and extension we want to write the changes to /// - public string OutputPath { get; set; } + public string OutputPath + { + get { return _outputPath; } + set + { + _outputPath = value; + Save(); + } + } + + private int _requiredMatches; /// /// Minimum number of times a member must have this name in the assembly before considering it /// for remapping /// - public int RequiredMatches { get; set; } + public int RequiredMatches + { + get { return _requiredMatches; } + set + { + _requiredMatches = value; + Save(); + } + } + + private int _minLengthToMatch; /// /// Minimum length of the field/property name in code before it will be considered for a rename /// - public int MinLengthToMatch { get; set; } + public int MinLengthToMatch + { + get { return _minLengthToMatch; } + set + { + _minLengthToMatch = value; + Save(); + } + } + + private bool _searchMethods; /// /// Will attempt to map types from method meta data and parameters /// - public bool SearchMethods { get; set; } + public bool SearchMethods + { + get { return _searchMethods; } + set + { + _searchMethods = value; + Save(); + } + } - public MappingSettings MappingSettings { get; set; } + private MappingSettings _mappingSettings; + + public MappingSettings MappingSettings + { + get { return _mappingSettings; } + set + { + _mappingSettings = value; + Save(); + } + } + + private List _typesToIgnore; /// /// Any member name you want to ignore while iterating through the assembly /// - public List TypesToIgnore { get; set; } + public List TypesToIgnore + { + get { return _typesToIgnore; } + set + { + _typesToIgnore = value; + Save(); + } + } + + private List _tokensToMatch; /// /// The auto mapper will look for these tokens in class names and prioritize those /// - public List TokensToMatch { get; set; } + public List TokensToMatch + { + get { return _tokensToMatch; } + set + { + _tokensToMatch = value; + Save(); + } + } + + private List _propertyFieldBlacklist; /// /// Property or fields names to ignore in the automap, these are case sanitized so case does not matter /// - public List PropertyFieldBlackList { get; set; } + public List PropertyFieldBlackList + { + get { return _propertyFieldBlacklist; } + set + { + _propertyFieldBlacklist = value; + Save(); + } + } + + private List _methodParamaterBlackList; /// /// method parameter names to ignore in the automap, these are case sanitized so case does not matter /// - public List MethodParamaterBlackList { get; set; } + public List MethodParamaterBlackList + { + get { return _methodParamaterBlackList; } + set + { + _methodParamaterBlackList = value; + Save(); + } + } + + private void Save() + { + DataProvider.SaveAppSettings(); + } } /// @@ -109,15 +343,40 @@ public class AutoMapperSettings /// public class CrossCompilerSettings { + private string _lastLoadedProject; + /// /// Last Loaded Project Path /// - public string LastLoadedProject { get; set; } + public string LastLoadedProject + { + get { return _lastLoadedProject; } + set + { + _lastLoadedProject = value; + Save(); + } + } + + private bool _autoLoadLastActiveProj; /// /// Should the last active project be auto loaded /// - public bool AutoLoadLastActiveProject { get; set; } + public bool AutoLoadLastActiveProject + { + get { return _autoLoadLastActiveProj; } + set + { + _autoLoadLastActiveProj = value; + Save(); + } + } + + private void Save() + { + DataProvider.SaveAppSettings(); + } } /// @@ -125,23 +384,68 @@ public class CrossCompilerSettings /// public class MappingSettings { + private bool _renameFields; + /// /// Names of fields of the matched type will be renamed to the type name with approproiate convention /// - public bool RenameFields { get; set; } + public bool RenameFields + { + get { return _renameFields; } + set + { + _renameFields = value; + Save(); + } + } + + private bool _renameProps; /// /// Names of properties of the matched type will be renamed to the type name with approproiate convention /// - public bool RenameProperties { get; set; } + public bool RenameProperties + { + get { return _renameProps; } + set + { + _renameProps = value; + Save(); + } + } + + private bool _publicize; /// /// Publicize all types, methods, and properties : NOTE: Not run until after the remap has completed /// - public bool Publicize { get; set; } + public bool Publicize + { + get { return _publicize; } + set + { + _unseal = value; + Save(); + } + } + + private bool _unseal; /// /// Unseal all types : NOTE: Not run until after the remap has completed /// - public bool Unseal { get; set; } + public bool Unseal + { + get { return _unseal; } + set + { + _unseal = value; + Save(); + } + } + + private void Save() + { + DataProvider.SaveAppSettings(); + } } \ No newline at end of file diff --git a/RecodeItLib/Utils/StringExtentions.cs b/RecodeItLib/Utils/SysTypeExtentions.cs similarity index 93% rename from RecodeItLib/Utils/StringExtentions.cs rename to RecodeItLib/Utils/SysTypeExtentions.cs index 1e78614..4972774 100644 --- a/RecodeItLib/Utils/StringExtentions.cs +++ b/RecodeItLib/Utils/SysTypeExtentions.cs @@ -2,7 +2,7 @@ namespace ReCodeIt.Utils; -internal static class StringExtentions +public static class SysTypeExtentions { /// /// Returns a string trimmed after any non letter character @@ -40,8 +40,7 @@ internal static class StringExtentions } /// - /// Does the property or field name exist in a given list, this applies prefixes and handles - /// capitalization. + /// Does the property or field name exist in a given list, this applies prefixes and handles capitalization. /// /// ///