diff --git a/CHANGELIST.md b/CHANGELIST.md index 5470d2af..8516c5be 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -4,6 +4,7 @@ - Fix CleanRip not pulling info (Deterous) - Fix XboxOne/XboxSX Filename bug (Deterous) - Trim PIC for XboxOne/XboxSX (Deterous) +- Get volume label from UIC outputs ### 3.1.8 (2024-05-09) diff --git a/MPF.Core/Modules/UmdImageCreator/Parameters.cs b/MPF.Core/Modules/UmdImageCreator/Parameters.cs index e8553aaf..79294d11 100644 --- a/MPF.Core/Modules/UmdImageCreator/Parameters.cs +++ b/MPF.Core/Modules/UmdImageCreator/Parameters.cs @@ -72,6 +72,10 @@ namespace MPF.Core.Modules.UmdImageCreator info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(this.InternalProgram); info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(basePath + "_disc.txt")?.ToString("yyyy-MM-dd HH:mm:ss"); + // Fill in the volume labels + if (GetVolumeLabels($"{basePath}_volDesc.txt", out var volLabels)) + VolumeLabels = volLabels; + // Extract info based generically on MediaType switch (this.Type) { @@ -242,6 +246,90 @@ namespace MPF.Core.Modules.UmdImageCreator } } + /// + /// Get all Volume Identifiers + /// + /// _volDesc.txt file location + /// Volume labels (by type), or null if none present + /// This is a copy of the code from DiscImageCreator and has extrandous checks + private static bool GetVolumeLabels(string volDesc, out Dictionary> volLabels) + { + // If the file doesn't exist, can't get the volume labels + volLabels = []; + if (!File.Exists(volDesc)) + return false; + + try + { + using var sr = File.OpenText(volDesc); + var line = sr.ReadLine(); + + string volType = "UNKNOWN"; + string label; + while (line != null) + { + // Trim the line for later use + line = line.Trim(); + + // ISO9660 and extensions section + if (line.StartsWith("Volume Descriptor Type: ")) + { + Int32.TryParse(line.Substring("Volume Descriptor Type: ".Length), out int volTypeInt); + volType = volTypeInt switch + { + // 0 => "Boot Record" // Should not not contain a Volume Identifier + 1 => "ISO", // ISO9660 + 2 => "Joliet", + // 3 => "Volume Partition Descriptor" // Should not not contain a Volume Identifier + // 255 => "???" // Should not not contain a Volume Identifier + _ => "UNKNOWN" // Should not contain a Volume Identifier + }; + } + // UDF section + else if (line.StartsWith("Primary Volume Descriptor Number:")) + { + volType = "UDF"; + } + // Identifier + else if (line.StartsWith("Volume Identifier: ")) + { + label = line.Substring("Volume Identifier: ".Length); + + // Remove leading non-printable character (unsure why DIC outputs this) + if (Convert.ToUInt32(label[0]) == 0x7F || Convert.ToUInt32(label[0]) < 0x20) + label = label.Substring(1); + + // Skip if label is blank + if (label == null || label.Length <= 0) + { + volType = "UNKNOWN"; + line = sr.ReadLine(); + continue; + } + + if (volLabels.ContainsKey(label)) + volLabels[label].Add(volType); + else + volLabels.Add(label, [volType]); + + // Reset volume type + volType = "UNKNOWN"; + } + + line = sr.ReadLine(); + } + + // Return true if a volume label was found + return volLabels.Count > 0; + } + catch + { + // We don't care what the exception is right now + volLabels = []; + return false; + } + } + #endregion } }