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

Add threading to publicizer

This commit is contained in:
Cj 2025-01-02 02:29:02 -05:00
parent 533ab39f30
commit dca2d61edb
3 changed files with 19 additions and 9 deletions

View File

@ -9,16 +9,25 @@ internal static class SPTPublicizer
{ {
var types = definition.GetTypes(); var types = definition.GetTypes();
var typeCount = types.Where(t => !t.IsNested).Count(); var publicizeTasks = new List<Task>();
var count = 0;
foreach (var type in types) foreach (var type in types)
{ {
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
PublicizeType(type, isLauncher); publicizeTasks.Add(
Logger.DrawProgressBar(count, typeCount - 1, 50); Task.Factory.StartNew(() =>
count++; {
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) private static void PublicizeType(TypeDef type, bool isLauncher)

View File

@ -75,6 +75,7 @@ public class ReMapper
} }
RenameMatches(types); RenameMatches(types);
Publicize(); Publicize();
// We are done, write the assembly // We are done, write the assembly
@ -100,7 +101,7 @@ public class ReMapper
{ {
while (!tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion)) 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)) 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()); Task.WaitAll(renameTasks.ToArray());

View File

@ -89,8 +89,8 @@ public static class Logger
Console.CursorVisible = false; Console.CursorVisible = false;
Console.SetCursorPosition(0, Console.CursorTop); Console.SetCursorPosition(0, Console.CursorTop);
double percentage = (double)progress / total; var percentage = (double)progress / total;
int completed = (int)(percentage * width); var completed = (int)(percentage * width);
Console.Write("["); Console.Write("[");
Console.Write(new string('=', completed)); // Completed part Console.Write(new string('=', completed)); // Completed part