Merge pull request 'try-catch parallel operations' (#18) from fix/change-ui-on-fail into main

Reviewed-on: #18
This commit is contained in:
IsWaffle 2024-05-18 16:49:38 +00:00
commit 66f1832c21
2 changed files with 154 additions and 136 deletions

View File

@ -298,6 +298,10 @@ namespace PatcherUtils
RaiseProgressChanged(0, fileCountTotal, "Generating deltas..."); RaiseProgressChanged(0, fileCountTotal, "Generating deltas...");
try
{
Parallel.ForEach(targetFiles, Parallel.ForEach(targetFiles,
new ParallelOptions() { MaxDegreeOfParallelism = 5 }, targetFile => new ParallelOptions() { MaxDegreeOfParallelism = 5 }, targetFile =>
{ {
@ -349,6 +353,11 @@ namespace PatcherUtils
RaiseProgressChanged(filesProcessed, fileCountTotal, RaiseProgressChanged(filesProcessed, fileCountTotal,
$"{targetFile.FullName.Replace(TargetFolder, "...")}{extension}", AdditionalInfo.ToArray()); $"{targetFile.FullName.Replace(TargetFolder, "...")}{extension}", AdditionalInfo.ToArray());
}); });
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
// remove all queued files that were found in the source files list // remove all queued files that were found in the source files list
PatchLogger.LogInfo(":: Updating Source List ::"); PatchLogger.LogInfo(":: Updating Source List ::");
@ -456,9 +465,12 @@ namespace PatcherUtils
fileCountTotal = deltaFiles.Count; fileCountTotal = deltaFiles.Count;
var patchingTokenSource = new CancellationTokenSource(); var patchingTokenSource = new CancellationTokenSource();
// foreach (FileInfo deltaFile in deltaDir.GetFiles("*", SearchOption.AllDirectories)) try
{
Parallel.ForEach(deltaDir.GetFiles("*", SearchOption.AllDirectories).ToList(), Parallel.ForEach(deltaDir.GetFiles("*", SearchOption.AllDirectories).ToList(),
new ParallelOptions() { MaxDegreeOfParallelism = 5, CancellationToken = patchingTokenSource.Token}, new ParallelOptions() { MaxDegreeOfParallelism = 5, CancellationToken = patchingTokenSource.Token },
deltaFile => deltaFile =>
{ {
switch (deltaFile.Extension) switch (deltaFile.Extension)
@ -553,9 +565,15 @@ namespace PatcherUtils
++filesProcessed; ++filesProcessed;
RaiseProgressChanged(filesProcessed, fileCountTotal, deltaFile.Name, AdditionalInfo.ToArray()); RaiseProgressChanged(filesProcessed, fileCountTotal, deltaFile.Name, AdditionalInfo.ToArray());
}); });
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
if (errorsQueue.Count > 0) if (errorsQueue.Count > 0)
{ {
PatchLogger.LogError($"Error queue entry count: {errorsQueue.Count}");
if (!errorsQueue.TryDequeue(out PatchMessage error)) if (!errorsQueue.TryDequeue(out PatchMessage error))
{ {
return new PatchMessage("Errors occurred during patching, but we couldn't dequeue them :(\n\nThere may be more information in the log", PatcherExitCode.PatchFailed); return new PatchMessage("Errors occurred during patching, but we couldn't dequeue them :(\n\nThere may be more information in the log", PatcherExitCode.PatchFailed);