[SabreTools] Split former Headerer flag into Extract and Replace

This commit is contained in:
Matt Nadareski
2016-11-07 14:46:54 -08:00
parent 2f102800b7
commit 209f189951
4 changed files with 112 additions and 55 deletions

View File

@@ -192,9 +192,8 @@ namespace SabreTools.Helper.Data
helptext.Add(" -extb= Second set of extensions (comma-separated)"); helptext.Add(" -extb= Second set of extensions (comma-separated)");
helptext.Add(" -out= Output directory"); helptext.Add(" -out= Output directory");
// Headerer // Extract and Remove Headers
helptext.Add(" -he, --headerer Extract and remove copier headers"); helptext.Add(" -ex, --extract Extract and remove copier headers");
helptext.Add(" -r, --restore Restore header to file based on SHA-1 instead");
helptext.Add(" -out= Output directory"); helptext.Add(" -out= Output directory");
// Hash Split // Hash Split
@@ -207,6 +206,10 @@ namespace SabreTools.Helper.Data
helptext.Add(" -s, --short Use short output names"); helptext.Add(" -s, --short Use short output names");
helptext.Add(" -ba, --base Use source DAT as base name for outputs"); helptext.Add(" -ba, --base Use source DAT as base name for outputs");
// Restore Headers
helptext.Add(" -re, --restore Restore header to file based on SHA-1");
helptext.Add(" -out= Output directory");
// Sort // Sort
helptext.Add(" -ss, --sort Sort input files by a set of DATs"); helptext.Add(" -ss, --sort Sort input files by a set of DATs");
helptext.Add(" -dat= Input DAT to rebuild against"); helptext.Add(" -dat= Input DAT to rebuild against");
@@ -263,7 +266,7 @@ namespace SabreTools.Helper.Data
helptext.Add(" -post=, --postfix= Set postfix for all lines"); helptext.Add(" -post=, --postfix= Set postfix for all lines");
helptext.Add(" -q, --quotes Put double-quotes around each item"); helptext.Add(" -q, --quotes Put double-quotes around each item");
helptext.Add(" -ae=, --add-ext= Add an extension to each item"); helptext.Add(" -ae=, --add-ext= Add an extension to each item");
helptext.Add(" -re=, --rep-ext= Replace all extensions with specified"); helptext.Add(" -rep=, --rep-ext= Replace all extensions with specified");
helptext.Add(" -rme, --rem-ext Remove all extensions from each item"); helptext.Add(" -rme, --rem-ext Remove all extensions from each item");
helptext.Add(" -ro, --romba Output in Romba format (requires SHA-1)"); helptext.Add(" -ro, --romba Output in Romba format (requires SHA-1)");
helptext.Add(" -tsv, --tsv Output in Tab-Separated Value format"); helptext.Add(" -tsv, --tsv Output in Tab-Separated Value format");

View File

@@ -297,12 +297,8 @@ Options:
This sets an output folder to be used when the files are created. If a path 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. is not defined, the application directory is used instead.
-hd, --headerer Backup or restore copier headers from a variety of file types -ex, --extract Backup and remove copier headers from a variety of file types
Headerer is meant as an intermediary between header skipper files (which, a bit This will detect, store, and remove copier headers from a file or folder
apart from their name, do not just show how to skip copier headers) and rom managers
that do not use them.
By default, this will detect, store, and remove copier headers from a file or folder
of files. The headers are backed up and collated by the hash of the unheadered file. of files. The headers are backed up and collated by the hash of the unheadered file.
Files are then output without the detected copier header alongside the originals with Files are then output without the detected copier header alongside the originals with
the suffix .new. No input files are altered in the process. the suffix .new. No input files are altered in the process.
@@ -317,12 +313,6 @@ Options:
- Nintendo Super Famicom / Super Nintendo Entertainment System - Nintendo Super Famicom / Super Nintendo Entertainment System
- Nintendo Super Famicom / Super Nintendo Entertainment System SPC Music - Nintendo Super Famicom / Super Nintendo Entertainment System SPC Music
-re, --restore Restore headers to file(s)
Instead of the default extraction, this flag enables use of stored copier headers
to reapply them to files if they match the included hash. More than one header can
be applied to a file, so they will be output to new files, suffixed with .newX,
where X is a number. No input files are altered in the process.
-out= Set the name of the output directory -out= Set the name of the output directory
This sets an output folder to be used when the files are created. If a path 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. is not defined, the application directory is used instead.
@@ -360,6 +350,26 @@ Options:
the output name, in the format of "Original Name (Dir - Name)". This can be used in the output name, in the format of "Original Name (Dir - Name)". This can be used in
conjunction with --short to output in the format of "Original Name (Name)" instead. conjunction with --short to output in the format of "Original Name (Name)" instead.
-re, --restore Restore copier headers from a variety of file types
This will make use of stored copier headers and reapply them to files if they match the
included hash. More than one header can be applied to a file, so they will be output to
new files, suffixed with .newX, where X is a number. No input files are altered in the
process.
The following systems have headers that this program can work with:
- Atari 7800
- Atari Lynx
- Commodore PSID Music
- NEC PC-Engine / TurboGrafx 16
- Nintendo Famicom / Nintendo Entertainment System
- Nintendo Famicom Disk System
- Nintendo Super Famicom / Super Nintendo Entertainment System
- Nintendo Super Famicom / Super Nintendo Entertainment System SPC Music
-out= Set the name of the output directory
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.
-ss, --sort Sort input files by a set of DATs -ss, --sort Sort input files by a set of DATs
This feature allows the user to quickly rebuild based on a supplied DAT file(s). By This feature allows the user to quickly rebuild based on a supplied DAT file(s). By
default all files will be rebuilt to uncompressed folders in the output directory. default all files will be rebuilt to uncompressed folders in the output directory.
@@ -1248,6 +1258,36 @@ Below are originally from SabreTools / DATabase -
-old, --romvault Produce a DAT in RV format -old, --romvault Produce a DAT in RV format
-hd, --headerer Backup or restore copier headers from a variety of file types
Headerer is meant as an intermediary between header skipper files (which, a bit
apart from their name, do not just show how to skip copier headers) and rom managers
that do not use them.
By default, this will detect, store, and remove copier headers from a file or folder
of files. The headers are backed up and collated by the hash of the unheadered file.
Files are then output without the detected copier header alongside the originals with
the suffix .new. No input files are altered in the process.
The following systems have headers that this program can work with:
- Atari 7800
- Atari Lynx
- Commodore PSID Music
- NEC PC-Engine / TurboGrafx 16
- Nintendo Famicom / Nintendo Entertainment System
- Nintendo Famicom Disk System
- Nintendo Super Famicom / Super Nintendo Entertainment System
- Nintendo Super Famicom / Super Nintendo Entertainment System SPC Music
-re, --restore Restore headers to file(s)
Instead of the default extraction, this flag enables use of stored copier headers
to reapply them to files if they match the included hash. More than one header can
be applied to a file, so they will be output to new files, suffixed with .newX,
where X is a number. No input files are altered in the process.
-out= Set the name of the output directory
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.
-i, -import Start tool in import mode -i, -import Start tool in import mode
This starts the tool in DATabase import mode. This will allow for hashing of new This starts the tool in DATabase import mode. This will allow for hashing of new
DAT files in the dats folder. If a source for the DAT cannot be automatically DAT files in the dats folder. If a source for the DAT cannot be automatically

View File

@@ -137,6 +137,29 @@ namespace SabreTools
} }
} }
/// <summary>
/// Wrap extracting headers
/// </summary>
/// <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>
private static void InitExtractRemoveHeader(List<string> inputs, string outDir)
{
foreach (string input in inputs)
{
if (File.Exists(input))
{
FileTools.DetectSkipperAndTransform(input, outDir, _logger);
}
else if (Directory.Exists(input))
{
foreach (string sub in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
{
FileTools.DetectSkipperAndTransform(sub, outDir, _logger);
}
}
}
}
/// <summary> /// <summary>
/// Wrap splitting a DAT by 2 extensions /// Wrap splitting a DAT by 2 extensions
/// </summary> /// </summary>
@@ -214,39 +237,24 @@ namespace SabreTools
} }
/// <summary> /// <summary>
/// Wrap extracting and replacing headers /// Wrap replacing headers
/// </summary> /// </summary>
/// <param name="inputs">Input file or folder names</param> /// <param name="inputs">Input file or folder names</param>
/// <param name="restore">False if we're extracting headers (default), true if we're restoring them</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 InitHeaderer(List<string> inputs, bool restore, string outDir) private static void InitReplaceHeader(List<string> inputs, string outDir)
{ {
foreach (string input in inputs) foreach (string input in inputs)
{ {
if (File.Exists(input)) if (File.Exists(input))
{
if (restore)
{ {
FileTools.RestoreHeader(input, outDir, _logger); FileTools.RestoreHeader(input, outDir, _logger);
} }
else
{
FileTools.DetectSkipperAndTransform(input, outDir, _logger);
}
}
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))
{
if (restore)
{ {
FileTools.RestoreHeader(sub, outDir, _logger); FileTools.RestoreHeader(sub, outDir, _logger);
} }
else
{
FileTools.DetectSkipperAndTransform(sub, outDir, _logger);
}
}
} }
} }
} }

View File

@@ -56,7 +56,8 @@ namespace SabreTools
// Feature flags // Feature flags
bool help = false, bool help = false,
datFromDir = false, datFromDir = false,
headerer = false, extract = false,
restore = false,
sort = false, // SimpleSort sort = false, // SimpleSort
splitByExt = false, splitByExt = false,
splitByHash = false, splitByHash = false,
@@ -87,7 +88,6 @@ namespace SabreTools
quotes = false, quotes = false,
remext = false, remext = false,
removeDateFromAutomaticName = false, removeDateFromAutomaticName = false,
restore = false,
romba = false, romba = false,
showBaddumpColumn = false, showBaddumpColumn = false,
showNodumpColumn = false, showNodumpColumn = false,
@@ -168,9 +168,9 @@ namespace SabreTools
case "--ext-split": case "--ext-split":
splitByExt = true; splitByExt = true;
break; break;
case "-hd": case "-ex":
case "--headerer": case "--extract":
headerer = true; extract = true;
break; break;
case "-hs": case "-hs":
case "--hash-split": case "--hash-split":
@@ -180,6 +180,10 @@ namespace SabreTools
case "--lvl-split": case "--lvl-split":
splitByLevel = true; splitByLevel = true;
break; break;
case "-re":
case "--restore":
restore = true;
break;
case "-ss": case "-ss":
case "--sort": case "--sort":
sort = true; sort = true;
@@ -374,10 +378,6 @@ namespace SabreTools
case "--rev-cascade": case "--rev-cascade":
diffMode |= DiffMode.ReverseCascade; diffMode |= DiffMode.ReverseCascade;
break; break;
case "-re":
case "--restore":
restore = true;
break;
case "-rme": case "-rme":
case "--rem-ext": case "--rem-ext":
remext = true; remext = true;
@@ -833,7 +833,7 @@ namespace SabreTools
case "--root-dir": case "--root-dir":
root = split[1]; root = split[1];
break; break;
case "-re": case "-rep":
case "--rep-ext": case "--rep-ext":
repext = split[1]; repext = split[1];
break; break;
@@ -926,7 +926,7 @@ namespace SabreTools
} }
// If more than one switch is enabled, show the help screen // If more than one switch is enabled, show the help screen
if (!(datFromDir ^ headerer ^ sort ^ splitByExt ^ splitByHash ^ splitByLevel ^ splitByType ^ stats ^ update ^ verify)) if (!(datFromDir ^ extract ^ restore ^ sort ^ splitByExt ^ splitByHash ^ splitByLevel ^ splitByType ^ stats ^ update ^ verify))
{ {
_logger.Error("Only one feature switch is allowed at a time"); _logger.Error("Only one feature switch is allowed at a time");
Build.Help("SabreTools"); Build.Help("SabreTools");
@@ -936,7 +936,7 @@ namespace SabreTools
// If a switch that requires a filename is set and no file is, show the help screen // If a switch that requires a filename is set and no file is, show the help screen
if (inputs.Count == 0 if (inputs.Count == 0
&& (datFromDir || headerer || splitByExt || splitByHash || splitByLevel || splitByType || stats || update)) && (datFromDir || extract || restore || splitByExt || splitByHash || splitByLevel || splitByType || stats || update))
{ {
_logger.Error("This feature requires at least one input"); _logger.Error("This feature requires at least one input");
Build.Help("SabreTools"); Build.Help("SabreTools");
@@ -975,10 +975,16 @@ namespace SabreTools
maxParallelism); maxParallelism);
} }
// If we're in headerer mode // If we're in header extract and remove mode
else if (headerer) else if (extract)
{ {
InitHeaderer(inputs, restore, outDir); InitExtractRemoveHeader(inputs, outDir);
}
// If we're in header restore mode
else if (restore)
{
InitReplaceHeader(inputs, outDir);
} }
// If we're using the sorter // If we're using the sorter