try-catch parallel operations #18

Merged
waffle.lord merged 1 commits from fix/change-ui-on-fail into main 2024-05-18 12:49:43 -04:00
2 changed files with 154 additions and 136 deletions

View File

@ -298,6 +298,10 @@ namespace PatcherUtils
RaiseProgressChanged(0, fileCountTotal, "Generating deltas...");
try
{
Parallel.ForEach(targetFiles,
new ParallelOptions() { MaxDegreeOfParallelism = 5 }, targetFile =>
{
@ -349,6 +353,11 @@ namespace PatcherUtils
RaiseProgressChanged(filesProcessed, fileCountTotal,
$"{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
PatchLogger.LogInfo(":: Updating Source List ::");
@ -456,7 +465,10 @@ namespace PatcherUtils
fileCountTotal = deltaFiles.Count;
var patchingTokenSource = new CancellationTokenSource();
// foreach (FileInfo deltaFile in deltaDir.GetFiles("*", SearchOption.AllDirectories))
try
{
Parallel.ForEach(deltaDir.GetFiles("*", SearchOption.AllDirectories).ToList(),
new ParallelOptions() { MaxDegreeOfParallelism = 5, CancellationToken = patchingTokenSource.Token },
deltaFile =>
@ -553,9 +565,15 @@ namespace PatcherUtils
++filesProcessed;
RaiseProgressChanged(filesProcessed, fileCountTotal, deltaFile.Name, AdditionalInfo.ToArray());
});
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
if (errorsQueue.Count > 0)
{
PatchLogger.LogError($"Error queue entry count: {errorsQueue.Count}");
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);