mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Headerer] Add output directory for headerer
This commit is contained in:
@@ -172,6 +172,7 @@ namespace SabreTools.Helper
|
|||||||
helptext.Add(" -o, --old Output DAT in CMP format instead of XML");
|
helptext.Add(" -o, --old Output DAT in CMP format instead of XML");
|
||||||
helptext.Add(" -he, --headerer Extract and remove copier headers");
|
helptext.Add(" -he, --headerer Extract and remove copier headers");
|
||||||
helptext.Add(" -r, --restore Restore header to file based on SHA-1 instead");
|
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(" -hs, --hash-split Split a DAT or folder by best-available hashes");
|
||||||
helptext.Add(" -out= Output directory");
|
helptext.Add(" -out= Output directory");
|
||||||
helptext.Add(" -i, --import Start tool in import mode");
|
helptext.Add(" -i, --import Start tool in import mode");
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace SabreTools
|
|||||||
// Private instance variables
|
// Private instance variables
|
||||||
private List<string> _inputs;
|
private List<string> _inputs;
|
||||||
private bool _restore;
|
private bool _restore;
|
||||||
|
private string _outdir;
|
||||||
private Logger _logger;
|
private Logger _logger;
|
||||||
|
|
||||||
// Private required variables
|
// Private required variables
|
||||||
@@ -26,11 +27,13 @@ namespace SabreTools
|
|||||||
/// </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="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>
|
/// <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;
|
_inputs = inputs;
|
||||||
_restore = restore;
|
_restore = restore;
|
||||||
|
_outdir = outdir;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +124,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, apply the rule to the file
|
// 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);
|
Skippers.TransformFile(file, newfile, rule, _logger);
|
||||||
|
|
||||||
// If the output file doesn't exist, return false
|
// 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));
|
_logger.Log("Found match with rom type " + sldr.GetString(1));
|
||||||
header = sldr.GetString(0);
|
header = sldr.GetString(0);
|
||||||
|
|
||||||
_logger.User("Creating reheadered file: " + file + ".new" + sub);
|
_logger.User("Creating reheadered file: " +
|
||||||
FileTools.AppendBytesToFile(file, file + ".new" + sub, header, string.Empty);
|
(_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!");
|
_logger.User("Reheadered file created!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -399,6 +399,10 @@ Options:
|
|||||||
to reapply them to files if they match the included hash. More than one header can
|
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,
|
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.
|
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
|
-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
|
For a DAT, or set of DATs, allow for splitting based on the best available hash for
|
||||||
|
|||||||
@@ -465,8 +465,7 @@ namespace SabreTools.Helper
|
|||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
logger.User(" Matching rule found!");
|
logger.User(" Matching rule found!");
|
||||||
skipperRule = rule;
|
return rule;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,10 +319,11 @@ namespace SabreTools
|
|||||||
/// </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="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>
|
/// <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();
|
headerer.Process();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -713,7 +713,7 @@ namespace SabreTools
|
|||||||
// If we're in headerer mode
|
// If we're in headerer mode
|
||||||
else if (headerer)
|
else if (headerer)
|
||||||
{
|
{
|
||||||
InitHeaderer(inputs, restore, _logger);
|
InitHeaderer(inputs, restore, outdir, _logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import a file or folder
|
// Import a file or folder
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the matches to the file that was found
|
// 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!");
|
_logger.Log("File '" + input + "' had " + foundroms.Count + " matches in the DAT!");
|
||||||
foreach (Rom found in foundroms)
|
foreach (Rom found in foundroms)
|
||||||
{
|
{
|
||||||
@@ -583,7 +583,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to find the matches to the file that was found
|
// 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!");
|
_logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!");
|
||||||
foreach (Rom found in founddroms)
|
foreach (Rom found in founddroms)
|
||||||
{
|
{
|
||||||
@@ -706,7 +706,7 @@ namespace SabreTools
|
|||||||
foreach (Rom rom in internalRomData)
|
foreach (Rom rom in internalRomData)
|
||||||
{
|
{
|
||||||
// Try to find the matches to the file that was found
|
// 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!");
|
_logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!");
|
||||||
foreach (Rom found in foundroms)
|
foreach (Rom found in foundroms)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user