From 80c7d1ef2141a789735c2d53827b74ea4ad7da17 Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:48:48 -0500 Subject: [PATCH] Simplify app settings, remove unused code --- Assets/Templates/Settings.jsonc | 28 +++----- ReCodeItCLI/Commands/AutoMatcher.cs | 1 - ReCodeItCLI/Commands/DeObfuscate.cs | 1 - ReCodeItCLI/Commands/Dumper.cs | 1 - ReCodeItCLI/Commands/ReMap.cs | 3 +- RecodeItLib/Models/AppSettingsModel.cs | 99 +------------------------- RecodeItLib/Remapper/AutoMatcher.cs | 2 +- RecodeItLib/Remapper/ReMapper.cs | 9 +-- RecodeItLib/Remapper/Renamer.cs | 2 +- RecodeItLib/Utils/DataProvider.cs | 45 ------------ 10 files changed, 18 insertions(+), 173 deletions(-) diff --git a/Assets/Templates/Settings.jsonc b/Assets/Templates/Settings.jsonc index 601cd0f..1a63339 100644 --- a/Assets/Templates/Settings.jsonc +++ b/Assets/Templates/Settings.jsonc @@ -1,20 +1,12 @@ { - "AppSettings": { - "Debug": false, - "SilentMode": true - }, - "Remapper": { - "AssemblyPath": "", - "OutputPath": "", - "MappingPath": "", - "TokensToMatch": [ - "Class", - "GClass", - "GStruct", - "GControl", - "ValueStruct", - "Interface", - "GInterface" - ] - } + "MappingPath": "", + "TokensToMatch": [ + "Class", + "GClass", + "GStruct", + "GControl", + "ValueStruct", + "Interface", + "GInterface" + ] } \ No newline at end of file diff --git a/ReCodeItCLI/Commands/AutoMatcher.cs b/ReCodeItCLI/Commands/AutoMatcher.cs index b1d2bbd..cf598af 100644 --- a/ReCodeItCLI/Commands/AutoMatcher.cs +++ b/ReCodeItCLI/Commands/AutoMatcher.cs @@ -25,7 +25,6 @@ public class AutoMatchCommand : ICommand public ValueTask ExecuteAsync(IConsole console) { - DataProvider.IsCli = true; DataProvider.LoadAppSettings(); Logger.LogSync("Finding match..."); diff --git a/ReCodeItCLI/Commands/DeObfuscate.cs b/ReCodeItCLI/Commands/DeObfuscate.cs index db5b0e7..c5be8ce 100644 --- a/ReCodeItCLI/Commands/DeObfuscate.cs +++ b/ReCodeItCLI/Commands/DeObfuscate.cs @@ -17,7 +17,6 @@ public class DeObfuscate : ICommand public ValueTask ExecuteAsync(IConsole console) { - DataProvider.IsCli = true; DataProvider.LoadAppSettings(); Logger.Log("Deobfuscating assembly..."); diff --git a/ReCodeItCLI/Commands/Dumper.cs b/ReCodeItCLI/Commands/Dumper.cs index 0bcd25f..5123e52 100644 --- a/ReCodeItCLI/Commands/Dumper.cs +++ b/ReCodeItCLI/Commands/Dumper.cs @@ -14,7 +14,6 @@ public class Dumper : ICommand public ValueTask ExecuteAsync(IConsole console) { - DataProvider.IsCli = true; DataProvider.LoadAppSettings(); Logger.Log("Creating DumperClass..."); diff --git a/ReCodeItCLI/Commands/ReMap.cs b/ReCodeItCLI/Commands/ReMap.cs index 50e57f1..a916256 100644 --- a/ReCodeItCLI/Commands/ReMap.cs +++ b/ReCodeItCLI/Commands/ReMap.cs @@ -19,9 +19,8 @@ public class ReMap : ICommand public ValueTask ExecuteAsync(IConsole console) { - DataProvider.IsCli = true; DataProvider.LoadAppSettings(); - DataProvider.Settings.Remapper.MappingPath = MappingJsonPath; + DataProvider.Settings.MappingPath = MappingJsonPath; var remaps = DataProvider.LoadMappingFile(MappingJsonPath); diff --git a/RecodeItLib/Models/AppSettingsModel.cs b/RecodeItLib/Models/AppSettingsModel.cs index eaabb73..656ceab 100644 --- a/RecodeItLib/Models/AppSettingsModel.cs +++ b/RecodeItLib/Models/AppSettingsModel.cs @@ -7,108 +7,13 @@ namespace ReCodeItLib.Models; /// public class Settings { - 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 void Save() - { - DataProvider.SaveAppSettings(); - } -} - -/// -/// These are settings for the application -/// -public class AppSettings -{ - 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(); - } -} - -/// -/// These are settings for the manual remapper -/// -public class RemapperSettings -{ - private string _mappingPath = string.Empty; - /// /// Path to the mapping file /// - public string MappingPath - { - get { return _mappingPath; } - set - { - _mappingPath = value; - Save(); - } - } + public string MappingPath { get; set; } = string.Empty; - private List _tokensToMatch = []; - /// /// The re-mapper will look for these tokens in class names, otherwise they will be skipped /// - public List TokensToMatch - { - get { return _tokensToMatch; } - set - { - _tokensToMatch = value; - Save(); - } - } - - private void Save() - { - DataProvider.SaveAppSettings(); - } + public required List TokensToMatch { get; set; } } \ No newline at end of file diff --git a/RecodeItLib/Remapper/AutoMatcher.cs b/RecodeItLib/Remapper/AutoMatcher.cs index 03150ec..59843a7 100644 --- a/RecodeItLib/Remapper/AutoMatcher.cs +++ b/RecodeItLib/Remapper/AutoMatcher.cs @@ -10,7 +10,7 @@ public class AutoMatcher(List mappings, string mappingPath) private List? CandidateTypes { get; set; } - private static List _tokens = DataProvider.Settings!.Remapper!.TokensToMatch; + private static List _tokens = DataProvider.Settings!.TokensToMatch; public void AutoMatch(string assemblyPath, string oldTypeName, string newTypeName) { diff --git a/RecodeItLib/Remapper/ReMapper.cs b/RecodeItLib/Remapper/ReMapper.cs index 5c50bfb..229a835 100644 --- a/RecodeItLib/Remapper/ReMapper.cs +++ b/RecodeItLib/Remapper/ReMapper.cs @@ -15,9 +15,6 @@ public class ReMapper public static bool IsRunning { get; private set; } = false; private static readonly Stopwatch Stopwatch = new(); - - private RemapperSettings? Settings => DataProvider.Settings?.Remapper; - private string OutPath { get; set; } = string.Empty; private List _remaps = []; @@ -167,7 +164,7 @@ public class ReMapper /// Mapping to score private void ScoreMapping(RemapModel mapping, IEnumerable types) { - var tokens = DataProvider.Settings?.Remapper?.TokensToMatch; + var tokens = DataProvider.Settings?.TokensToMatch; if (mapping.UseForceRename) { @@ -347,9 +344,9 @@ public class ReMapper throw; } - if (DataProvider.Settings?.Remapper?.MappingPath != string.Empty) + if (DataProvider.Settings?.MappingPath != string.Empty) { - DataProvider.UpdateMapping(DataProvider.Settings!.Remapper!.MappingPath.Replace("mappings.", "mappings-new."), _remaps); + DataProvider.UpdateMapping(DataProvider.Settings!.MappingPath!.Replace("mappings.", "mappings-new."), _remaps); } new Statistics(_remaps, Stopwatch, OutPath, hollowedPath) diff --git a/RecodeItLib/Remapper/Renamer.cs b/RecodeItLib/Remapper/Renamer.cs index d473fd0..afa1875 100644 --- a/RecodeItLib/Remapper/Renamer.cs +++ b/RecodeItLib/Remapper/Renamer.cs @@ -6,7 +6,7 @@ namespace ReCodeItLib.ReMapper; internal class Renamer { - private static List? TokensToMatch => DataProvider.Settings?.Remapper?.TokensToMatch; + private static List TokensToMatch => DataProvider.Settings!.TokensToMatch; /// /// Only used by the manual remapper, should probably be removed diff --git a/RecodeItLib/Utils/DataProvider.cs b/RecodeItLib/Utils/DataProvider.cs index 326025e..93a60e5 100644 --- a/RecodeItLib/Utils/DataProvider.cs +++ b/RecodeItLib/Utils/DataProvider.cs @@ -12,11 +12,6 @@ public static class DataProvider LoadItems(); } - /// - /// Is this running in the CLI? - /// - public static bool IsCli { get; set; } = false; - public static string DataPath => Path.Combine(AppContext.BaseDirectory, "Data"); public static List Remaps { get; set; } = []; @@ -38,30 +33,6 @@ public static class DataProvider Settings = JsonConvert.DeserializeObject(jsonText, settings); } - public static void SaveAppSettings() - { - if (IsCli) { return; } - - var settingsPath = Path.Combine(DataPath, "Settings.jsonc"); - - if (!File.Exists(settingsPath)) - { - Logger.Log($"path `{settingsPath}` does not exist. Could not save settings", ConsoleColor.Red); - return; - } - - JsonSerializerSettings settings = new() - { - Formatting = Formatting.Indented - }; - - var jsonText = JsonConvert.SerializeObject(Settings, settings); - - File.WriteAllText(settingsPath, jsonText); - - //Logger.Log($"App settings saved to {settingsPath}"); - } - public static List LoadMappingFile(string path) { if (!File.Exists(path)) @@ -77,22 +48,6 @@ public static class DataProvider return remaps ?? []; } - public static void SaveMapping() - { - JsonSerializerSettings settings = new() - { - NullValueHandling = NullValueHandling.Ignore, - Formatting = Formatting.Indented - }; - - var path = Settings?.Remapper?.MappingPath; - - var jsonText = JsonConvert.SerializeObject(Remaps, settings); - - File.WriteAllText(path!, jsonText); - Logger.Log($"Mapping File Saved To {path}"); - } - public static void UpdateMapping(string path, List remaps) { if (!File.Exists(path))