From 4540b4e4d897d60e6cbdecf4ce712ebb72090ae2 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 2 May 2026 13:28:26 +0200 Subject: Update various patches --- .../Patches/Implementations/PatchSet.cs | 60 ++++++++++++++++++---- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'ReferenceClientProxyImplementation/Patches/Implementations/PatchSet.cs') 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 ActivePatchStates { get; } = []; public List Patches { get; } = sp.GetServices().OrderBy(x => x.GetOrder()).ToList(); - public async Task ApplyPatches(string relativeName, byte[] content) { + public async Task 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 -- cgit 1.5.1