From 56e91bf177df676fd4d47ec24255c397b16db163 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 15 Aug 2023 00:47:32 -0400 Subject: [PATCH] Add dumping date to log (fixes #533) --- CHANGELIST.md | 1 + MPF.Core/Data/Constants.cs | 1 + MPF.Library/InfoTool.cs | 1 + MPF.Modules/Aaru/Parameters.cs | 1 + MPF.Modules/BaseParameters.cs | 16 ++++++++++++++++ MPF.Modules/CleanRIp/Parameters.cs | 5 ++++- MPF.Modules/DD/Parameters.cs | 4 +++- MPF.Modules/DiscImageCreator/Parameters.cs | 3 ++- MPF.Modules/Redumper/Parameters.cs | 1 + MPF.Modules/UmdImageCreator/Parameters.cs | 1 + MPF.Test/RedumpLib/SubmissionInfoTests.cs | 2 ++ MPF/ViewModels/MainViewModel.cs | 1 + RedumpLib/Data/SubmissionInfo.cs | 5 +++++ 13 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index f4f4b41b..f94cdab3 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -4,6 +4,7 @@ - Add known .NET 6 limitations to README - Remove `_drive.txt` from required UIC outputs - Make `use` flag required for MPF.Check +- Add dumping date to log ### 2.6.2 (2023-07-25) diff --git a/MPF.Core/Data/Constants.cs b/MPF.Core/Data/Constants.cs index 25800530..080409ba 100644 --- a/MPF.Core/Data/Constants.cs +++ b/MPF.Core/Data/Constants.cs @@ -85,6 +85,7 @@ namespace MPF.Core.Data // Automatic Information public const string DumpingProgramField = "Dumping Program"; + public const string DumpingDateField = "Date"; public const string DumpingDriveManufacturer = "Manufacturer"; public const string DumpingDriveModel = "Model"; public const string DumpingDriveFirmware = "Firmware"; diff --git a/MPF.Library/InfoTool.cs b/MPF.Library/InfoTool.cs index 05683413..7ce3f6f9 100644 --- a/MPF.Library/InfoTool.cs +++ b/MPF.Library/InfoTool.cs @@ -857,6 +857,7 @@ namespace MPF.Library // Dumping Info section output.Add(""); output.Add("Dumping Info:"); AddIfExists(output, Template.DumpingProgramField, info.DumpingInfo.DumpingProgram, 1); + AddIfExists(output, Template.DumpingDateField, info.DumpingInfo.DumpingDate, 1); AddIfExists(output, Template.DumpingDriveManufacturer, info.DumpingInfo.Manufacturer, 1); AddIfExists(output, Template.DumpingDriveModel, info.DumpingInfo.Model, 1); AddIfExists(output, Template.DumpingDriveFirmware, info.DumpingInfo.Firmware, 1); diff --git a/MPF.Modules/Aaru/Parameters.cs b/MPF.Modules/Aaru/Parameters.cs index 07a78763..5c287146 100644 --- a/MPF.Modules/Aaru/Parameters.cs +++ b/MPF.Modules/Aaru/Parameters.cs @@ -199,6 +199,7 @@ namespace MPF.Modules.Aaru // TODO: Determine if there's an Aaru version anywhere info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram); + info.DumpingInfo.DumpingDate = GetFileModifiedDate(basePath + ".cicm.xml")?.ToString("yyyy-MM-dd hh:mm:ss"); // Deserialize the sidecar, if possible var sidecar = GenerateSidecar(basePath + ".cicm.xml"); diff --git a/MPF.Modules/BaseParameters.cs b/MPF.Modules/BaseParameters.cs index 94f06630..59c209bc 100644 --- a/MPF.Modules/BaseParameters.cs +++ b/MPF.Modules/BaseParameters.cs @@ -1339,6 +1339,22 @@ namespace MPF.Modules return false; } + /// + /// Get the last modified date from a file path, if possible + /// + /// Path to the input file + /// Filled DateTime on success, null on failure + protected static DateTime? GetFileModifiedDate(string filename, bool fallback = false) + { + if (string.IsNullOrWhiteSpace(filename)) + return fallback ? (DateTime?)DateTime.UtcNow : null; + else if (!File.Exists(filename)) + return fallback ? (DateTime?)DateTime.UtcNow : null; + + var fi = new FileInfo(filename); + return fi.LastWriteTimeUtc; + } + /// /// Get the split values for ISO-based media /// diff --git a/MPF.Modules/CleanRIp/Parameters.cs b/MPF.Modules/CleanRIp/Parameters.cs index 0ce101ee..45eb13d1 100644 --- a/MPF.Modules/CleanRIp/Parameters.cs +++ b/MPF.Modules/CleanRIp/Parameters.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -63,6 +64,8 @@ namespace MPF.Modules.CleanRip { // TODO: Determine if there's a CleanRip version anywhere info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram); + info.DumpingInfo.DumpingDate = GetFileModifiedDate(basePath + "-dumpinfo.txt")?.ToString("yyyy-MM-dd hh:mm:ss"); + Datafile datafile = GenerateCleanripDatafile(basePath + ".iso", basePath + "-dumpinfo.txt"); // Get the individual hash data, as per internal diff --git a/MPF.Modules/DD/Parameters.cs b/MPF.Modules/DD/Parameters.cs index a87a272f..710420c3 100644 --- a/MPF.Modules/DD/Parameters.cs +++ b/MPF.Modules/DD/Parameters.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -83,6 +84,7 @@ namespace MPF.Modules.DD // TODO: Determine if there's a DD version anywhere info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram); + info.DumpingInfo.DumpingDate = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"); switch (this.Type) { diff --git a/MPF.Modules/DiscImageCreator/Parameters.cs b/MPF.Modules/DiscImageCreator/Parameters.cs index 832cb674..3ec79866 100644 --- a/MPF.Modules/DiscImageCreator/Parameters.cs +++ b/MPF.Modules/DiscImageCreator/Parameters.cs @@ -389,8 +389,9 @@ namespace MPF.Modules.DiscImageCreator string outputDirectory = Path.GetDirectoryName(basePath); // Get the dumping program and version - (_, string dicVersion) = GetCommandFilePathAndVersion(basePath); + (string dicCmd, string dicVersion) = GetCommandFilePathAndVersion(basePath); info.DumpingInfo.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {dicVersion ?? "Unknown Version"}"; + info.DumpingInfo.DumpingDate = GetFileModifiedDate(dicCmd)?.ToString("yyyy-MM-dd hh:mm:ss"); // Fill in the hardware data if (GetHardwareInfo($"{basePath}_drive.txt", out string manufacturer, out string model, out string firmware)) diff --git a/MPF.Modules/Redumper/Parameters.cs b/MPF.Modules/Redumper/Parameters.cs index 2069c11f..6e15ae3c 100644 --- a/MPF.Modules/Redumper/Parameters.cs +++ b/MPF.Modules/Redumper/Parameters.cs @@ -247,6 +247,7 @@ namespace MPF.Modules.Redumper { // Get the dumping program and version info.DumpingInfo.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {GetVersion($"{basePath}.log") ?? "Unknown Version"}"; + info.DumpingInfo.DumpingDate = GetFileModifiedDate($"{basePath}.log")?.ToString("yyyy-MM-dd hh:mm:ss"); // Fill in the hardware data if (GetHardwareInfo($"{basePath}.log", out string manufacturer, out string model, out string firmware)) diff --git a/MPF.Modules/UmdImageCreator/Parameters.cs b/MPF.Modules/UmdImageCreator/Parameters.cs index 79ecaa40..37ff9dcd 100644 --- a/MPF.Modules/UmdImageCreator/Parameters.cs +++ b/MPF.Modules/UmdImageCreator/Parameters.cs @@ -65,6 +65,7 @@ namespace MPF.Modules.UmdImageCreator { // TODO: Determine if there's a UMDImageCreator version anywhere info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram); + info.DumpingInfo.DumpingDate = GetFileModifiedDate(basePath + "_disc.txt")?.ToString("yyyy-MM-dd hh:mm:ss"); // Extract info based generically on MediaType switch (this.Type) diff --git a/MPF.Test/RedumpLib/SubmissionInfoTests.cs b/MPF.Test/RedumpLib/SubmissionInfoTests.cs index 73e5de5e..cd4e2247 100644 --- a/MPF.Test/RedumpLib/SubmissionInfoTests.cs +++ b/MPF.Test/RedumpLib/SubmissionInfoTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Newtonsoft.Json; +using psxt001z; using RedumpLib.Data; using Xunit; @@ -160,6 +161,7 @@ namespace MPF.Test.RedumpLib DumpingInfo = new DumpingInfoSection() { DumpingProgram = "DiscImageCreator 20500101", + DumpingDate = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), Manufacturer = "ATAPI", Model = "Optical Drive", Firmware = "1.23", diff --git a/MPF/ViewModels/MainViewModel.cs b/MPF/ViewModels/MainViewModel.cs index 9154acee..dc8be2a5 100644 --- a/MPF/ViewModels/MainViewModel.cs +++ b/MPF/ViewModels/MainViewModel.cs @@ -424,6 +424,7 @@ namespace MPF.UI.ViewModels DumpingInfo = new DumpingInfoSection() { DumpingProgram = "DiscImageCreator 20500101", + DumpingDate = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss"), Manufacturer = "ATAPI", Model = "Optical Drive", Firmware = "1.23", diff --git a/RedumpLib/Data/SubmissionInfo.cs b/RedumpLib/Data/SubmissionInfo.cs index 3ff6c478..3514444b 100644 --- a/RedumpLib/Data/SubmissionInfo.cs +++ b/RedumpLib/Data/SubmissionInfo.cs @@ -534,6 +534,10 @@ namespace RedumpLib.Data [JsonProperty(PropertyName = "d_dumping_program", Required = Required.AllowNull)] public string DumpingProgram { get; set; } + // Name not defined by Redump + [JsonProperty(PropertyName = "d_dumping_date", Required = Required.AllowNull)] + public string DumpingDate { get; set; } + // Name not defined by Redump [JsonProperty(PropertyName = "d_drive_manufacturer", Required = Required.AllowNull)] public string Manufacturer { get; set; } @@ -555,6 +559,7 @@ namespace RedumpLib.Data return new DumpingInfoSection { DumpingProgram = this.DumpingProgram, + DumpingDate = this.DumpingDate, Manufacturer = this.Manufacturer, Model = this.Model, Firmware = this.Firmware,