diff --git a/CHANGELIST.md b/CHANGELIST.md index 9804e0d9..0fc7df18 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -48,6 +48,7 @@ - Clarification on some options - One more note about hidden settings - Explicitly unset Redumper speed, if needed +- Simplify WriteOutputData path handling ### 3.3.0 (2025-01-03) diff --git a/MPF.Frontend/DumpEnvironment.cs b/MPF.Frontend/DumpEnvironment.cs index 92a79671..c3f8f2dd 100644 --- a/MPF.Frontend/DumpEnvironment.cs +++ b/MPF.Frontend/DumpEnvironment.cs @@ -747,38 +747,32 @@ namespace MPF.Frontend string json = JsonConvert.SerializeObject(info, Formatting.Indented); byte[] jsonBytes = Encoding.UTF8.GetBytes(json); + // Get the output path + var path = string.Empty; + if (string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix)) + path = "!submissionInfo.json"; + else if (string.IsNullOrEmpty(outputDirectory) && !string.IsNullOrEmpty(filenameSuffix)) + path = $"!submissionInfo_{filenameSuffix}.json"; + else if (!string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix)) + path = Path.Combine(outputDirectory, "!submissionInfo.json"); + else if (!string.IsNullOrEmpty(outputDirectory) && !string.IsNullOrEmpty(filenameSuffix)) + path = Path.Combine(outputDirectory, $"!submissionInfo_{filenameSuffix}.json"); + + // Ensure the extension is correct for the output + if (includedArtifacts) + path += ".gz"; + + // Create and open the output file + using var fs = File.Create(path); + // If we included artifacts, write to a GZip-compressed file if (includedArtifacts) { - var path = string.Empty; - if (string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix)) - path = "!submissionInfo.json.gz"; - else if (string.IsNullOrEmpty(outputDirectory) && !string.IsNullOrEmpty(filenameSuffix)) - path = $"!submissionInfo_{filenameSuffix}.json.gz"; - else if (!string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix)) - path = Path.Combine(outputDirectory, "!submissionInfo.json.gz"); - else if (!string.IsNullOrEmpty(outputDirectory) && !string.IsNullOrEmpty(filenameSuffix)) - path = Path.Combine(outputDirectory, $"!submissionInfo_{filenameSuffix}.json.gz"); - - using var fs = File.Create(path); using var gs = new GZipStream(fs, CompressionMode.Compress); gs.Write(jsonBytes, 0, jsonBytes.Length); } - - // Otherwise, write out to a normal JSON else { - var path = string.Empty; - if (string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix)) - path = "!submissionInfo.json"; - else if (string.IsNullOrEmpty(outputDirectory) && !string.IsNullOrEmpty(filenameSuffix)) - path = $"!submissionInfo_{filenameSuffix}.json"; - else if (!string.IsNullOrEmpty(outputDirectory) && string.IsNullOrEmpty(filenameSuffix)) - path = Path.Combine(outputDirectory, "!submissionInfo.json"); - else if (!string.IsNullOrEmpty(outputDirectory) && !string.IsNullOrEmpty(filenameSuffix)) - path = Path.Combine(outputDirectory, $"!submissionInfo_{filenameSuffix}.json"); - - using var fs = File.Create(path); fs.Write(jsonBytes, 0, jsonBytes.Length); } }