[SabreTools, FileTools, README.1ST] Add "don't add to db" flag

This commit is contained in:
Matt Nadareski
2017-10-31 21:35:54 -07:00
parent 592b81b626
commit 29c29df8cf
5 changed files with 27 additions and 7 deletions

View File

@@ -405,6 +405,11 @@ Options:
This sets an output folder to be used when the files are created. If This sets an output folder to be used when the files are created. If
a path is not defined, the application directory is used instead. a path is not defined, the application directory is used instead.
-nsh, --no-store-header Don't store the extracted header
By default, all headers that are removed from files are backed up in
the database. This flag allows users to skip that step entirely,
avoiding caching the headers at all.
-hs, --hash-split Split a DAT or folder by best-available hashes -hs, --hash-split Split a DAT or folder by best-available hashes
For a DAT, or set of DATs, allow for splitting based on the best For a DAT, or set of DATs, allow for splitting based on the best
available hash for each file within. The order of preference for the available hash for each file within. The order of preference for the

View File

@@ -394,8 +394,9 @@ namespace SabreTools.Library.Tools
/// </summary> /// </summary>
/// <param name="file">Name of the file to be parsed</param> /// <param name="file">Name of the file to be parsed</param>
/// <param name="outDir">Output directory to write the file to, empty means the same directory as the input file</param> /// <param name="outDir">Output directory to write the file to, empty means the same directory as the input file</param>
/// <param name="nostore">True if headers should not be stored in the database, false otherwise</param>
/// <returns>True if the output file was created, false otherwise</returns> /// <returns>True if the output file was created, false otherwise</returns>
public static bool DetectSkipperAndTransform(string file, string outDir) public static bool DetectSkipperAndTransform(string file, string outDir, bool nostore)
{ {
// Create the output directory if it doesn't exist // Create the output directory if it doesn't exist
if (outDir != "" && !Directory.Exists(outDir)) if (outDir != "" && !Directory.Exists(outDir))
@@ -439,8 +440,11 @@ namespace SabreTools.Library.Tools
} }
// Now add the information to the database if it's not already there // Now add the information to the database if it's not already there
if (!nostore)
{
Rom rom = (Rom)GetFileInfo(newfile, chdsAsFiles: true); Rom rom = (Rom)GetFileInfo(newfile, chdsAsFiles: true);
DatabaseTools.AddHeaderToDatabase(hstr, rom.SHA1, rule.SourceFile); DatabaseTools.AddHeaderToDatabase(hstr, rom.SHA1, rule.SourceFile);
}
return true; return true;
} }

View File

@@ -312,6 +312,11 @@ namespace SabreTools
"Output directory", "Output directory",
FeatureType.String, FeatureType.String,
null)); null));
extract.AddFeature("no-store-header", new Feature(
new List<string>() { "-nsh", "--no-store-header" },
"Don't store the extracted header",
FeatureType.Flag,
null));
// Create the Extension Split feature // Create the Extension Split feature
Feature extSplit = new Feature( Feature extSplit = new Feature(

View File

@@ -160,19 +160,20 @@ namespace SabreTools
/// </summary> /// </summary>
/// <param name="inputs">Input file or folder names</param> /// <param name="inputs">Input file or folder names</param>
/// <param name="outDir">Output directory to write new files to, blank defaults to rom folder</param> /// <param name="outDir">Output directory to write new files to, blank defaults to rom folder</param>
private static void InitExtractRemoveHeader(List<string> inputs, string outDir) /// <param name="nostore">True if headers should not be stored in the database, false otherwise</param>
private static void InitExtractRemoveHeader(List<string> inputs, string outDir, bool nostore)
{ {
foreach (string input in inputs) foreach (string input in inputs)
{ {
if (File.Exists(input)) if (File.Exists(input))
{ {
FileTools.DetectSkipperAndTransform(input, outDir); FileTools.DetectSkipperAndTransform(input, outDir, nostore);
} }
else if (Directory.Exists(input)) else if (Directory.Exists(input))
{ {
foreach (string sub in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) foreach (string sub in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
{ {
FileTools.DetectSkipperAndTransform(sub, outDir); FileTools.DetectSkipperAndTransform(sub, outDir, nostore);
} }
} }
} }

View File

@@ -103,6 +103,7 @@ namespace SabreTools
inplace = true, inplace = true,
inverse = false, inverse = false,
merge = false, merge = false,
nostore = false,
oneGameOneRegion = false, oneGameOneRegion = false,
quickScan = false, quickScan = false,
quotes = false, quotes = false,
@@ -436,6 +437,10 @@ namespace SabreTools
case "--noSHA512": case "--noSHA512":
omitFromScan &= ~Hash.SHA512; // This needs to be inverted later omitFromScan &= ~Hash.SHA512; // This needs to be inverted later
break; break;
case "-nsh":
case "--no-store-header":
nostore = true;
break;
case "-oa": case "-oa":
case "--output-all": case "--output-all":
datFormat |= DatFormat.ALL; datFormat |= DatFormat.ALL;
@@ -1261,7 +1266,7 @@ namespace SabreTools
// If we're in header extract and remove mode // If we're in header extract and remove mode
else if (extract) else if (extract)
{ {
InitExtractRemoveHeader(inputs, outDir); InitExtractRemoveHeader(inputs, outDir, nostore);
} }
// If we're in header restore mode // If we're in header restore mode