[SabreTools, README.1ST] Hook up and document level split

This commit is contained in:
Matt Nadareski
2016-10-26 14:41:37 -07:00
parent ddc39fee0f
commit b76099ba7a
4 changed files with 61 additions and 5 deletions

View File

@@ -200,6 +200,10 @@ namespace SabreTools.Helper.Data
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");
// Level/SuperDAT Split
helptext.Add(" -ls, --lvl-split Split a SuperDAT or folder by internal path");
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");

View File

@@ -336,9 +336,15 @@ 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.
-input= Set an input string -ls, --lvl-split Split a SuperDAT or folder by lowest available level
This should only be used if one of the inputs starts with a flag or another already For a DAT, or set of DATs, allow for splitting based on the lowest available level
defined input. of game name. That is, if a game name is top/mid/last, then it will create
an output DAT for the parent directory "mid" in a folder called "top" with a game
called "last".
-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

View File

@@ -244,6 +244,41 @@ namespace SabreTools
} }
} }
/// <summary>
/// Wrap splitting a SuperDAT by lowest available level
/// </summary>
/// <param name="inputs">List of inputs to be used</param>
/// <param name="outDir">Output directory for the split files</param>
private static void InitLevelSplit(List<string> inputs, string outDir)
{
// Loop over the input files
foreach (string input in inputs)
{
if (File.Exists(input))
{
DatFile datFile = new DatFile();
datFile.Parse(Path.GetFullPath(input), 0, 0, _logger, softlist: true);
datFile.SplitByLevel(outDir, Path.GetDirectoryName(input), _logger);
}
else if (Directory.Exists(input))
{
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
{
DatFile datFile = new DatFile();
datFile.Parse(Path.GetFullPath(file), 0, 0, _logger, softlist: true);
datFile.SplitByLevel(outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger);
}
}
else
{
_logger.Error(input + " is not a valid file or folder!");
Console.WriteLine();
Build.Help("SabreTools");
return;
}
}
}
/// <summary> /// <summary>
/// Wrap sorting files using an input DAT /// Wrap sorting files using an input DAT
/// </summary> /// </summary>

View File

@@ -56,6 +56,7 @@ namespace SabreTools
sort = false, // SimpleSort sort = false, // SimpleSort
splitByExt = false, splitByExt = false,
splitByHash = false, splitByHash = false,
splitByLevel = false,
splitByType = false, splitByType = false,
stats = false, stats = false,
update = false, update = false,
@@ -169,6 +170,10 @@ namespace SabreTools
case "--hash-split": case "--hash-split":
splitByHash = true; splitByHash = true;
break; break;
case "-ls":
case "--lvl-split":
splitByLevel = true;
break;
case "-ss": case "-ss":
case "--sort": case "--sort":
sort = true; sort = true;
@@ -903,7 +908,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 ^ splitByType ^ stats ^ update ^ verify)) if (!(datFromDir ^ headerer ^ 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");
@@ -913,7 +918,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 || splitByType || stats || update)) && (datFromDir || headerer || 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");
@@ -977,6 +982,12 @@ namespace SabreTools
InitHashSplit(inputs, outDir); InitHashSplit(inputs, outDir);
} }
// Split a SuperDAT by lowest available level
else if (splitByLevel)
{
InitLevelSplit(inputs, outDir);
}
// Split a DAT by item type // Split a DAT by item type
else if (splitByType) else if (splitByType)
{ {