mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add multiple input and directory support
This commit is contained in:
@@ -12,7 +12,7 @@ namespace SabreTools
|
|||||||
public class HashSplit
|
public class HashSplit
|
||||||
{
|
{
|
||||||
// Internal variables
|
// Internal variables
|
||||||
string _filename;
|
List<string> _inputs;
|
||||||
Logger _logger;
|
Logger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -20,9 +20,9 @@ namespace SabreTools
|
|||||||
/// </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="logger">Logger object for file and console output</param>
|
/// <param name="logger">Logger object for file and console output</param>
|
||||||
public HashSplit(string filename, Logger logger)
|
public HashSplit(List<string> inputs, Logger logger)
|
||||||
{
|
{
|
||||||
_filename = filename;
|
_inputs = inputs;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,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 filename = "";
|
List<string> inputs = new List<string>();
|
||||||
foreach (string arg in args)
|
foreach (string arg in args)
|
||||||
{
|
{
|
||||||
switch (arg)
|
switch (arg)
|
||||||
@@ -57,13 +57,13 @@ namespace SabreTools
|
|||||||
logger.Close();
|
logger.Close();
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
filename = arg;
|
inputs.Add(arg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no inputs, show the help
|
// If there's no inputs, show the help
|
||||||
if (filename == "")
|
if (inputs.Count() == 0)
|
||||||
{
|
{
|
||||||
Build.Help();
|
Build.Help();
|
||||||
logger.Close();
|
logger.Close();
|
||||||
@@ -74,18 +74,19 @@ namespace SabreTools
|
|||||||
Build.Start("HashSplit");
|
Build.Start("HashSplit");
|
||||||
|
|
||||||
// Verify the input file
|
// Verify the input file
|
||||||
filename = filename.Replace("\"", "");
|
foreach (string input in inputs)
|
||||||
if (!File.Exists(filename))
|
|
||||||
{
|
{
|
||||||
logger.Error(filename + " is not a valid file!");
|
if (!File.Exists(input.Replace("\"", "")) && !Directory.Exists(input.Replace("\"", "")))
|
||||||
Console.WriteLine();
|
{
|
||||||
Build.Help();
|
logger.Error(input + " is not a valid file!");
|
||||||
return;
|
Console.WriteLine();
|
||||||
|
Build.Help();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If so, run the program
|
// If so, run the program
|
||||||
filename = Path.GetFullPath(filename);
|
HashSplit hs = new HashSplit(inputs, logger);
|
||||||
HashSplit hs = new HashSplit(filename, logger);
|
|
||||||
hs.Split();
|
hs.Split();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,16 +95,47 @@ namespace SabreTools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>True if the DATs were output, false otherwise</returns>
|
/// <returns>True if the DATs were output, false otherwise</returns>
|
||||||
public bool Split()
|
public bool Split()
|
||||||
|
{
|
||||||
|
// First, clean the original filenames
|
||||||
|
List<string> newinputs = new List<string>();
|
||||||
|
foreach (string input in _inputs)
|
||||||
|
{
|
||||||
|
newinputs.Add(Path.GetFullPath(input.Replace("\"", "")));
|
||||||
|
}
|
||||||
|
_inputs = newinputs;
|
||||||
|
|
||||||
|
// Now, process each file and folder in the input
|
||||||
|
bool finalreturn = true;
|
||||||
|
foreach (string input in _inputs)
|
||||||
|
{
|
||||||
|
if (File.Exists(input))
|
||||||
|
{
|
||||||
|
finalreturn &= SplitHelper(input);
|
||||||
|
}
|
||||||
|
if (Directory.Exists(input))
|
||||||
|
{
|
||||||
|
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
finalreturn &= SplitHelper(Path.GetFullPath(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalreturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool SplitHelper(string filename)
|
||||||
{
|
{
|
||||||
// Get the file data to be split
|
// Get the file data to be split
|
||||||
OutputFormat outputFormat = RomManipulation.GetOutputFormat(_filename);
|
OutputFormat outputFormat = RomManipulation.GetOutputFormat(filename);
|
||||||
DatData datdata = new DatData
|
DatData datdata = new DatData
|
||||||
{
|
{
|
||||||
Roms = new Dictionary<string, List<RomData>>(),
|
Roms = new Dictionary<string, List<RomData>>(),
|
||||||
};
|
};
|
||||||
datdata = RomManipulation.Parse(_filename, 0, 0, datdata, _logger, true);
|
datdata = RomManipulation.Parse(filename, 0, 0, datdata, _logger, true);
|
||||||
|
|
||||||
// Create each of the respective output DATs
|
// Create each of the respective output DATs
|
||||||
|
_logger.User("Creating and populating new DATs");
|
||||||
DatData sha1 = new DatData
|
DatData sha1 = new DatData
|
||||||
{
|
{
|
||||||
Name = datdata.Name + " (SHA-1)",
|
Name = datdata.Name + " (SHA-1)",
|
||||||
@@ -223,7 +255,8 @@ namespace SabreTools
|
|||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
// Now, output all of the files to the original location
|
// Now, output all of the files to the original location
|
||||||
string outdir = Path.GetDirectoryName(_filename);
|
_logger.User("DAT information created, outputting new files");
|
||||||
|
string outdir = Path.GetDirectoryName(filename);
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user