From ccc33bebbd641fd6d723fa45115a1cbf91a5499e Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 10 Oct 2025 08:09:49 -0400 Subject: [PATCH] Try to handle Windows-specific compression issue --- CHANGELIST.md | 1 + MPF.Processors/BaseProcessor.cs | 41 ++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 7636c4ee..153461e2 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -44,6 +44,7 @@ - Enable skeleton output for all CLI runs - Fix test broken by last commit - Support detecting split Wii for CleanRip +- Try to handle Windows-specific compression issue ### 3.4.2 (2025-09-30) diff --git a/MPF.Processors/BaseProcessor.cs b/MPF.Processors/BaseProcessor.cs index 98df3b8d..84285233 100644 --- a/MPF.Processors/BaseProcessor.cs +++ b/MPF.Processors/BaseProcessor.cs @@ -123,12 +123,13 @@ namespace MPF.Processors // Add the log files to the archive and delete the uncompressed file after ZipArchive? zf = null; + bool disposed = false; try { zf = ZipArchive.Create(); - _ = AddToArchive(zf, zippableFiles, outputDirectory, true); - _ = AddToArchive(zf, generatedFiles, outputDirectory, false); + List successful = AddToArchive(zf, zippableFiles, outputDirectory); + _ = AddToArchive(zf, generatedFiles, outputDirectory); switch (logCompression) { @@ -144,6 +145,16 @@ namespace MPF.Processors break; } + // Dispose the archive + zf?.Dispose(); + disposed = true; + + // Delete all successful files + foreach (string file in successful) + { + try { File.Delete(file); } catch { } + } + status = "Compression complete!"; return true; } @@ -154,7 +165,8 @@ namespace MPF.Processors } finally { - zf?.Dispose(); + if (!disposed) + zf?.Dispose(); } #endif } @@ -380,22 +392,22 @@ namespace MPF.Processors /// Archive to add the file to /// Full path to a set of existing files /// Directory that the existing files live in - /// Indicates if the files should be deleted after adding - /// True if all files were added successfully, false otherwise - private static bool AddToArchive(ZipArchive archive, List files, string? outputDirectory, bool delete) + /// List of all files that were successfully added + private static List AddToArchive(ZipArchive archive, List files, string? outputDirectory) { // An empty list means success if (files.Count == 0) - return true; + return []; // Loop through and add all files - bool allAdded = true; + List added = []; foreach (string file in files) { - allAdded &= AddToArchive(archive, file, outputDirectory, delete); + if (AddToArchive(archive, file, outputDirectory)) + added.Add(file); } - return allAdded; + return added; } /// @@ -404,9 +416,8 @@ namespace MPF.Processors /// Archive to add the file to /// Full path to an existing file /// Directory that the existing file lives in - /// Indicates if the file should be deleted after adding /// True if the file was added successfully, false otherwise - private static bool AddToArchive(ZipArchive archive, string file, string? outputDirectory, bool delete) + private static bool AddToArchive(ZipArchive archive, string file, string? outputDirectory) { // Check if the file exists if (!File.Exists(file)) @@ -430,12 +441,6 @@ namespace MPF.Processors return false; } - // Try to delete the file if requested - if (delete) - { - try { File.Delete(file); } catch { } - } - return true; } #endif