summary refs log tree commit diff
path: root/ReferenceClientProxyImplementation/Patches/Implementations/PatchSet.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ReferenceClientProxyImplementation/Patches/Implementations/PatchSet.cs60
1 files changed, 49 insertions, 11 deletions
diff --git a/ReferenceClientProxyImplementation/Patches/Implementations/PatchSet.cs b/ReferenceClientProxyImplementation/Patches/Implementations/PatchSet.cs

index c3dba59..5840e03 100644 --- a/ReferenceClientProxyImplementation/Patches/Implementations/PatchSet.cs +++ b/ReferenceClientProxyImplementation/Patches/Implementations/PatchSet.cs
@@ -1,26 +1,64 @@ +using System.Collections.Concurrent; + namespace ReferenceClientProxyImplementation.Patches.Implementations; -public class PatchSet(IServiceProvider sp) { +public class PatchSet(IServiceProvider sp) +{ + public ConcurrentDictionary<string, PatchState> ActivePatchStates { get; } = []; public List<IPatch> Patches { get; } = sp.GetServices<IPatch>().OrderBy(x => x.GetOrder()).ToList(); - public async Task<byte[]> ApplyPatches(string relativeName, byte[] content) { + public async Task<byte[]> ApplyPatches(string relativeName, byte[] content) + { var i = 0; var patches = Patches .Where(p => p.Applies(relativeName, content)) .OrderBy(p => p.GetOrder()) .ToList(); - foreach (var patch in patches) { - if (patch.Applies(relativeName, content)) { - var defaultColor = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.DarkBlue; - Console.Write("==> "); - Console.ForegroundColor = ConsoleColor.DarkGray; - Console.WriteLine($"Running task {++i}/{patches.Count}: {patch.GetName()} (Type<{patch.GetType().Name}>)"); - Console.ForegroundColor = defaultColor; - content = await patch.Execute(relativeName, content); + + if (!patches.Any()) + { + Console.WriteLine($"No patches required for {relativeName}!"); + return content; + } + + lock (ActivePatchStates) + ActivePatchStates[relativeName] = new() + { + CurrentPatch = patches[0].GetName(), + CurrentPatchIndex = 0, + TotalPatchCount = patches.Count + }; + + foreach (var patch in patches) + { + // if (patch.Applies(relativeName, content)) { + lock (ActivePatchStates) + { + ActivePatchStates[relativeName].CurrentPatchIndex = patches.IndexOf(patch); + ActivePatchStates[relativeName].CurrentPatch = patch.GetName(); } + + var defaultColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.DarkBlue; + Console.Write($"{relativeName,32} ==> "); + Console.ForegroundColor = ConsoleColor.DarkGray; + Console.WriteLine($"Running task {++i}/{patches.Count}: {patch.GetName()} (Type<{patch.GetType().Name}>)"); + Console.ForegroundColor = defaultColor; + content = await patch.Execute(relativeName, content); + // } } + lock (ActivePatchStates) + ActivePatchStates.Remove(relativeName, out _); + Console.WriteLine($"Finished patching {relativeName}, {ActivePatchStates.Count} files still processing"); + return content; } +} + +public class PatchState +{ + public required string CurrentPatch { get; set; } + public int CurrentPatchIndex { get; set; } = 0; + public required int TotalPatchCount { get; set; } } \ No newline at end of file