diff --git a/MPF.Library/Data/BaseParameters.cs b/MPF.Library/Data/BaseParameters.cs index 23436a8b..26d23f85 100644 --- a/MPF.Library/Data/BaseParameters.cs +++ b/MPF.Library/Data/BaseParameters.cs @@ -160,6 +160,13 @@ namespace MPF.Data /// public bool IsValid() => GenerateParameters() != null; + /// + /// Generate a list of all log files generated + /// + /// Base filename and path to use for checking + /// List of all log file paths, empty otherwise + public List GetLogFilePaths(string basePath) => new List(); + /// /// Reset all special variables to have default values /// diff --git a/MPF.Library/Data/DumpEnvironment.cs b/MPF.Library/Data/DumpEnvironment.cs index 8408c479..f45f68ef 100644 --- a/MPF.Library/Data/DumpEnvironment.cs +++ b/MPF.Library/Data/DumpEnvironment.cs @@ -478,6 +478,10 @@ namespace MPF.Data resultProgress?.Report(Result.Failure("Writing could not complete!")); } + // Conpress the logs, if required + if (Options.CompressLogFiles) + CompressLogFiles(); + resultProgress?.Report(Result.Success("Submission information process complete!")); return Result.Success(); } @@ -1292,6 +1296,51 @@ namespace MPF.Data return true; } + /// + /// Compress log files to save space + /// + /// True if the process succeeded, false otherwise + private bool CompressLogFiles() + { + // Prepare the necessary paths + string outputFilename = Path.GetFileNameWithoutExtension(OutputFilename); + string combinedBase = Path.Combine(OutputDirectory, outputFilename); + string archiveName = Path.Combine(OutputDirectory, "!dumpinfo.zip"); + + // Get the list of log files from the parameters object + var files = Parameters.GetLogFilePaths(combinedBase); + if (!files.Any()) + return true; + + // Add the log files to the archive and delete the uncompressed file after + ZipArchive zf = null; + try + { + zf = ZipFile.Open(archiveName, ZipArchiveMode.Create); + foreach (string file in files) + { + string entryName = file.Substring(OutputDirectory.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + zf.CreateEntryFromFile(file, entryName); + + try + { + File.Delete(file); + } + catch { } + } + + return true; + } + catch + { + return false; + } + finally + { + zf?.Dispose(); + } + } + #endregion #region Information Extraction diff --git a/MPF.Library/MPF.Library.csproj b/MPF.Library/MPF.Library.csproj index b70fa54b..b7904a7a 100644 --- a/MPF.Library/MPF.Library.csproj +++ b/MPF.Library/MPF.Library.csproj @@ -71,6 +71,7 @@ runtime; compile; build; native; analyzers; buildtransitive +