0
0
mirror of https://github.com/sp-tarkov/assembly-tool.git synced 2025-02-12 22:30:44 -05:00

Simplify app settings, remove unused code

This commit is contained in:
Cj 2025-01-08 21:48:48 -05:00
parent 38e5ac302d
commit 80c7d1ef21
10 changed files with 18 additions and 173 deletions

View File

@ -1,20 +1,12 @@
{ {
"AppSettings": { "MappingPath": "",
"Debug": false, "TokensToMatch": [
"SilentMode": true "Class",
}, "GClass",
"Remapper": { "GStruct",
"AssemblyPath": "", "GControl",
"OutputPath": "", "ValueStruct",
"MappingPath": "", "Interface",
"TokensToMatch": [ "GInterface"
"Class", ]
"GClass",
"GStruct",
"GControl",
"ValueStruct",
"Interface",
"GInterface"
]
}
} }

View File

@ -25,7 +25,6 @@ public class AutoMatchCommand : ICommand
public ValueTask ExecuteAsync(IConsole console) public ValueTask ExecuteAsync(IConsole console)
{ {
DataProvider.IsCli = true;
DataProvider.LoadAppSettings(); DataProvider.LoadAppSettings();
Logger.LogSync("Finding match..."); Logger.LogSync("Finding match...");

View File

@ -17,7 +17,6 @@ public class DeObfuscate : ICommand
public ValueTask ExecuteAsync(IConsole console) public ValueTask ExecuteAsync(IConsole console)
{ {
DataProvider.IsCli = true;
DataProvider.LoadAppSettings(); DataProvider.LoadAppSettings();
Logger.Log("Deobfuscating assembly..."); Logger.Log("Deobfuscating assembly...");

View File

@ -14,7 +14,6 @@ public class Dumper : ICommand
public ValueTask ExecuteAsync(IConsole console) public ValueTask ExecuteAsync(IConsole console)
{ {
DataProvider.IsCli = true;
DataProvider.LoadAppSettings(); DataProvider.LoadAppSettings();
Logger.Log("Creating DumperClass..."); Logger.Log("Creating DumperClass...");

View File

@ -19,9 +19,8 @@ public class ReMap : ICommand
public ValueTask ExecuteAsync(IConsole console) public ValueTask ExecuteAsync(IConsole console)
{ {
DataProvider.IsCli = true;
DataProvider.LoadAppSettings(); DataProvider.LoadAppSettings();
DataProvider.Settings.Remapper.MappingPath = MappingJsonPath; DataProvider.Settings.MappingPath = MappingJsonPath;
var remaps = DataProvider.LoadMappingFile(MappingJsonPath); var remaps = DataProvider.LoadMappingFile(MappingJsonPath);

View File

@ -7,108 +7,13 @@ namespace ReCodeItLib.Models;
/// </summary> /// </summary>
public class Settings 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();
}
}
/// <summary>
/// These are settings for the application
/// </summary>
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();
}
}
/// <summary>
/// These are settings for the manual remapper
/// </summary>
public class RemapperSettings
{
private string _mappingPath = string.Empty;
/// <summary> /// <summary>
/// Path to the mapping file /// Path to the mapping file
/// </summary> /// </summary>
public string MappingPath public string MappingPath { get; set; } = string.Empty;
{
get { return _mappingPath; }
set
{
_mappingPath = value;
Save();
}
}
private List<string> _tokensToMatch = [];
/// <summary> /// <summary>
/// The re-mapper will look for these tokens in class names, otherwise they will be skipped /// The re-mapper will look for these tokens in class names, otherwise they will be skipped
/// </summary> /// </summary>
public List<string> TokensToMatch public required List<string> TokensToMatch { get; set; }
{
get { return _tokensToMatch; }
set
{
_tokensToMatch = value;
Save();
}
}
private void Save()
{
DataProvider.SaveAppSettings();
}
} }

View File

@ -10,7 +10,7 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
private List<TypeDef>? CandidateTypes { get; set; } private List<TypeDef>? CandidateTypes { get; set; }
private static List<string> _tokens = DataProvider.Settings!.Remapper!.TokensToMatch; private static List<string> _tokens = DataProvider.Settings!.TokensToMatch;
public void AutoMatch(string assemblyPath, string oldTypeName, string newTypeName) public void AutoMatch(string assemblyPath, string oldTypeName, string newTypeName)
{ {

View File

@ -15,9 +15,6 @@ public class ReMapper
public static bool IsRunning { get; private set; } = false; public static bool IsRunning { get; private set; } = false;
private static readonly Stopwatch Stopwatch = new(); private static readonly Stopwatch Stopwatch = new();
private RemapperSettings? Settings => DataProvider.Settings?.Remapper;
private string OutPath { get; set; } = string.Empty; private string OutPath { get; set; } = string.Empty;
private List<RemapModel> _remaps = []; private List<RemapModel> _remaps = [];
@ -167,7 +164,7 @@ public class ReMapper
/// <param name="mapping">Mapping to score</param> /// <param name="mapping">Mapping to score</param>
private void ScoreMapping(RemapModel mapping, IEnumerable<TypeDef> types) private void ScoreMapping(RemapModel mapping, IEnumerable<TypeDef> types)
{ {
var tokens = DataProvider.Settings?.Remapper?.TokensToMatch; var tokens = DataProvider.Settings?.TokensToMatch;
if (mapping.UseForceRename) if (mapping.UseForceRename)
{ {
@ -347,9 +344,9 @@ public class ReMapper
throw; 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) new Statistics(_remaps, Stopwatch, OutPath, hollowedPath)

View File

@ -6,7 +6,7 @@ namespace ReCodeItLib.ReMapper;
internal class Renamer internal class Renamer
{ {
private static List<string>? TokensToMatch => DataProvider.Settings?.Remapper?.TokensToMatch; private static List<string> TokensToMatch => DataProvider.Settings!.TokensToMatch;
/// <summary> /// <summary>
/// Only used by the manual remapper, should probably be removed /// Only used by the manual remapper, should probably be removed

View File

@ -12,11 +12,6 @@ public static class DataProvider
LoadItems(); LoadItems();
} }
/// <summary>
/// Is this running in the CLI?
/// </summary>
public static bool IsCli { get; set; } = false;
public static string DataPath => Path.Combine(AppContext.BaseDirectory, "Data"); public static string DataPath => Path.Combine(AppContext.BaseDirectory, "Data");
public static List<RemapModel> Remaps { get; set; } = []; public static List<RemapModel> Remaps { get; set; } = [];
@ -38,30 +33,6 @@ public static class DataProvider
Settings = JsonConvert.DeserializeObject<Settings>(jsonText, settings); Settings = JsonConvert.DeserializeObject<Settings>(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<RemapModel> LoadMappingFile(string path) public static List<RemapModel> LoadMappingFile(string path)
{ {
if (!File.Exists(path)) if (!File.Exists(path))
@ -77,22 +48,6 @@ public static class DataProvider
return remaps ?? []; 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<RemapModel> remaps) public static void UpdateMapping(string path, List<RemapModel> remaps)
{ {
if (!File.Exists(path)) if (!File.Exists(path))