[Headerer] Add output directory for headerer

This commit is contained in:
Matt Nadareski
2016-09-12 17:47:16 -07:00
parent 46a3aa1c77
commit e08dd958f2
7 changed files with 22 additions and 12 deletions

View File

@@ -172,6 +172,7 @@ namespace SabreTools.Helper
helptext.Add(" -o, --old Output DAT in CMP format instead of XML");
helptext.Add(" -he, --headerer 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(" -hs, --hash-split Split a DAT or folder by best-available hashes");
helptext.Add(" -out= Output directory");
helptext.Add(" -i, --import Start tool in import mode");

View File

@@ -14,6 +14,7 @@ namespace SabreTools
// Private instance variables
private List<string> _inputs;
private bool _restore;
private string _outdir;
private Logger _logger;
// Private required variables
@@ -26,11 +27,13 @@ namespace SabreTools
/// </summary>
/// <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="logger">Logger object for file and console output</param>
public Headerer(List<string> inputs, bool restore, Logger logger)
public Headerer(List<string> inputs, bool restore, string outdir, Logger logger)
{
_inputs = inputs;
_restore = restore;
_outdir = outdir;
_logger = logger;
}
@@ -121,7 +124,7 @@ namespace SabreTools
}
// Otherwise, apply the rule to the file
string newfile = file + ".new";
string newfile = (_outdir == "" ? Path.GetFullPath(file) + ".new" : Path.Combine(_outdir, Path.GetFileName(file)));
Skippers.TransformFile(file, newfile, rule, _logger);
// If the output file doesn't exist, return false
@@ -207,8 +210,10 @@ namespace SabreTools
_logger.Log("Found match with rom type " + sldr.GetString(1));
header = sldr.GetString(0);
_logger.User("Creating reheadered file: " + file + ".new" + sub);
FileTools.AppendBytesToFile(file, file + ".new" + sub, header, string.Empty);
_logger.User("Creating reheadered file: " +
(_outdir == "" ? Path.GetFullPath(file) + ".new" : Path.Combine(_outdir, Path.GetFileName(file))) + sub);
FileTools.AppendBytesToFile(file,
(_outdir == "" ? Path.GetFullPath(file) + ".new" : Path.Combine(_outdir, Path.GetFileName(file))) + sub, header, string.Empty);
_logger.User("Reheadered file created!");
}
}

View File

@@ -400,6 +400,10 @@ Options:
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.
-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 available hash for
each file within. The order of preference for the outputted DATs is as follows:

View File

@@ -465,8 +465,7 @@ namespace SabreTools.Helper
if (success)
{
logger.User(" Matching rule found!");
skipperRule = rule;
break;
return rule;
}
}
}

View File

@@ -319,10 +319,11 @@ namespace SabreTools
/// </summary>
/// <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="logger">Logger object for file and console output</param>
private static void InitHeaderer(List<string> inputs, bool restore, Logger logger)
private static void InitHeaderer(List<string> inputs, bool restore, string outdir, Logger logger)
{
Headerer headerer = new Headerer(inputs, restore, logger);
Headerer headerer = new Headerer(inputs, restore, outdir, logger);
headerer.Process();
}

View File

@@ -713,7 +713,7 @@ namespace SabreTools
// If we're in headerer mode
else if (headerer)
{
InitHeaderer(inputs, restore, _logger);
InitHeaderer(inputs, restore, outdir, _logger);
}
// Import a file or folder

View File

@@ -517,7 +517,7 @@ namespace SabreTools
}
// Try to find the matches to the file that was found
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger);
_logger.Log("File '" + input + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Rom found in foundroms)
{
@@ -583,7 +583,7 @@ namespace SabreTools
}
// Try to find the matches to the file that was found
List<Rom> founddroms = RomTools.GetDuplicates(drom, _datdata, _logger, true);
List<Rom> founddroms = RomTools.GetDuplicates(drom, _datdata, _logger);
_logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!");
foreach (Rom found in founddroms)
{
@@ -706,7 +706,7 @@ namespace SabreTools
foreach (Rom rom in internalRomData)
{
// Try to find the matches to the file that was found
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger);
_logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Rom found in foundroms)
{