From dca2d61edb3de4cd1d79fc0151ff0ae169ce038e Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Thu, 2 Jan 2025 02:29:02 -0500 Subject: [PATCH] Add threading to publicizer --- RecodeItLib/Remapper/Publicizer.cs | 19 ++++++++++++++----- RecodeItLib/Remapper/ReMapper.cs | 5 +++-- RecodeItLib/Utils/Logger.cs | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/RecodeItLib/Remapper/Publicizer.cs b/RecodeItLib/Remapper/Publicizer.cs index 96d3257..40f6bea 100644 --- a/RecodeItLib/Remapper/Publicizer.cs +++ b/RecodeItLib/Remapper/Publicizer.cs @@ -9,16 +9,25 @@ internal static class SPTPublicizer { var types = definition.GetTypes(); - var typeCount = types.Where(t => !t.IsNested).Count(); - var count = 0; + var publicizeTasks = new List(); 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++; + publicizeTasks.Add( + Task.Factory.StartNew(() => + { + PublicizeType(type, isLauncher); + }) + ); } + + while (!publicizeTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion)) + { + Logger.DrawProgressBar(publicizeTasks.Where(t => t.IsCompleted)!.Count() + 1, publicizeTasks.Count, 50); + } + + Task.WaitAll(publicizeTasks.ToArray()); } private static void PublicizeType(TypeDef type, bool isLauncher) diff --git a/RecodeItLib/Remapper/ReMapper.cs b/RecodeItLib/Remapper/ReMapper.cs index 4b9e3ab..4c6746f 100644 --- a/RecodeItLib/Remapper/ReMapper.cs +++ b/RecodeItLib/Remapper/ReMapper.cs @@ -75,6 +75,7 @@ public class ReMapper } RenameMatches(types); + Publicize(); // We are done, write the assembly @@ -100,7 +101,7 @@ public class ReMapper { while (!tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion)) { - Logger.DrawProgressBar(tasks.Where(t => t.IsCompleted)!.Count(), tasks.Count, 50); + Logger.DrawProgressBar(tasks.Where(t => t.IsCompleted)!.Count() + 1, tasks.Count, 50); } } @@ -124,7 +125,7 @@ public class ReMapper while (!renameTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion)) { - Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count(), renameTasks.Count, 50); + Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count() + 1, renameTasks.Count, 50); } Task.WaitAll(renameTasks.ToArray()); diff --git a/RecodeItLib/Utils/Logger.cs b/RecodeItLib/Utils/Logger.cs index 30769ba..61be1e0 100644 --- a/RecodeItLib/Utils/Logger.cs +++ b/RecodeItLib/Utils/Logger.cs @@ -89,8 +89,8 @@ public static class Logger Console.CursorVisible = false; Console.SetCursorPosition(0, Console.CursorTop); - double percentage = (double)progress / total; - int completed = (int)(percentage * width); + var percentage = (double)progress / total; + var completed = (int)(percentage * width); Console.Write("["); Console.Write(new string('=', completed)); // Completed part