0
0
mirror of https://github.com/sp-tarkov/assembly-tool.git synced 2025-02-12 21:10:45 -05:00

Clean up logging, add progress bars

This commit is contained in:
Cj 2024-12-31 04:48:12 -05:00
parent 33e68f4ca7
commit b3a676f044
5 changed files with 50 additions and 18 deletions

View File

@ -1,5 +1,6 @@
using dnlib.DotNet;
using System.Runtime.CompilerServices;
using ReCodeIt.Utils;
namespace ReCodeIt.ReMapper;
@ -12,12 +13,16 @@ internal static class SPTPublicizer
var types = definition.GetTypes();
MainModule = definition;
var typeCount = types.Where(t => !t.IsNested).Count();
var count = 0;
foreach (var type in types)
{
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
PublicizeType(type, isLauncher);
Logger.DrawProgressBar(count, typeCount - 1, 50);
count++;
}
}

View File

@ -85,6 +85,8 @@ public class ReCodeItRemapper
GenerateDynamicRemaps(assemblyPath, types);
}
Logger.LogSync("Finding Best Matches...", ConsoleColor.Green);
var tasks = new List<Task>(remapModels.Count);
foreach (var remap in remapModels)
{
@ -95,6 +97,12 @@ public class ReCodeItRemapper
})
);
}
while (!tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
{
Logger.DrawProgressBar(tasks.Where(t => t.IsCompleted)!.Count(), tasks.Count, 50);
}
Task.WaitAll(tasks.ToArray());
ChooseBestMatches();
@ -106,6 +114,8 @@ public class ReCodeItRemapper
return;
}
Logger.LogSync("\nRenaming...", ConsoleColor.Green);
var renameTasks = new List<Task>(remapModels.Count);
foreach (var remap in remapModels)
{
@ -116,12 +126,18 @@ public class ReCodeItRemapper
})
);
}
while (!renameTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
{
Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count(), tasks.Count - 1, 50);
}
Task.WaitAll(renameTasks.ToArray());
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
if (Settings!.MappingSettings!.Publicize)
{
Logger.Log("Publicizing classes...", ConsoleColor.Yellow);
Logger.LogSync("\nPublicizing classes...", ConsoleColor.Green);
SPTPublicizer.PublicizeClasses(Module);
}
@ -493,9 +509,7 @@ public class ReCodeItRemapper
if (DataProvider.ItemTemplates!.TryGetValue(type.Key, out var template))
{
if (!type.Value.Name.StartsWith("GClass")) continue;
Logger.Log($"Key: {type.Key} Type: {type.Value.Name} Associated to {template._name}", ConsoleColor.Green);
var remap = new RemapModel
{
OriginalTypeName = type.Value.Name,
@ -507,7 +521,7 @@ public class ReCodeItRemapper
continue;
}
Logger.Log($"Found no association for key: {type.Key} Type: {type.Value}", ConsoleColor.Yellow);
// Logger.Log($"Found no association for key: {type.Key} Type: {type.Value}", ConsoleColor.Yellow);
}
}
@ -577,7 +591,7 @@ public class ReCodeItRemapper
throw;
}
Logger.Log("Creating Hollow...", ConsoleColor.Yellow);
Logger.Log("\nCreating Hollow...", ConsoleColor.Yellow);
Hollow();
var hollowedDir = Path.GetDirectoryName(OutPath);

View File

@ -41,8 +41,6 @@ internal static class RenameHelper
FixMethods(types, remap);
RenameType(types, remap);
Logger.Log($"{remap!.TypePrimeCandidate!.Name.String} Renamed.", ConsoleColor.Green);
}
private static void FixMethods(

View File

@ -36,8 +36,6 @@ public static class DataProvider
};
Settings = JsonConvert.DeserializeObject<Settings>(jsonText, settings);
Logger.Log($"Settings loaded from '{settingsPath}'");
}
public static void SaveAppSettings()
@ -75,12 +73,8 @@ public static class DataProvider
var jsonText = File.ReadAllText(path);
var remaps = JsonConvert.DeserializeObject<List<RemapModel>>(jsonText);
if (remaps == null) { return []; }
Logger.Log($"Mapping file loaded from '{path}' containing {remaps.Count} remaps");
return remaps;
return remaps!;
}
public static void SaveMapping()

View File

@ -82,6 +82,20 @@ public static class Logger
return !IsTerminated;
}
public static void DrawProgressBar(int progress, int total, int width)
{
Console.CursorVisible = false;
Console.SetCursorPosition(0, Console.CursorTop);
double percentage = (double)progress / total;
int completed = (int)(percentage * width);
Console.Write("[");
Console.Write(new string('=', completed)); // Completed part
Console.Write(new string(' ', width - completed)); // Remaining part
Console.Write($"] {progress}/{total} ({percentage:P0})");
}
private const string _defaultFileName = "ReCodeIt.log";
private static string _logPath => Path.Combine(AppContext.BaseDirectory, "Data", "ReCodeIt.log");
public static void ClearLog()
@ -97,6 +111,13 @@ public static class Logger
{
_messages.Enqueue(new LogMessage {Message = message, Color = color, Silent = silent, ThreadId = Thread.CurrentThread.ManagedThreadId});
}
public static void LogSync(string message, ConsoleColor color = ConsoleColor.White)
{
Console.ForegroundColor = color;
Console.WriteLine(message);
Console.ResetColor();
}
private static void LogInternal(LogMessage message)
{