From bf181e229489ea54003631c4e52df69dab805488 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 7 Oct 2025 18:07:46 -0400 Subject: [PATCH] Start wiring through log compression changes --- CHANGELIST.md | 1 + MPF.CLI/Features/BaseFeature.cs | 2 ++ MPF.Check/Features/BaseFeature.cs | 2 ++ MPF.Check/Features/InteractiveFeature.cs | 2 ++ MPF.Check/Features/MainFeature.cs | 2 ++ MPF.Frontend.Test/EnumExtensionsTests.cs | 12 +++++++ MPF.Frontend/DumpEnvironment.cs | 2 +- MPF.Frontend/EnumExtensions.cs | 40 +++++++++++++++++++++ MPF.Frontend/Options.cs | 17 +++++++++ MPF.Frontend/ViewModels/OptionsViewModel.cs | 16 +++++++++ MPF.Processors/BaseProcessor.cs | 18 ++++++++-- MPF.Processors/Enumerations.cs | 21 +++++++++++ MPF.UI/ElementConverter.cs | 3 ++ 13 files changed, 135 insertions(+), 3 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 91efd773..27eee81a 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -22,6 +22,7 @@ - Update packages - More consistency in commandline programs - Use GC.SharpCompress as archive handling library +- Start wiring through log compression changes ### 3.4.2 (2025-09-30) diff --git a/MPF.CLI/Features/BaseFeature.cs b/MPF.CLI/Features/BaseFeature.cs index 41b6b3c5..d89070f7 100644 --- a/MPF.CLI/Features/BaseFeature.cs +++ b/MPF.CLI/Features/BaseFeature.cs @@ -8,6 +8,7 @@ using MPF.Frontend; using MPF.Frontend.Tools; using SabreTools.RedumpLib.Data; using SabreTools.RedumpLib.Web; +using LogCompression = MPF.Processors.LogCompression; namespace MPF.CLI.Features { @@ -77,6 +78,7 @@ namespace MPF.CLI.Features OutputSubmissionJSON = false, IncludeArtifacts = false, CompressLogFiles = false, + LogCompression = LogCompression.DeflateMaximum, DeleteUnnecessaryFiles = false, CreateIRDAfterDumping = false, diff --git a/MPF.Check/Features/BaseFeature.cs b/MPF.Check/Features/BaseFeature.cs index 73d9e278..7fe30d43 100644 --- a/MPF.Check/Features/BaseFeature.cs +++ b/MPF.Check/Features/BaseFeature.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using MPF.Frontend; using SabreTools.RedumpLib.Data; using SabreTools.RedumpLib.Web; +using LogCompression = MPF.Processors.LogCompression; namespace MPF.Check.Features { @@ -52,6 +53,7 @@ namespace MPF.Check.Features OutputSubmissionJSON = false, IncludeArtifacts = false, CompressLogFiles = false, + LogCompression = LogCompression.DeflateMaximum, DeleteUnnecessaryFiles = false, CreateIRDAfterDumping = false, diff --git a/MPF.Check/Features/InteractiveFeature.cs b/MPF.Check/Features/InteractiveFeature.cs index 5672fafa..2d3b542b 100644 --- a/MPF.Check/Features/InteractiveFeature.cs +++ b/MPF.Check/Features/InteractiveFeature.cs @@ -4,6 +4,7 @@ using MPF.Frontend; using MPF.Frontend.Tools; using SabreTools.RedumpLib; using SabreTools.RedumpLib.Data; +using LogCompression = MPF.Processors.LogCompression; namespace MPF.Check.Features { @@ -50,6 +51,7 @@ namespace MPF.Check.Features OutputSubmissionJSON = false, IncludeArtifacts = false, CompressLogFiles = false, + LogCompression = LogCompression.DeflateMaximum, DeleteUnnecessaryFiles = false, CreateIRDAfterDumping = false, diff --git a/MPF.Check/Features/MainFeature.cs b/MPF.Check/Features/MainFeature.cs index e3fa47d1..b1520582 100644 --- a/MPF.Check/Features/MainFeature.cs +++ b/MPF.Check/Features/MainFeature.cs @@ -3,6 +3,7 @@ using MPF.Frontend.Tools; using SabreTools.CommandLine.Inputs; using SabreTools.RedumpLib; using SabreTools.RedumpLib.Data; +using LogCompression = MPF.Processors.LogCompression; namespace MPF.Check.Features { @@ -124,6 +125,7 @@ namespace MPF.Check.Features OutputSubmissionJSON = false, IncludeArtifacts = false, CompressLogFiles = false, + LogCompression = LogCompression.DeflateMaximum, DeleteUnnecessaryFiles = false, CreateIRDAfterDumping = false, diff --git a/MPF.Frontend.Test/EnumExtensionsTests.cs b/MPF.Frontend.Test/EnumExtensionsTests.cs index eda02a47..052cbcf1 100644 --- a/MPF.Frontend.Test/EnumExtensionsTests.cs +++ b/MPF.Frontend.Test/EnumExtensionsTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using SabreTools.RedumpLib.Data; using Xunit; +using LogCompression = MPF.Processors.LogCompression; using RedumperDriveType = MPF.ExecutionContexts.Redumper.DriveType; using RedumperReadMethod = MPF.ExecutionContexts.Redumper.ReadMethod; using RedumperSectorOrder = MPF.ExecutionContexts.Redumper.SectorOrder; @@ -29,6 +30,17 @@ namespace MPF.Frontend.Test Assert.Equal(expected, actual); } + [Theory] + [InlineData(null, "Unknown")] + [InlineData(LogCompression.DeflateDefault, "ZIP using Deflate (Level 5)")] + [InlineData(LogCompression.DeflateMaximum, "ZIP using Deflate (Level 9)")] + [InlineData(LogCompression.Zstd19, "ZIP using Zstd (Level 19)")] + public void LongName_LogCompression(LogCompression? comp, string? expected) + { + string? actual = comp.LongName(); + Assert.Equal(expected, actual); + } + [Theory] [InlineData(null, "Unknown")] [InlineData(RedumperReadMethod.NONE, "Default")] diff --git a/MPF.Frontend/DumpEnvironment.cs b/MPF.Frontend/DumpEnvironment.cs index b7e11498..023594f5 100644 --- a/MPF.Frontend/DumpEnvironment.cs +++ b/MPF.Frontend/DumpEnvironment.cs @@ -582,7 +582,7 @@ namespace MPF.Frontend await Task.Run(() => #endif { - bool compressSuccess = _processor.CompressLogFiles(mediaType, outputDirectory, outputFilename, filenameSuffix, out string compressResult); + bool compressSuccess = _processor.CompressLogFiles(mediaType, _options.LogCompression, outputDirectory, outputFilename, filenameSuffix, out string compressResult); if (compressSuccess) resultProgress.Report(ResultEventArgs.Success(compressResult)); else diff --git a/MPF.Frontend/EnumExtensions.cs b/MPF.Frontend/EnumExtensions.cs index 0479e638..eb84dc6f 100644 --- a/MPF.Frontend/EnumExtensions.cs +++ b/MPF.Frontend/EnumExtensions.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; #endif using System.Reflection; using SabreTools.RedumpLib.Data; +using LogCompression = MPF.Processors.LogCompression; using RedumperDriveType = MPF.ExecutionContexts.Redumper.DriveType; using RedumperReadMethod = MPF.ExecutionContexts.Redumper.ReadMethod; using RedumperSectorOrder = MPF.ExecutionContexts.Redumper.SectorOrder; @@ -92,6 +93,23 @@ namespace MPF.Frontend }; } + /// + /// Get the string representation of the LogCompression enum values + /// + /// LogCompression value to convert + /// String representing the value, if possible + public static string LongName(this LogCompression? comp) + { + return comp switch + { + LogCompression.DeflateDefault => "ZIP using Deflate (Level 5)", + LogCompression.DeflateMaximum => "ZIP using Deflate (Level 9)", + LogCompression.Zstd19 => "ZIP using Zstd (Level 19)", + + _ => "Unknown", + }; + } + /// /// Get the string representation of the RedumperReadMethod enum values /// @@ -232,6 +250,28 @@ namespace MPF.Frontend }; } + /// + /// Get the LogCompression enum value for a given string + /// + /// String value to convert + /// LogCompression represented by teh string, if possible + public static LogCompression ToLogCompression(this string? logCompression) + { + return (logCompression?.ToLowerInvariant()) switch + { + "deflate" + or "deflatedefault" + or "zip" => LogCompression.DeflateDefault, + "deflatemaximum" + or "max" + or "maximum" => LogCompression.DeflateMaximum, + "zstd" + or "zstd19" => LogCompression.Zstd19, + + _ => LogCompression.DeflateDefault, + }; + } + /// /// Get the RedumperReadMethod enum value for a given string /// diff --git a/MPF.Frontend/Options.cs b/MPF.Frontend/Options.cs index 4128d0da..407d1437 100644 --- a/MPF.Frontend/Options.cs +++ b/MPF.Frontend/Options.cs @@ -2,6 +2,7 @@ using SabreTools.RedumpLib.Data; using AaruSettings = MPF.ExecutionContexts.Aaru.SettingConstants; using DICSettings = MPF.ExecutionContexts.DiscImageCreator.SettingConstants; +using LogCompression = MPF.Processors.LogCompression; using RedumperDriveType = MPF.ExecutionContexts.Redumper.DriveType; using RedumperReadMethod = MPF.ExecutionContexts.Redumper.ReadMethod; using RedumperSectorOrder = MPF.ExecutionContexts.Redumper.SectorOrder; @@ -557,6 +558,22 @@ namespace MPF.Frontend set { Settings["CompressLogFiles"] = value.ToString(); } } + /// + /// Compression type used during log compression + /// + public LogCompression LogCompression + { + get + { + var valueString = GetStringSetting(Settings, "LogCompression", LogCompression.DeflateMaximum.ToString()); + return valueString.ToLogCompression(); + } + set + { + Settings["InternalProgram"] = value.ToString(); + } + } + /// /// Delete unnecessary files to reduce space /// diff --git a/MPF.Frontend/ViewModels/OptionsViewModel.cs b/MPF.Frontend/ViewModels/OptionsViewModel.cs index 7eaec789..6323ebd5 100644 --- a/MPF.Frontend/ViewModels/OptionsViewModel.cs +++ b/MPF.Frontend/ViewModels/OptionsViewModel.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel; using MPF.Frontend.ComboBoxItems; +using LogCompression = MPF.Processors.LogCompression; using RedumperDriveType = MPF.ExecutionContexts.Redumper.DriveType; using RedumperReadMethod = MPF.ExecutionContexts.Redumper.ReadMethod; using RedumperSectorOrder = MPF.ExecutionContexts.Redumper.SectorOrder; @@ -50,6 +51,11 @@ namespace MPF.Frontend.ViewModels /// public static List> InternalPrograms => PopulateInternalPrograms(); + /// + /// List of available log compression methods + /// + public static List> LogCompressions = PopulateLogCompressions(); + /// /// Current list of supported Redumper read methods /// @@ -99,6 +105,16 @@ namespace MPF.Frontend.ViewModels return internalPrograms.ConvertAll(ip => new Element(ip)); } + /// + /// Get a complete list of supported log compression methods + /// + /// + private static List> PopulateLogCompressions() + { + var logCompressions = new List { LogCompression.DeflateDefault, LogCompression.DeflateMaximum, LogCompression.Zstd19 }; + return logCompressions.ConvertAll(lc => new Element(lc)); + } + /// /// Get a complete list of supported redumper drive read methods /// diff --git a/MPF.Processors/BaseProcessor.cs b/MPF.Processors/BaseProcessor.cs index b05784f9..1c2c1762 100644 --- a/MPF.Processors/BaseProcessor.cs +++ b/MPF.Processors/BaseProcessor.cs @@ -9,7 +9,6 @@ using SabreTools.RedumpLib.Data; using SharpCompress.Archives; using SharpCompress.Archives.Zip; using SharpCompress.Common; -using SharpCompress.Compressors.Deflate; using SharpCompress.Writers; #endif @@ -77,6 +76,7 @@ namespace MPF.Processors /// Compress log files to save space /// /// Media type for controlling expected file sets + /// Compression type to use for logs /// Output folder to use as the base path /// Output filename to use as the base path /// Output filename to use as the base path @@ -84,6 +84,7 @@ namespace MPF.Processors /// True if the process succeeded, false otherwise /// Assumes filename has an extension public bool CompressLogFiles(MediaType? mediaType, + LogCompression logCompression, string? outputDirectory, string outputFilename, string? filenameSuffix, @@ -128,7 +129,20 @@ namespace MPF.Processors _ = AddToArchive(zf, zippableFiles, outputDirectory, true); _ = AddToArchive(zf, generatedFiles, outputDirectory, false); - zf.SaveTo(archiveName, new WriterOptions(CompressionType.Deflate, 9)); + switch (logCompression) + { + case LogCompression.DeflateMaximum: + zf.SaveTo(archiveName, new WriterOptions(CompressionType.Deflate, 9)); + break; + case LogCompression.Zstd19: + zf.SaveTo(archiveName, new WriterOptions(CompressionType.ZStandard, 19)); + break; + case LogCompression.DeflateDefault: + default: + zf.SaveTo(archiveName, new WriterOptions(CompressionType.Deflate, 5)); + break; + } + status = "Compression complete!"; return true; } diff --git a/MPF.Processors/Enumerations.cs b/MPF.Processors/Enumerations.cs index a2baee9d..e64f724f 100644 --- a/MPF.Processors/Enumerations.cs +++ b/MPF.Processors/Enumerations.cs @@ -1,5 +1,26 @@ namespace MPF.Processors { + /// + /// Indicates the type of compression used for logs + /// + public enum LogCompression + { + /// + /// PKZIP using DEFLATE level 5 + /// + DeflateDefault, + + /// + /// PKZIP using DEFLATE level 9 + /// + DeflateMaximum, + + /// + /// PKZIP using Zstd level 19 + /// + Zstd19, + } + /// /// Enum for SecuROM scheme type /// diff --git a/MPF.UI/ElementConverter.cs b/MPF.UI/ElementConverter.cs index 52b76125..a44fddf9 100644 --- a/MPF.UI/ElementConverter.cs +++ b/MPF.UI/ElementConverter.cs @@ -4,6 +4,7 @@ using System.Windows.Data; using MPF.Frontend; using MPF.Frontend.ComboBoxItems; using SabreTools.RedumpLib.Data; +using LogCompression = MPF.Processors.LogCompression; using RedumperDriveType = MPF.ExecutionContexts.Redumper.DriveType; using RedumperReadMethod = MPF.ExecutionContexts.Redumper.ReadMethod; using RedumperSectorOrder = MPF.ExecutionContexts.Redumper.SectorOrder; @@ -18,6 +19,7 @@ namespace MPF.UI { DiscCategory discCategory => new Element(discCategory), InternalProgram internalProgram => new Element(internalProgram), + LogCompression logCompression => new Element(logCompression), MediaType mediaType => new Element(mediaType), RedumperReadMethod readMethod => new Element(readMethod), RedumperSectorOrder sectorOrder => new Element(sectorOrder), @@ -40,6 +42,7 @@ namespace MPF.UI { Element dcElement => dcElement.Value, Element ipElement => ipElement.Value, + Element lcElement => lcElement.Value, Element mtElement => mtElement.Value, Element rmElement => rmElement.Value, Element soElement => soElement.Value,