diff --git a/RombaSharp/Features/Build.cs b/RombaSharp/Features/Build.cs index d52426b3..b7888735 100644 --- a/RombaSharp/Features/Build.cs +++ b/RombaSharp/Features/Build.cs @@ -58,8 +58,8 @@ structure according to the original DAT master directory tree structure."; DatFile datFile = Parser.CreateAndParse(Path.Combine(_dats!, foundDats[key])); // Set the depot values - datFile.Header.InputDepot = new DepotInformation(true, 4); - datFile.Header.OutputDepot = new DepotInformation(true, 4); + datFile.Header.SetFieldValue(DatHeader.InputDepotKey, new DepotInformation(true, 4)); + datFile.Header.SetFieldValue(DatHeader.OutputDepotKey, new DepotInformation(true, 4)); // Create the new output directory if it doesn't exist string outputFolder = Path.Combine(outdat, Path.GetFileNameWithoutExtension(foundDats[key])); diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs index 56375711..c35aaef4 100644 --- a/SabreTools.DatFiles/DatFile.cs +++ b/SabreTools.DatFiles/DatFile.cs @@ -456,14 +456,14 @@ namespace SabreTools.DatFiles string post = CreatePrefixPostfix(item, false); // If we're in Depot mode, take care of that instead - if (Header.OutputDepot?.IsActive == true) + if (Header.GetFieldValue(DatHeader.OutputDepotKey)?.IsActive == true) { if (item is Disk disk) { // We can only write out if there's a SHA-1 if (!string.IsNullOrEmpty(disk.GetFieldValue(Models.Metadata.Disk.SHA1Key))) { - name = Utilities.GetDepotPath(disk.GetFieldValue(Models.Metadata.Disk.SHA1Key), Header.OutputDepot.Depth)?.Replace('\\', '/'); + name = Utilities.GetDepotPath(disk.GetFieldValue(Models.Metadata.Disk.SHA1Key), Header.GetFieldValue(DatHeader.OutputDepotKey)!.Depth)?.Replace('\\', '/'); item.SetName($"{pre}{name}{post}"); } } @@ -472,7 +472,7 @@ namespace SabreTools.DatFiles // We can only write out if there's a SHA-1 if (!string.IsNullOrEmpty(media.GetFieldValue(Models.Metadata.Media.SHA1Key))) { - name = Utilities.GetDepotPath(media.GetFieldValue(Models.Metadata.Media.SHA1Key), Header.OutputDepot.Depth)?.Replace('\\', '/'); + name = Utilities.GetDepotPath(media.GetFieldValue(Models.Metadata.Media.SHA1Key), Header.GetFieldValue(DatHeader.OutputDepotKey)!.Depth)?.Replace('\\', '/'); item.SetName($"{pre}{name}{post}"); } } @@ -481,7 +481,7 @@ namespace SabreTools.DatFiles // We can only write out if there's a SHA-1 if (!string.IsNullOrEmpty(rom.GetFieldValue(Models.Metadata.Rom.SHA1Key))) { - name = Utilities.GetDepotPath(rom.GetFieldValue(Models.Metadata.Rom.SHA1Key), Header.OutputDepot.Depth)?.Replace('\\', '/'); + name = Utilities.GetDepotPath(rom.GetFieldValue(Models.Metadata.Rom.SHA1Key), Header.GetFieldValue(DatHeader.OutputDepotKey)!.Depth)?.Replace('\\', '/'); item.SetName($"{pre}{name}{post}"); } } diff --git a/SabreTools.DatFiles/DatHeader.cs b/SabreTools.DatFiles/DatHeader.cs index 8e1d4ac9..f2c8b129 100644 --- a/SabreTools.DatFiles/DatHeader.cs +++ b/SabreTools.DatFiles/DatHeader.cs @@ -38,6 +38,16 @@ namespace SabreTools.DatFiles /// public const string GameNameKey = "GAMENAME"; + /// + /// Input depot information + /// + public const string InputDepotKey = "INPUTDEPOT"; + + /// + /// Output depot information + /// + public const string OutputDepotKey = "OUTPUTDEPOT"; + /// /// Text to append to all outputted lines /// @@ -92,22 +102,6 @@ namespace SabreTools.DatFiles } } - #region Depot Information - - /// - /// Input depot information - /// - [JsonIgnore, XmlIgnore] - public DepotInformation? InputDepot { get; set; } - - /// - /// Output depot information - /// - [JsonIgnore, XmlIgnore] - public DepotInformation? OutputDepot { get; set; } - - #endregion - /// /// Internal Header model /// @@ -163,11 +157,7 @@ namespace SabreTools.DatFiles /// public object Clone() { - var header = new DatHeader() - { - InputDepot = this.InputDepot?.Clone() as DepotInformation, - OutputDepot = this.OutputDepot?.Clone() as DepotInformation, - }; + var header = new DatHeader(); header.SetFieldValue(DatHeader.AddExtensionKey, GetFieldValue(DatHeader.AddExtensionKey)); header.SetFieldValue(Models.Metadata.Header.AuthorKey, GetFieldValue(Models.Metadata.Header.AuthorKey)); header.SetFieldValue(Models.Metadata.Header.BiosModeKey, GetFieldValue(Models.Metadata.Header.BiosModeKey)); @@ -190,6 +180,8 @@ namespace SabreTools.DatFiles header.SetFieldValue(Models.Metadata.Header.HomepageKey, GetFieldValue(Models.Metadata.Header.HomepageKey)); header.SetFieldValue(Models.Metadata.Header.IdKey, GetFieldValue(Models.Metadata.Header.IdKey)); header.SetFieldValue(Models.Metadata.Header.InfosKey, GetFieldValue(Models.Metadata.Header.InfosKey)); // TODO: Perform a deep clone + header.SetFieldValue(DatHeader.InputDepotKey, GetFieldValue(DatHeader.InputDepotKey)?.Clone() as DepotInformation); + header.SetFieldValue(DatHeader.OutputDepotKey, GetFieldValue(DatHeader.OutputDepotKey)?.Clone() as DepotInformation); header.SetFieldValue(Models.Metadata.Header.LockBiosModeKey, GetFieldValue(Models.Metadata.Header.LockBiosModeKey)); header.SetFieldValue(Models.Metadata.Header.LockRomModeKey, GetFieldValue(Models.Metadata.Header.LockRomModeKey)); header.SetFieldValue(Models.Metadata.Header.LockSampleModeKey, GetFieldValue(Models.Metadata.Header.LockSampleModeKey)); @@ -248,14 +240,12 @@ namespace SabreTools.DatFiles /// public DatHeader CloneFiltering() { - var header = new DatHeader() - { - InputDepot = this.InputDepot?.Clone() as DepotInformation, - OutputDepot = this.OutputDepot?.Clone() as DepotInformation, - }; + var header = new DatHeader(); header.SetFieldValue(DatHeader.AddExtensionKey, GetFieldValue(DatHeader.AddExtensionKey)); header.SetFieldValue(DatHeader.DatFormatKey, GetFieldValue(DatHeader.DatFormatKey)); header.SetFieldValue(DatHeader.GameNameKey, GetFieldValue(DatHeader.GameNameKey)); + header.SetFieldValue(DatHeader.InputDepotKey, GetFieldValue(DatHeader.InputDepotKey)?.Clone() as DepotInformation); + header.SetFieldValue(DatHeader.OutputDepotKey, GetFieldValue(DatHeader.OutputDepotKey)?.Clone() as DepotInformation); header.SetFieldValue(DatHeader.PostfixKey, GetFieldValue(DatHeader.PostfixKey)); header.SetFieldValue(DatHeader.PrefixKey, GetFieldValue(DatHeader.PrefixKey)); header.SetFieldValue(DatHeader.RemoveExtensionKey, GetFieldValue(DatHeader.RemoveExtensionKey)); @@ -341,8 +331,8 @@ namespace SabreTools.DatFiles if (!string.IsNullOrEmpty(datHeader.GetFieldValue(DatHeader.ReplaceExtensionKey))) SetFieldValue(DatHeader.ReplaceExtensionKey, datHeader.GetFieldValue(DatHeader.ReplaceExtensionKey)); - InputDepot = datHeader.InputDepot?.Clone() as DepotInformation; - OutputDepot = datHeader.OutputDepot?.Clone() as DepotInformation; + SetFieldValue(DatHeader.InputDepotKey, datHeader.GetFieldValue(DatHeader.InputDepotKey)?.Clone() as DepotInformation); + SetFieldValue(DatHeader.OutputDepotKey, datHeader.GetFieldValue(DatHeader.OutputDepotKey)?.Clone() as DepotInformation); SetFieldValue(DatHeader.GameNameKey, datHeader.GetFieldValue(DatHeader.GameNameKey)); SetFieldValue(DatHeader.QuotesKey, datHeader.GetFieldValue(DatHeader.QuotesKey)); SetFieldValue(DatHeader.RemoveExtensionKey, datHeader.GetFieldValue(DatHeader.RemoveExtensionKey)); diff --git a/SabreTools.DatFiles/Formats/Missfile.Writer.cs b/SabreTools.DatFiles/Formats/Missfile.Writer.cs index 76d230a9..3a5c6df9 100644 --- a/SabreTools.DatFiles/Formats/Missfile.Writer.cs +++ b/SabreTools.DatFiles/Formats/Missfile.Writer.cs @@ -92,7 +92,7 @@ namespace SabreTools.DatFiles.Formats ProcessItemName(datItem, false, forceRomName: false); // Romba mode automatically uses item name - if (Header.OutputDepot?.IsActive == true || Header.GetFieldValue(DatHeader.UseRomNameKey)) + if (Header.GetFieldValue(DatHeader.OutputDepotKey)?.IsActive == true || Header.GetFieldValue(DatHeader.UseRomNameKey)) sw.Write($"{datItem.GetName() ?? string.Empty}\n"); else if (!Header.GetFieldValue(DatHeader.UseRomNameKey) && datItem.GetFieldValue(DatItem.MachineKey)!.GetFieldValue(Models.Metadata.Machine.NameKey) != lastgame) sw.Write($"{datItem.GetFieldValue(DatItem.MachineKey)!.GetFieldValue(Models.Metadata.Machine.NameKey) ?? string.Empty}\n"); diff --git a/SabreTools.DatTools/DatFromDir.cs b/SabreTools.DatTools/DatFromDir.cs index 84655afb..ad438274 100644 --- a/SabreTools.DatTools/DatFromDir.cs +++ b/SabreTools.DatTools/DatFromDir.cs @@ -210,7 +210,7 @@ namespace SabreTools.DatTools private static bool CheckDepotFile(DatFile datFile, string item) { // If we're not in Depot mode, return false - if (datFile.Header.OutputDepot?.IsActive != true) + if (datFile.Header.GetFieldValue(DatHeader.OutputDepotKey)?.IsActive != true) return false; // Check the file as if it were in a depot @@ -321,7 +321,7 @@ namespace SabreTools.DatTools private static void ProcessDirectoryBlanks(DatFile datFile, string? basePath) { // If we're in depot mode, we don't process blanks - if (datFile.Header.OutputDepot?.IsActive == true) + if (datFile.Header.GetFieldValue(DatHeader.OutputDepotKey)?.IsActive == true) return; List empties = basePath.ListEmpty() ?? []; diff --git a/SabreTools.DatTools/Rebuilder.cs b/SabreTools.DatTools/Rebuilder.cs index d7d47e7d..885ecd0c 100644 --- a/SabreTools.DatTools/Rebuilder.cs +++ b/SabreTools.DatTools/Rebuilder.cs @@ -120,7 +120,7 @@ namespace SabreTools.DatTools logger.User($"Checking hash '{hash}'"); // Get the extension path for the hash - string? subpath = Utilities.GetDepotPath(hash, datFile.Header.InputDepot?.Depth ?? 0); + string? subpath = Utilities.GetDepotPath(hash, datFile.Header.GetFieldValue(DatHeader.InputDepotKey)?.Depth ?? 0); if (subpath == null) continue; @@ -590,7 +590,7 @@ namespace SabreTools.DatTools // Get the proper output path string sha1 = (datItem as Rom)!.GetFieldValue(Models.Metadata.Rom.SHA1Key) ?? string.Empty; if (outputFormat == OutputFormat.TorrentGzipRomba) - outDir = Path.Combine(outDir, Utilities.GetDepotPath(sha1, datFile.Header.OutputDepot?.Depth ?? 0) ?? string.Empty); + outDir = Path.Combine(outDir, Utilities.GetDepotPath(sha1, datFile.Header.GetFieldValue(DatHeader.OutputDepotKey)?.Depth ?? 0) ?? string.Empty); else outDir = Path.Combine(outDir, sha1 + ".gz"); @@ -636,7 +636,7 @@ namespace SabreTools.DatTools // Get the proper output path string sha1 = (datItem as Rom)!.GetFieldValue(Models.Metadata.Rom.SHA1Key) ?? string.Empty; if (outputFormat == OutputFormat.TorrentXZRomba) - outDir = Path.Combine(outDir, Utilities.GetDepotPath(sha1, datFile.Header.OutputDepot?.Depth ?? 0) ?? string.Empty).Replace(".gz", ".xz"); + outDir = Path.Combine(outDir, Utilities.GetDepotPath(sha1, datFile.Header.GetFieldValue(DatHeader.OutputDepotKey)?.Depth ?? 0) ?? string.Empty).Replace(".gz", ".xz"); else outDir = Path.Combine(outDir, sha1 + ".xz"); @@ -728,9 +728,9 @@ namespace SabreTools.DatTools // Set the depth fields where appropriate if (outputArchive is GZipArchive gzipArchive) - gzipArchive.Depth = datFile.Header.OutputDepot?.Depth ?? 0; + gzipArchive.Depth = datFile.Header.GetFieldValue(DatHeader.OutputDepotKey)?.Depth ?? 0; else if (outputArchive is XZArchive xzArchive) - xzArchive.Depth = datFile.Header.OutputDepot?.Depth ?? 0; + xzArchive.Depth = datFile.Header.GetFieldValue(DatHeader.OutputDepotKey)?.Depth ?? 0; return outputArchive; } diff --git a/SabreTools.DatTools/Verification.cs b/SabreTools.DatTools/Verification.cs index bad14cd9..cbc4d7a1 100644 --- a/SabreTools.DatTools/Verification.cs +++ b/SabreTools.DatTools/Verification.cs @@ -69,7 +69,7 @@ namespace SabreTools.DatTools logger.User($"Checking hash '{hash}'"); // Get the extension path for the hash - string? subpath = Utilities.GetDepotPath(hash, datFile.Header.InputDepot?.Depth ?? 0); + string? subpath = Utilities.GetDepotPath(hash, datFile.Header.GetFieldValue(DatHeader.InputDepotKey)?.Depth ?? 0); if (subpath == null) continue; diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index d7f3bf9d..ea558efa 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -2149,17 +2149,16 @@ Some special strings that can be used: /// private DatHeader? GetDatHeader(Dictionary features) { - // TODO: Sort this by region, like the actual header - var datHeader = new DatHeader() - { - // Get the depot information - InputDepot = new DepotInformation( + // Get the depot information + var inputDepot = new DepotInformation( GetBoolean(features, DepotValue), - GetInt32(features, DepotDepthInt32Value)), - OutputDepot = new DepotInformation( + GetInt32(features, DepotDepthInt32Value)); + var outputDepot = new DepotInformation( GetBoolean(features, RombaValue), - GetInt32(features, RombaDepthInt32Value)) - }; + GetInt32(features, RombaDepthInt32Value)); + + var datHeader = new DatHeader(); + datHeader.SetFieldValue(DatHeader.AddExtensionKey, GetString(features, AddExtensionStringValue)); datHeader.SetFieldValue(Models.Metadata.Header.AuthorKey, GetString(features, AuthorStringValue)); datHeader.SetFieldValue(Models.Metadata.Header.CategoryKey, GetString(features, CategoryStringValue)); datHeader.SetFieldValue(Models.Metadata.Header.CommentKey, GetString(features, CommentStringValue)); @@ -2170,22 +2169,22 @@ Some special strings that can be used: datHeader.SetFieldValue(Models.Metadata.Header.ForceMergingKey, GetString(features, ForceMergingStringValue).AsEnumValue()); datHeader.SetFieldValue(Models.Metadata.Header.ForceNodumpKey, GetString(features, ForceNodumpStringValue).AsEnumValue()); datHeader.SetFieldValue(Models.Metadata.Header.ForceNodumpKey, GetString(features, ForcePackingStringValue).AsEnumValue()); + datHeader.SetFieldValue(DatHeader.GameNameKey, GetBoolean(features, GamePrefixValue)); datHeader.SetFieldValue(Models.Metadata.Header.HeaderKey, GetString(features, HeaderStringValue)); datHeader.SetFieldValue(Models.Metadata.Header.HomepageKey, GetString(features, HomepageStringValue)); + datHeader.SetFieldValue(DatHeader.InputDepotKey, inputDepot); datHeader.SetFieldValue(Models.Metadata.Header.NameKey, GetString(features, NameStringValue)); - datHeader.SetFieldValue(Models.Metadata.Header.RootDirKey, GetString(features, RootStringValue)); - datHeader.SetFieldValue(Models.Metadata.Header.TypeKey, GetBoolean(features, SuperdatValue) ? "SuperDAT" : null); - datHeader.SetFieldValue(Models.Metadata.Header.UrlKey, GetString(features, UrlStringValue)); - datHeader.SetFieldValue(Models.Metadata.Header.VersionKey, GetString(features, VersionStringValue)); - - datHeader.SetFieldValue(DatHeader.AddExtensionKey, GetString(features, AddExtensionStringValue)); - datHeader.SetFieldValue(DatHeader.GameNameKey, GetBoolean(features, GamePrefixValue)); + datHeader.SetFieldValue(DatHeader.OutputDepotKey, outputDepot); datHeader.SetFieldValue(DatHeader.PostfixKey, GetString(features, PostfixStringValue)); datHeader.SetFieldValue(DatHeader.PrefixKey, GetString(features, PrefixStringValue)); datHeader.SetFieldValue(DatHeader.QuotesKey, GetBoolean(features, QuotesValue)); datHeader.SetFieldValue(DatHeader.RemoveExtensionKey, GetBoolean(features, RemoveExtensionsValue)); datHeader.SetFieldValue(DatHeader.ReplaceExtensionKey, GetString(features, ReplaceExtensionStringValue)); datHeader.SetFieldValue(DatHeader.UseRomNameKey, GetBoolean(features, RomsValue)); + datHeader.SetFieldValue(Models.Metadata.Header.RootDirKey, GetString(features, RootStringValue)); + datHeader.SetFieldValue(Models.Metadata.Header.TypeKey, GetBoolean(features, SuperdatValue) ? "SuperDAT" : null); + datHeader.SetFieldValue(Models.Metadata.Header.UrlKey, GetString(features, UrlStringValue)); + datHeader.SetFieldValue(Models.Metadata.Header.VersionKey, GetString(features, VersionStringValue)); bool deprecated = GetBoolean(features, DeprecatedValue); foreach (string ot in GetList(features, OutputTypeListValue)) diff --git a/SabreTools/Features/Sort.cs b/SabreTools/Features/Sort.cs index e8b99c37..2617b1b9 100644 --- a/SabreTools/Features/Sort.cs +++ b/SabreTools/Features/Sort.cs @@ -74,7 +74,7 @@ namespace SabreTools.Features var outputFormat = GetOutputFormat(features); // If we have the romba flag - if (Header!.OutputDepot?.IsActive == true) + if (Header!.GetFieldValue(DatHeader.OutputDepotKey)?.IsActive == true) { // Update TorrentGzip output if (outputFormat == OutputFormat.TorrentGzip) @@ -98,8 +98,8 @@ namespace SabreTools.Features Parser.ParseInto(datdata, datfile, int.MaxValue, keep: true); // Set depot information - datdata.Header.InputDepot = Header.InputDepot?.Clone() as DepotInformation; - datdata.Header.OutputDepot = Header.OutputDepot?.Clone() as DepotInformation; + datdata.Header.SetFieldValue(DatHeader.InputDepotKey, Header.GetFieldValue(DatHeader.InputDepotKey)?.Clone() as DepotInformation); + datdata.Header.SetFieldValue(DatHeader.OutputDepotKey, Header.GetFieldValue(DatHeader.OutputDepotKey)?.Clone() as DepotInformation); // If we have overridden the header skipper, set it now if (!string.IsNullOrEmpty(Header.GetFieldValue(Models.Metadata.Header.HeaderKey))) @@ -107,7 +107,7 @@ namespace SabreTools.Features // If we have the depot flag, respect it bool success; - if (Header.InputDepot?.IsActive ?? false) + if (Header.GetFieldValue(DatHeader.InputDepotKey)?.IsActive ?? false) success = Rebuilder.RebuildDepot(datdata, Inputs, Path.Combine(OutputDir!, datdata.Header.GetFieldValue(DatHeader.FileNameKey)!), date, delete, inverse, outputFormat); else success = Rebuilder.RebuildGeneric(datdata, Inputs, Path.Combine(OutputDir!, datdata.Header.GetFieldValue(DatHeader.FileNameKey)!), quickScan, date, delete, inverse, outputFormat, asFiles); @@ -137,8 +137,8 @@ namespace SabreTools.Features } // Set depot information - datdata.Header.InputDepot = Header.InputDepot?.Clone() as DepotInformation; - datdata.Header.OutputDepot = Header.OutputDepot?.Clone() as DepotInformation; + datdata.Header.SetFieldValue(DatHeader.InputDepotKey, Header.GetFieldValue(DatHeader.InputDepotKey)?.Clone() as DepotInformation); + datdata.Header.SetFieldValue(DatHeader.OutputDepotKey, Header.GetFieldValue(DatHeader.OutputDepotKey)?.Clone() as DepotInformation); // If we have overridden the header skipper, set it now if (!string.IsNullOrEmpty(Header.GetFieldValue(Models.Metadata.Header.HeaderKey))) @@ -148,7 +148,7 @@ namespace SabreTools.Features // If we have the depot flag, respect it bool success; - if (Header.InputDepot?.IsActive ?? false) + if (Header.GetFieldValue(DatHeader.InputDepotKey)?.IsActive ?? false) success = Rebuilder.RebuildDepot(datdata, Inputs, OutputDir!, date, delete, inverse, outputFormat); else success = Rebuilder.RebuildGeneric(datdata, Inputs, OutputDir!, quickScan, date, delete, inverse, outputFormat, asFiles); diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index 78f6bf6b..65f5e4ba 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -72,14 +72,14 @@ namespace SabreTools.Features Remover!.ApplyRemovals(datdata); // Set depot information - datdata.Header.InputDepot = Header!.InputDepot?.Clone() as DepotInformation; + datdata.Header.SetFieldValue(DatHeader.InputDepotKey, Header!.GetFieldValue(DatHeader.InputDepotKey)?.Clone() as DepotInformation); // If we have overridden the header skipper, set it now if (!string.IsNullOrEmpty(Header.GetFieldValue(Models.Metadata.Header.HeaderKey))) datdata.Header.SetFieldValue(Models.Metadata.Header.HeaderKey, Header.GetFieldValue(Models.Metadata.Header.HeaderKey)); // If we have the depot flag, respect it - if (Header.InputDepot?.IsActive ?? false) + if (Header.GetFieldValue(DatHeader.InputDepotKey)?.IsActive ?? false) { Verification.VerifyDepot(datdata, Inputs); } @@ -120,7 +120,7 @@ namespace SabreTools.Features Remover!.ApplyRemovals(datdata); // Set depot information - datdata.Header.InputDepot = Header!.InputDepot?.Clone() as DepotInformation; + datdata.Header.SetFieldValue(DatHeader.InputDepotKey, Header!.GetFieldValue(DatHeader.InputDepotKey)?.Clone() as DepotInformation); // If we have overridden the header skipper, set it now if (!string.IsNullOrEmpty(Header.GetFieldValue(Models.Metadata.Header.HeaderKey))) @@ -129,7 +129,7 @@ namespace SabreTools.Features watch.Stop(); // If we have the depot flag, respect it - if (Header.InputDepot?.IsActive ?? false) + if (Header.GetFieldValue(DatHeader.InputDepotKey)?.IsActive ?? false) { Verification.VerifyDepot(datdata, Inputs); }