From 0d9259ddc18a537364238fb45655c1110c594ec0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 3 Feb 2017 16:59:31 -0800 Subject: [PATCH] [SabreTools, DatFile] Get flag usage and override working for sort/sort-depot/verify/verify-depot --- SabreTools.Helper/Data/Enums.cs | 2 + .../Dats/Partials/DatFile.Parsers.cs | 60 ++++++++++++++++--- .../Dats/Partials/DatFile.Writers.cs | 10 +++- SabreTools.Helper/README.1ST | 34 +++++++++++ SabreTools/Partials/SabreTools.Help.cs | 40 +++++++++++++ SabreTools/Partials/SabreTools.Inits.cs | 20 +++++-- 6 files changed, 152 insertions(+), 14 deletions(-) diff --git a/SabreTools.Helper/Data/Enums.cs b/SabreTools.Helper/Data/Enums.cs index 411faf7b..9e203426 100644 --- a/SabreTools.Helper/Data/Enums.cs +++ b/SabreTools.Helper/Data/Enums.cs @@ -217,6 +217,8 @@ { None = 0, Split, + Merged, + NonMerged, Full, } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs index 001beae1..1ad45e13 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs @@ -34,9 +34,12 @@ namespace SabreTools.Helper.Dats /// True if game names are sanitized, false otherwise (default) /// True if SL XML names should be kept, false otherwise (default) /// True if original extension should be kept, false otherwise (default) - public void Parse(string filename, int sysid, int srcid, Logger logger, bool keep = false, bool clean = false, bool softlist = false, bool keepext = false) + /// True if tags from the DAT should be used to merge the output, false otherwise (default) + public void Parse(string filename, int sysid, int srcid, Logger logger, + bool keep = false, bool clean = false, bool softlist = false, bool keepext = false, bool useTags = false) { - Parse(filename, sysid, srcid, new Filter(), SplitType.None, false, false, "", logger, keep, clean, softlist, keepext); + Parse(filename, sysid, srcid, new Filter(), SplitType.None, false, false, "", logger, + keep: keep, clean: clean, softlist: softlist, keepext: keepext, useTags: useTags); } /// @@ -55,6 +58,7 @@ namespace SabreTools.Helper.Dats /// True if game names are sanitized, false otherwise (default) /// True if SL XML names should be kept, false otherwise (default) /// True if original extension should be kept, false otherwise (default) + /// True if tags from the DAT should be used to merge the output, false otherwise (default) public void Parse( // Standard Dat parsing string filename, @@ -75,7 +79,8 @@ namespace SabreTools.Helper.Dats bool keep = false, bool clean = false, bool softlist = false, - bool keepext = false) + bool keepext = false, + bool useTags = false) { // Check the file extension first as a safeguard string ext = Path.GetExtension(filename).ToLowerInvariant(); @@ -126,6 +131,29 @@ namespace SabreTools.Helper.Dats return; } + // If we are using tags from the DAT, set the proper input for split type unless overridden + if (useTags && splitType == SplitType.None) + { + switch (_forceMerging) + { + case ForceMerging.None: + // No-op + break; + case ForceMerging.Split: + splitType = SplitType.Split; + break; + case ForceMerging.Merged: + splitType = SplitType.Merged; + break; + case ForceMerging.NonMerged: + splitType = SplitType.NonMerged; + break; + case ForceMerging.Full: + splitType = SplitType.FullNonMerged; + break; + } + } + // Now we pre-process the DAT with the splitting/merging mode switch (splitType) { @@ -726,6 +754,12 @@ namespace SabreTools.Helper.Dats case "split": ForceMerging = ForceMerging.Split; break; + case "merged": + ForceMerging = ForceMerging.Merged; + break; + case "nonmerged": + ForceMerging = ForceMerging.NonMerged; + break; case "full": ForceMerging = ForceMerging.Full; break; @@ -898,11 +932,17 @@ namespace SabreTools.Helper.Dats { switch (xtr.GetAttribute("forcemerging")) { + case "none": + ForceMerging = ForceMerging.None; + break; case "split": ForceMerging = ForceMerging.Split; break; - case "none": - ForceMerging = ForceMerging.None; + case "merged": + ForceMerging = ForceMerging.Merged; + break; + case "nonmerged": + ForceMerging = ForceMerging.NonMerged; break; case "full": ForceMerging = ForceMerging.Full; @@ -1094,11 +1134,17 @@ namespace SabreTools.Helper.Dats { switch (headreader.GetAttribute("forcemerging")) { + case "none": + ForceMerging = ForceMerging.None; + break; case "split": ForceMerging = ForceMerging.Split; break; - case "none": - ForceMerging = ForceMerging.None; + case "merged": + ForceMerging = ForceMerging.Merged; + break; + case "nonmerged": + ForceMerging = ForceMerging.NonMerged; break; case "full": ForceMerging = ForceMerging.Full; diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs b/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs index ba531607..04ed9d25 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs @@ -258,6 +258,8 @@ namespace SabreTools.Helper.Dats (ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") + (ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") + (ForceMerging == ForceMerging.Split ? "\tforcemerging split\n" : "") + + (ForceMerging == ForceMerging.Merged ? "\tforcemerging merged\n" : "") + + (ForceMerging == ForceMerging.NonMerged ? "\tforcemerging nonmerged\n" : "") + ")\n"; break; case DatFormat.CSV: @@ -298,6 +300,8 @@ namespace SabreTools.Helper.Dats (ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") + (ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") + (ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") + + (ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") + + (ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") + (ForceNodump == ForceNodump.Ignore ? " forceitemStatus=\"ignore\"" : "") + (ForceNodump == ForceNodump.Obsolete ? " forceitemStatus=\"obsolete\"" : "") + (ForceNodump == ForceNodump.Required ? " forceitemStatus=\"required\"" : "") + @@ -361,7 +365,7 @@ namespace SabreTools.Helper.Dats "[DAT]\n" + "version=2.50\n" + "split=" + (ForceMerging == ForceMerging.Split ? "1" : "0") + "\n" + - "merge=" + (ForceMerging == ForceMerging.Full ? "1" : "0") + "\n" + + "merge=" + (ForceMerging == ForceMerging.Full || ForceMerging == ForceMerging.Merged ? "1" : "0") + "\n" + "[EMULATOR]\n" + "refname=" + Name + "\n" + "version=" + Description + "\n" + @@ -387,6 +391,8 @@ namespace SabreTools.Helper.Dats (ForcePacking == ForcePacking.Zip ? "\t\t\t\n" : "") + (ForceMerging == ForceMerging.Full ? "\t\t\t\n" : "") + (ForceMerging == ForceMerging.Split ? "\t\t\t\n" : "") + + (ForceMerging == ForceMerging.Merged ? "\t\t\t\n" : "") + + (ForceMerging == ForceMerging.NonMerged ? "\t\t\t\n" : "") + (ForceNodump == ForceNodump.Ignore ? "\t\t\t\n" : "") + (ForceNodump == ForceNodump.Obsolete ? "\t\t\t\n" : "") + (ForceNodump == ForceNodump.Required ? "\t\t\t\n" : "") + @@ -404,6 +410,8 @@ namespace SabreTools.Helper.Dats (ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") + (ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") + (ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") + + (ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") + + (ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") + (ForceNodump == ForceNodump.Ignore ? " forceitemStatus=\"ignore\"" : "") + (ForceNodump == ForceNodump.Obsolete ? " forceitemStatus=\"obsolete\"" : "") + (ForceNodump == ForceNodump.Required ? " forceitemStatus=\"required\"" : "") + diff --git a/SabreTools.Helper/README.1ST b/SabreTools.Helper/README.1ST index c65d82a5..229a8fda 100644 --- a/SabreTools.Helper/README.1ST +++ b/SabreTools.Helper/README.1ST @@ -1047,6 +1047,23 @@ Options: defined, and that skipper exists, then it will be used instead of trying to find one that matches. + -dm, --dat-merged Force checking merged sets in the output + Preprocess the DAT to have parent sets contain all items from the children based + on the cloneof tag. This is incompatible with the other --dat-X flags. + + -ds, --dat-split Force checking split sets in the output + Preprocess the DAT to remove redundant files between parents and children based + on the romof and cloneof tags. This is incompatible with the other --dat-X flags. + + -dnm, --dat-nonmerged Force checking non-merged sets in the output + Preprocess the DAT to have child sets contain all items from the parent set based + on the cloneof tag. This is incompatible with the other --dat-X flags. + + -df, --dat-fullnonmerged Force checking fully non-merged sets in the output + Preprocess the DAT to have child sets contain all items from the parent sets based + on the cloneof and romof tags as well as device references. This is incompatible with + the other --dat-X flags. + -ved, --verify-depot Verify a depot against an input DAT When used, this will use an input DAT or set of DATs to blindly check against an input depot. This is based on the sort-depot code in which the base directories are assumed @@ -1067,6 +1084,23 @@ Options: to be hashed without possibly variant information. If a particular header skipper is defined, and that skipper exists, then it will be used instead of trying to find one that matches. + + -dm, --dat-merged Force checking merged sets in the output + Preprocess the DAT to have parent sets contain all items from the children based + on the cloneof tag. This is incompatible with the other --dat-X flags. + + -ds, --dat-split Force checking split sets in the output + Preprocess the DAT to remove redundant files between parents and children based + on the romof and cloneof tags. This is incompatible with the other --dat-X flags. + + -dnm, --dat-nonmerged Force checking non-merged sets in the output + Preprocess the DAT to have child sets contain all items from the parent set based + on the cloneof tag. This is incompatible with the other --dat-X flags. + + -df, --dat-fullnonmerged Force checking fully non-merged sets in the output + Preprocess the DAT to have child sets contain all items from the parent sets based + on the cloneof and romof tags as well as device references. This is incompatible with + the other --dat-X flags. ** Section 3.0 - Examples diff --git a/SabreTools/Partials/SabreTools.Help.cs b/SabreTools/Partials/SabreTools.Help.cs index 71f2f171..dc96d6bb 100644 --- a/SabreTools/Partials/SabreTools.Help.cs +++ b/SabreTools/Partials/SabreTools.Help.cs @@ -1231,6 +1231,26 @@ namespace SabreTools "Set a header skipper to use, blank means all", FeatureType.String, null)); + verify.AddFeature("dat-merged", new Feature( + new List() { "-dm", "--dat-merged" }, + "Force checking merged sets", + FeatureType.Flag, + null)); + verify.AddFeature("dat-split", new Feature( + new List() { "-ds", "--dat-split" }, + "Force checking split sets", + FeatureType.Flag, + null)); + verify.AddFeature("dat-nonmerged", new Feature( + new List() { "-dnm", "--dat-nonmerged" }, + "Force checking non-merged sets", + FeatureType.Flag, + null)); + verify.AddFeature("dat-fullnonmerged", new Feature( + new List() { "-df", "--dat-fullnonmerged" }, + "Force checking fully non-merged sets", + FeatureType.Flag, + null)); // Create the Verify Depot feature Feature verifyDepot = new Feature( @@ -1253,6 +1273,26 @@ namespace SabreTools "Set a header skipper to use, blank means all", FeatureType.String, null)); + verifyDepot.AddFeature("dat-merged", new Feature( + new List() { "-dm", "--dat-merged" }, + "Force checking merged sets", + FeatureType.Flag, + null)); + verifyDepot.AddFeature("dat-split", new Feature( + new List() { "-ds", "--dat-split" }, + "Force checking split sets", + FeatureType.Flag, + null)); + verifyDepot.AddFeature("dat-nonmerged", new Feature( + new List() { "-dnm", "--dat-nonmerged" }, + "Force checking non-merged sets", + FeatureType.Flag, + null)); + verifyDepot.AddFeature("dat-fullnonmerged", new Feature( + new List() { "-df", "--dat-fullnonmerged" }, + "Force checking fully non-merged sets", + FeatureType.Flag, + null)); // Now, add all of the main features to the Help object help.Add("Help", helpFeature); diff --git a/SabreTools/Partials/SabreTools.Inits.cs b/SabreTools/Partials/SabreTools.Inits.cs index 7e41fc5e..2e980d39 100644 --- a/SabreTools/Partials/SabreTools.Inits.cs +++ b/SabreTools/Partials/SabreTools.Inits.cs @@ -325,7 +325,8 @@ namespace SabreTools DatFile datdata = new DatFile(); foreach (string datfile in datfiles) { - datdata.Parse(datfile, 99, 99, new Filter(), splitType, false /* trim */, false /* single */, null /* root */, _logger, keep: true, softlist: true); + datdata.Parse(datfile, 99, 99, new Filter(), splitType, false /* trim */, false /* single */, null /* root */, _logger, + keep: true, softlist: true, useTags: true); } _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); @@ -359,7 +360,8 @@ namespace SabreTools DatFile datdata = new DatFile(); foreach (string datfile in datfiles) { - datdata.Parse(datfile, 99, 99, new Filter(), splitType, false /* trim */, false /* single */, null /* root */, _logger, keep: true, softlist: true); + datdata.Parse(datfile, 99, 99, new Filter(), splitType, false /* trim */, false /* single */, null /* root */, _logger, + keep: true, softlist: true, useTags: true); } _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); @@ -823,7 +825,9 @@ namespace SabreTools /// True if only hashes should be checked, false for full file information /// True to enable external scanning of archives, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise - private static void InitVerify(List datfiles, List inputs, string tempDir, bool hashOnly, bool quickScan, string headerToCheckAgainst) + /// Type of the split that should be performed (split, merged, fully merged) + private static void InitVerify(List datfiles, List inputs, string tempDir, + bool hashOnly, bool quickScan, string headerToCheckAgainst, SplitType splitType) { // Get the archive scanning level ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1); @@ -835,7 +839,8 @@ namespace SabreTools DatFile datdata = new DatFile(); foreach (string datfile in datfiles) { - datdata.Parse(datfile, 99, 99, _logger, keep: true, softlist: true); + datdata.Parse(datfile, 99, 99, new Filter(), splitType, false /* trim */, false /* single */, null /* root */, _logger, + keep: true, softlist: true, useTags: true); } _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); @@ -849,7 +854,9 @@ namespace SabreTools /// Input directories to compare against /// Temporary directory for archive extraction /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise - private static void InitVerifyDepot(List datfiles, List inputs, string tempDir, string headerToCheckAgainst) + /// Type of the split that should be performed (split, merged, fully merged) + private static void InitVerifyDepot(List datfiles, List inputs, string tempDir, + string headerToCheckAgainst, SplitType splitType) { DateTime start = DateTime.Now; _logger.User("Populating internal DAT..."); @@ -858,7 +865,8 @@ namespace SabreTools DatFile datdata = new DatFile(); foreach (string datfile in datfiles) { - datdata.Parse(datfile, 99, 99, _logger, keep: true, softlist: true); + datdata.Parse(datfile, 99, 99, new Filter(), splitType, false /* trim */, false /* single */, null /* root */, _logger, + keep: true, softlist: true, useTags: true); } _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));