mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add output redirection to HashSplit
This commit is contained in:
@@ -13,16 +13,19 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
// Internal variables
|
// Internal variables
|
||||||
List<string> _inputs;
|
List<string> _inputs;
|
||||||
|
string _outdir;
|
||||||
Logger _logger;
|
Logger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a HashSplit object
|
/// Create a HashSplit object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The name of the file to be split</param>
|
/// <param name="filename">The name of the file to be split</param>
|
||||||
|
/// <param name="outdir">Optional output directory, defaults to DAT directory</param>
|
||||||
/// <param name="logger">Logger object for file and console output</param>
|
/// <param name="logger">Logger object for file and console output</param>
|
||||||
public HashSplit(List<string> inputs, Logger logger)
|
public HashSplit(List<string> inputs, string outdir, Logger logger)
|
||||||
{
|
{
|
||||||
_inputs = inputs;
|
_inputs = inputs;
|
||||||
|
_outdir = (outdir.EndsWith(Path.DirectorySeparatorChar.ToString()) ? outdir : outdir + Path.DirectorySeparatorChar).Replace("\"", "");
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +48,7 @@ namespace SabreTools
|
|||||||
logger.Start();
|
logger.Start();
|
||||||
|
|
||||||
// First things first, take care of all of the arguments that this could have
|
// First things first, take care of all of the arguments that this could have
|
||||||
|
string outdir = "";
|
||||||
List<string> inputs = new List<string>();
|
List<string> inputs = new List<string>();
|
||||||
foreach (string arg in args)
|
foreach (string arg in args)
|
||||||
{
|
{
|
||||||
@@ -57,7 +61,14 @@ namespace SabreTools
|
|||||||
logger.Close();
|
logger.Close();
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
inputs.Add(arg);
|
if (arg.StartsWith("out="))
|
||||||
|
{
|
||||||
|
outdir = arg.Split('=')[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inputs.Add(arg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +97,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If so, run the program
|
// If so, run the program
|
||||||
HashSplit hs = new HashSplit(inputs, logger);
|
HashSplit hs = new HashSplit(inputs, outdir, logger);
|
||||||
hs.Split();
|
hs.Split();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,13 +121,13 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
if (File.Exists(input))
|
if (File.Exists(input))
|
||||||
{
|
{
|
||||||
finalreturn &= SplitHelper(input);
|
finalreturn &= SplitHelper(input, Path.GetDirectoryName(input));
|
||||||
}
|
}
|
||||||
if (Directory.Exists(input))
|
if (Directory.Exists(input))
|
||||||
{
|
{
|
||||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
finalreturn &= SplitHelper(Path.GetFullPath(file));
|
finalreturn &= SplitHelper(Path.GetFullPath(file), (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +135,7 @@ namespace SabreTools
|
|||||||
return finalreturn;
|
return finalreturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SplitHelper(string filename)
|
private bool SplitHelper(string filename, string basepath)
|
||||||
{
|
{
|
||||||
// Get the file data to be split
|
// Get the file data to be split
|
||||||
OutputFormat outputFormat = RomManipulation.GetOutputFormat(filename);
|
OutputFormat outputFormat = RomManipulation.GetOutputFormat(filename);
|
||||||
@@ -252,11 +263,20 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = true;
|
// Get the output directory
|
||||||
|
string outdir = "";
|
||||||
|
if (_outdir != "")
|
||||||
|
{
|
||||||
|
outdir = _outdir + Path.GetDirectoryName(filename).Remove(0, filename.Length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outdir = Path.GetDirectoryName(filename);
|
||||||
|
}
|
||||||
|
|
||||||
// Now, output all of the files to the original location
|
// Now, output all of the files to the output directory
|
||||||
_logger.User("DAT information created, outputting new files");
|
_logger.User("DAT information created, outputting new files");
|
||||||
string outdir = Path.GetDirectoryName(filename);
|
bool success = true;
|
||||||
success &= Output.WriteDatfile(sha1, outdir, _logger);
|
success &= Output.WriteDatfile(sha1, outdir, _logger);
|
||||||
success &= Output.WriteDatfile(md5, outdir, _logger);
|
success &= Output.WriteDatfile(md5, outdir, _logger);
|
||||||
success &= Output.WriteDatfile(crc, outdir, _logger);
|
success &= Output.WriteDatfile(crc, outdir, _logger);
|
||||||
|
|||||||
@@ -215,10 +215,11 @@ Options:
|
|||||||
case "HashSplit":
|
case "HashSplit":
|
||||||
Console.WriteLine(@"HashSplit - Split a DAT by best-available hashes
|
Console.WriteLine(@"HashSplit - Split a DAT by best-available hashes
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
Usage: DATabaseTwo [options] filename
|
Usage: HashSplit [options] [filename|dirname] <filename|dirname> ...
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, -?, --help Show this help dialog
|
-h, -?, --help Show this help dialog
|
||||||
|
-out= Output directory
|
||||||
");
|
");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user