mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Add log file compression
This commit is contained in:
@@ -160,6 +160,13 @@ namespace MPF.Data
|
||||
/// <returns></returns>
|
||||
public bool IsValid() => GenerateParameters() != null;
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of all log files generated
|
||||
/// </summary>
|
||||
/// <param name="basePath">Base filename and path to use for checking</param>
|
||||
/// <returns>List of all log file paths, empty otherwise</returns>
|
||||
public List<string> GetLogFilePaths(string basePath) => new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Reset all special variables to have default values
|
||||
/// </summary>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compress log files to save space
|
||||
/// </summary>
|
||||
/// <returns>True if the process succeeded, false otherwise</returns>
|
||||
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
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
<IncludeAssets>runtime; compile; build; native; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
|
||||
<PackageReference Include="System.Management" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user