[SabreTools, DatFile] Get flag usage and override working for sort/sort-depot/verify/verify-depot

This commit is contained in:
Matt Nadareski
2017-02-03 16:59:31 -08:00
parent f75920e879
commit 0d9259ddc1
6 changed files with 152 additions and 14 deletions

View File

@@ -217,6 +217,8 @@
{ {
None = 0, None = 0,
Split, Split,
Merged,
NonMerged,
Full, Full,
} }

View File

@@ -34,9 +34,12 @@ namespace SabreTools.Helper.Dats
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param> /// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="softlist">True if SL XML names should be kept, false otherwise (default)</param> /// <param name="softlist">True if SL XML names should be kept, false otherwise (default)</param>
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param> /// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
public void Parse(string filename, int sysid, int srcid, Logger logger, bool keep = false, bool clean = false, bool softlist = false, bool keepext = false) /// <param name="useTags">True if tags from the DAT should be used to merge the output, false otherwise (default)</param>
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);
} }
/// <summary> /// <summary>
@@ -55,6 +58,7 @@ namespace SabreTools.Helper.Dats
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param> /// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="softlist">True if SL XML names should be kept, false otherwise (default)</param> /// <param name="softlist">True if SL XML names should be kept, false otherwise (default)</param>
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param> /// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
/// <param name="useTags">True if tags from the DAT should be used to merge the output, false otherwise (default)</param>
public void Parse( public void Parse(
// Standard Dat parsing // Standard Dat parsing
string filename, string filename,
@@ -75,7 +79,8 @@ namespace SabreTools.Helper.Dats
bool keep = false, bool keep = false,
bool clean = false, bool clean = false,
bool softlist = false, bool softlist = false,
bool keepext = false) bool keepext = false,
bool useTags = false)
{ {
// Check the file extension first as a safeguard // Check the file extension first as a safeguard
string ext = Path.GetExtension(filename).ToLowerInvariant(); string ext = Path.GetExtension(filename).ToLowerInvariant();
@@ -126,6 +131,29 @@ namespace SabreTools.Helper.Dats
return; 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 // Now we pre-process the DAT with the splitting/merging mode
switch (splitType) switch (splitType)
{ {
@@ -726,6 +754,12 @@ namespace SabreTools.Helper.Dats
case "split": case "split":
ForceMerging = ForceMerging.Split; ForceMerging = ForceMerging.Split;
break; break;
case "merged":
ForceMerging = ForceMerging.Merged;
break;
case "nonmerged":
ForceMerging = ForceMerging.NonMerged;
break;
case "full": case "full":
ForceMerging = ForceMerging.Full; ForceMerging = ForceMerging.Full;
break; break;
@@ -898,11 +932,17 @@ namespace SabreTools.Helper.Dats
{ {
switch (xtr.GetAttribute("forcemerging")) switch (xtr.GetAttribute("forcemerging"))
{ {
case "none":
ForceMerging = ForceMerging.None;
break;
case "split": case "split":
ForceMerging = ForceMerging.Split; ForceMerging = ForceMerging.Split;
break; break;
case "none": case "merged":
ForceMerging = ForceMerging.None; ForceMerging = ForceMerging.Merged;
break;
case "nonmerged":
ForceMerging = ForceMerging.NonMerged;
break; break;
case "full": case "full":
ForceMerging = ForceMerging.Full; ForceMerging = ForceMerging.Full;
@@ -1094,11 +1134,17 @@ namespace SabreTools.Helper.Dats
{ {
switch (headreader.GetAttribute("forcemerging")) switch (headreader.GetAttribute("forcemerging"))
{ {
case "none":
ForceMerging = ForceMerging.None;
break;
case "split": case "split":
ForceMerging = ForceMerging.Split; ForceMerging = ForceMerging.Split;
break; break;
case "none": case "merged":
ForceMerging = ForceMerging.None; ForceMerging = ForceMerging.Merged;
break;
case "nonmerged":
ForceMerging = ForceMerging.NonMerged;
break; break;
case "full": case "full":
ForceMerging = ForceMerging.Full; ForceMerging = ForceMerging.Full;

View File

@@ -258,6 +258,8 @@ namespace SabreTools.Helper.Dats
(ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") + (ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") +
(ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") + (ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") +
(ForceMerging == ForceMerging.Split ? "\tforcemerging split\n" : "") + (ForceMerging == ForceMerging.Split ? "\tforcemerging split\n" : "") +
(ForceMerging == ForceMerging.Merged ? "\tforcemerging merged\n" : "") +
(ForceMerging == ForceMerging.NonMerged ? "\tforcemerging nonmerged\n" : "") +
")\n"; ")\n";
break; break;
case DatFormat.CSV: case DatFormat.CSV:
@@ -298,6 +300,8 @@ namespace SabreTools.Helper.Dats
(ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") + (ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
(ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") + (ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
(ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") + (ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
(ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
(ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
(ForceNodump == ForceNodump.Ignore ? " forceitemStatus=\"ignore\"" : "") + (ForceNodump == ForceNodump.Ignore ? " forceitemStatus=\"ignore\"" : "") +
(ForceNodump == ForceNodump.Obsolete ? " forceitemStatus=\"obsolete\"" : "") + (ForceNodump == ForceNodump.Obsolete ? " forceitemStatus=\"obsolete\"" : "") +
(ForceNodump == ForceNodump.Required ? " forceitemStatus=\"required\"" : "") + (ForceNodump == ForceNodump.Required ? " forceitemStatus=\"required\"" : "") +
@@ -361,7 +365,7 @@ namespace SabreTools.Helper.Dats
"[DAT]\n" + "[DAT]\n" +
"version=2.50\n" + "version=2.50\n" +
"split=" + (ForceMerging == ForceMerging.Split ? "1" : "0") + "\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" + "[EMULATOR]\n" +
"refname=" + Name + "\n" + "refname=" + Name + "\n" +
"version=" + Description + "\n" + "version=" + Description + "\n" +
@@ -387,6 +391,8 @@ namespace SabreTools.Helper.Dats
(ForcePacking == ForcePacking.Zip ? "\t\t\t<flag name=\"forcepacking\" value=\"zip\"/>\n" : "") + (ForcePacking == ForcePacking.Zip ? "\t\t\t<flag name=\"forcepacking\" value=\"zip\"/>\n" : "") +
(ForceMerging == ForceMerging.Full ? "\t\t\t<flag name=\"forcemerging\" value=\"full\"/>\n" : "") + (ForceMerging == ForceMerging.Full ? "\t\t\t<flag name=\"forcemerging\" value=\"full\"/>\n" : "") +
(ForceMerging == ForceMerging.Split ? "\t\t\t<flag name=\"forcemerging\" value=\"split\"/>\n" : "") + (ForceMerging == ForceMerging.Split ? "\t\t\t<flag name=\"forcemerging\" value=\"split\"/>\n" : "") +
(ForceMerging == ForceMerging.Merged ? "\t\t\t<flag name=\"forcemerging\" value=\"merged\"/>\n" : "") +
(ForceMerging == ForceMerging.NonMerged ? "\t\t\t<flag name=\"forcemerging\" value=\"nonmerged\"/>\n" : "") +
(ForceNodump == ForceNodump.Ignore ? "\t\t\t<flag name=\"forceitemStatus\" value=\"ignore\"/>\n" : "") + (ForceNodump == ForceNodump.Ignore ? "\t\t\t<flag name=\"forceitemStatus\" value=\"ignore\"/>\n" : "") +
(ForceNodump == ForceNodump.Obsolete ? "\t\t\t<flag name=\"forceitemStatus\" value=\"obsolete\"/>\n" : "") + (ForceNodump == ForceNodump.Obsolete ? "\t\t\t<flag name=\"forceitemStatus\" value=\"obsolete\"/>\n" : "") +
(ForceNodump == ForceNodump.Required ? "\t\t\t<flag name=\"forceitemStatus\" value=\"required\"/>\n" : "") + (ForceNodump == ForceNodump.Required ? "\t\t\t<flag name=\"forceitemStatus\" value=\"required\"/>\n" : "") +
@@ -404,6 +410,8 @@ namespace SabreTools.Helper.Dats
(ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") + (ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
(ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") + (ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
(ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") + (ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
(ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
(ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
(ForceNodump == ForceNodump.Ignore ? " forceitemStatus=\"ignore\"" : "") + (ForceNodump == ForceNodump.Ignore ? " forceitemStatus=\"ignore\"" : "") +
(ForceNodump == ForceNodump.Obsolete ? " forceitemStatus=\"obsolete\"" : "") + (ForceNodump == ForceNodump.Obsolete ? " forceitemStatus=\"obsolete\"" : "") +
(ForceNodump == ForceNodump.Required ? " forceitemStatus=\"required\"" : "") + (ForceNodump == ForceNodump.Required ? " forceitemStatus=\"required\"" : "") +

View File

@@ -1047,6 +1047,23 @@ Options:
defined, and that skipper exists, then it will be used instead of trying to find one defined, and that skipper exists, then it will be used instead of trying to find one
that matches. 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 -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 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 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 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 defined, and that skipper exists, then it will be used instead of trying to find one
that matches. 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 ** Section 3.0 - Examples

View File

@@ -1231,6 +1231,26 @@ namespace SabreTools
"Set a header skipper to use, blank means all", "Set a header skipper to use, blank means all",
FeatureType.String, FeatureType.String,
null)); null));
verify.AddFeature("dat-merged", new Feature(
new List<string>() { "-dm", "--dat-merged" },
"Force checking merged sets",
FeatureType.Flag,
null));
verify.AddFeature("dat-split", new Feature(
new List<string>() { "-ds", "--dat-split" },
"Force checking split sets",
FeatureType.Flag,
null));
verify.AddFeature("dat-nonmerged", new Feature(
new List<string>() { "-dnm", "--dat-nonmerged" },
"Force checking non-merged sets",
FeatureType.Flag,
null));
verify.AddFeature("dat-fullnonmerged", new Feature(
new List<string>() { "-df", "--dat-fullnonmerged" },
"Force checking fully non-merged sets",
FeatureType.Flag,
null));
// Create the Verify Depot feature // Create the Verify Depot feature
Feature verifyDepot = new Feature( Feature verifyDepot = new Feature(
@@ -1253,6 +1273,26 @@ namespace SabreTools
"Set a header skipper to use, blank means all", "Set a header skipper to use, blank means all",
FeatureType.String, FeatureType.String,
null)); null));
verifyDepot.AddFeature("dat-merged", new Feature(
new List<string>() { "-dm", "--dat-merged" },
"Force checking merged sets",
FeatureType.Flag,
null));
verifyDepot.AddFeature("dat-split", new Feature(
new List<string>() { "-ds", "--dat-split" },
"Force checking split sets",
FeatureType.Flag,
null));
verifyDepot.AddFeature("dat-nonmerged", new Feature(
new List<string>() { "-dnm", "--dat-nonmerged" },
"Force checking non-merged sets",
FeatureType.Flag,
null));
verifyDepot.AddFeature("dat-fullnonmerged", new Feature(
new List<string>() { "-df", "--dat-fullnonmerged" },
"Force checking fully non-merged sets",
FeatureType.Flag,
null));
// Now, add all of the main features to the Help object // Now, add all of the main features to the Help object
help.Add("Help", helpFeature); help.Add("Help", helpFeature);

View File

@@ -325,7 +325,8 @@ namespace SabreTools
DatFile datdata = new DatFile(); DatFile datdata = new DatFile();
foreach (string datfile in datfiles) 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")); _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
@@ -359,7 +360,8 @@ namespace SabreTools
DatFile datdata = new DatFile(); DatFile datdata = new DatFile();
foreach (string datfile in datfiles) 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")); _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
@@ -823,7 +825,9 @@ namespace SabreTools
/// <param name="hashOnly">True if only hashes should be checked, false for full file information</param> /// <param name="hashOnly">True if only hashes should be checked, false for full file information</param>
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param> /// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param> /// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
private static void InitVerify(List<string> datfiles, List<string> inputs, string tempDir, bool hashOnly, bool quickScan, string headerToCheckAgainst) /// <param name="splitType">Type of the split that should be performed (split, merged, fully merged)</param>
private static void InitVerify(List<string> datfiles, List<string> inputs, string tempDir,
bool hashOnly, bool quickScan, string headerToCheckAgainst, SplitType splitType)
{ {
// Get the archive scanning level // Get the archive scanning level
ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1); ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1);
@@ -835,7 +839,8 @@ namespace SabreTools
DatFile datdata = new DatFile(); DatFile datdata = new DatFile();
foreach (string datfile in datfiles) 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")); _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
@@ -849,7 +854,9 @@ namespace SabreTools
/// <param name="inputs">Input directories to compare against</param> /// <param name="inputs">Input directories to compare against</param>
/// <param name="tempDir">Temporary directory for archive extraction</param> /// <param name="tempDir">Temporary directory for archive extraction</param>
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param> /// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
private static void InitVerifyDepot(List<string> datfiles, List<string> inputs, string tempDir, string headerToCheckAgainst) /// <param name="splitType">Type of the split that should be performed (split, merged, fully merged)</param>
private static void InitVerifyDepot(List<string> datfiles, List<string> inputs, string tempDir,
string headerToCheckAgainst, SplitType splitType)
{ {
DateTime start = DateTime.Now; DateTime start = DateTime.Now;
_logger.User("Populating internal DAT..."); _logger.User("Populating internal DAT...");
@@ -858,7 +865,8 @@ namespace SabreTools
DatFile datdata = new DatFile(); DatFile datdata = new DatFile();
foreach (string datfile in datfiles) 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")); _logger.User("Populating complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));