mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools, Enums] One split init for all variants
This commit is contained in:
@@ -258,6 +258,18 @@
|
||||
SHA512,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines how the DAT will be split on output
|
||||
/// </summary>
|
||||
public enum ExternalSplitType
|
||||
{
|
||||
None = 0,
|
||||
Extension,
|
||||
Hash,
|
||||
Level,
|
||||
Type,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines forcemerging tag for DAT output
|
||||
/// </summary>
|
||||
|
||||
@@ -172,66 +172,6 @@ namespace SabreTools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap splitting a DAT by 2 extensions
|
||||
/// </summary>
|
||||
/// <param name="inputs">Input files or folders to be split</param>
|
||||
/// <param name="exta">First extension to split on</param>
|
||||
/// <param name="extb">Second extension to split on</param>
|
||||
/// <param name="outDir">Output directory for the split files</param>
|
||||
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||
private static void InitExtSplit(List<string> inputs, List<string> exta, List<string> extb, string outDir, bool inplace)
|
||||
{
|
||||
// Get only files from the inputs
|
||||
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||
|
||||
// Loop over the input files
|
||||
foreach (string file in files)
|
||||
{
|
||||
// Split the input filename
|
||||
string[] splitpath = file.Split('¬');
|
||||
|
||||
// Create and fill the new DAT
|
||||
DatFile datFile = new DatFile();
|
||||
datFile.Parse(splitpath[0], 0, 0);
|
||||
|
||||
// Get the output directory
|
||||
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||
|
||||
// Split and write the DAT
|
||||
datFile.SplitByExtension(outDir, inplace, exta, extb);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap splitting a DAT by best available hashes
|
||||
/// </summary>
|
||||
/// <param name="inputs">List of inputs to be used</param>
|
||||
/// <param name="outDir">Output directory for the split files</param>
|
||||
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||
private static void InitHashSplit(List<string> inputs, string outDir, bool inplace)
|
||||
{
|
||||
// Get only files from the inputs
|
||||
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||
|
||||
// Loop over the input files
|
||||
foreach (string file in files)
|
||||
{
|
||||
// Split the input filename
|
||||
string[] splitpath = file.Split('¬');
|
||||
|
||||
// Create and fill the new DAT
|
||||
DatFile datFile = new DatFile();
|
||||
datFile.Parse(splitpath[0], 0, 0);
|
||||
|
||||
// Get the output directory
|
||||
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||
|
||||
// Split and write the DAT
|
||||
datFile.SplitByHash(outDir, inplace);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap replacing headers
|
||||
/// </summary>
|
||||
@@ -248,37 +188,6 @@ 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>
|
||||
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||
/// <param name="shortname">True if short filenames should be used, false otherwise</param>
|
||||
/// <param name="basedat">True if original filenames should be used as the base for output filename, false otherwise</param>
|
||||
private static void InitLevelSplit(List<string> inputs, string outDir, bool inplace, bool shortname, bool basedat)
|
||||
{
|
||||
// Get only files from the inputs
|
||||
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||
|
||||
// Loop over the input files
|
||||
foreach (string file in files)
|
||||
{
|
||||
// Split the input filename
|
||||
string[] splitpath = file.Split('¬');
|
||||
|
||||
// Create and fill the new DAT
|
||||
DatFile datFile = new DatFile();
|
||||
datFile.Parse(splitpath[0], 0, 0);
|
||||
|
||||
// Get the output directory
|
||||
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||
|
||||
// Split and write the DAT
|
||||
datFile.SplitByLevel(outDir, inplace, shortname, basedat);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap sorting files using an input DAT
|
||||
/// </summary>
|
||||
@@ -335,29 +244,25 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap getting statistics on a DAT or folder of DATs
|
||||
/// </summary>
|
||||
/// <param name="inputs">List of inputs to be used</param>
|
||||
/// <param name="filename">Name of the file to output to, blank for default</param>
|
||||
/// <param name="outDir">Output directory for the report files</param>
|
||||
/// <param name="single">True to show individual DAT statistics, false otherwise</param>
|
||||
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
|
||||
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
|
||||
/// <param name="statDatFormat">Set the statistics output format to use</param>
|
||||
private static void InitStats(List<string> inputs, string filename, string outDir, bool single, bool baddumpCol, bool nodumpCol,
|
||||
StatReportFormat statDatFormat)
|
||||
{
|
||||
DatFile.OutputStats(inputs, filename, outDir, single, baddumpCol, nodumpCol, statDatFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap splitting a DAT by item type
|
||||
/// Wrap splitting a DAT by any known type
|
||||
/// </summary>
|
||||
/// <param name="inputs">List of inputs to be used</param>
|
||||
/// <param name="outDir">Output directory for the split files</param>
|
||||
/// <param name="inplace">True if files should be written to the source folders, false otherwise</param>
|
||||
private static void InitTypeSplit(List<string> inputs, string outDir, bool inplace)
|
||||
/// <param name="splitType">Type of split to perform, if any</param>
|
||||
/// <param name="exta">First extension to split on (Extension Split only)</param>
|
||||
/// <param name="extb">Second extension to split on (Extension Split only)</param>
|
||||
/// <param name="shortname">True if short filenames should be used, false otherwise (Level Split only)</param>
|
||||
/// <param name="basedat">True if original filenames should be used as the base for output filename, false otherwise (Level Split only)</param>
|
||||
private static void InitSplit(List<string> inputs, string outDir, bool inplace, ExternalSplitType splitType,
|
||||
List<string> exta, List<string> extb, bool shortname, bool basedat)
|
||||
{
|
||||
// If we somehow have the "none" split type, return
|
||||
if (splitType == ExternalSplitType.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get only files from the inputs
|
||||
List<string> files = Utilities.GetOnlyFilesFromInputs(inputs, appendparent: true);
|
||||
|
||||
@@ -375,9 +280,39 @@ namespace SabreTools
|
||||
outDir = Utilities.GetOutputPath(outDir, file, inplace, splitpath: true);
|
||||
|
||||
// Split and write the DAT
|
||||
switch (splitType)
|
||||
{
|
||||
case ExternalSplitType.Extension:
|
||||
datFile.SplitByExtension(outDir, inplace, exta, extb);
|
||||
break;
|
||||
case ExternalSplitType.Hash:
|
||||
datFile.SplitByHash(outDir, inplace);
|
||||
break;
|
||||
case ExternalSplitType.Level:
|
||||
datFile.SplitByLevel(outDir, inplace, shortname, basedat);
|
||||
break;
|
||||
case ExternalSplitType.Type:
|
||||
datFile.SplitByType(outDir, inplace);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap getting statistics on a DAT or folder of DATs
|
||||
/// </summary>
|
||||
/// <param name="inputs">List of inputs to be used</param>
|
||||
/// <param name="filename">Name of the file to output to, blank for default</param>
|
||||
/// <param name="outDir">Output directory for the report files</param>
|
||||
/// <param name="single">True to show individual DAT statistics, false otherwise</param>
|
||||
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
|
||||
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
|
||||
/// <param name="statDatFormat">Set the statistics output format to use</param>
|
||||
private static void InitStats(List<string> inputs, string filename, string outDir, bool single, bool baddumpCol, bool nodumpCol,
|
||||
StatReportFormat statDatFormat)
|
||||
{
|
||||
DatFile.OutputStats(inputs, filename, outDir, single, baddumpCol, nodumpCol, statDatFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrap converting and updating DAT file from any format to any format
|
||||
|
||||
@@ -1300,25 +1300,25 @@ namespace SabreTools
|
||||
// Split a DAT by extension
|
||||
else if (splitByExt)
|
||||
{
|
||||
InitExtSplit(inputs, exta, extb, outDir, inplace);
|
||||
InitSplit(inputs, outDir, inplace, ExternalSplitType.Extension, exta, extb, shortname, basedat);
|
||||
}
|
||||
|
||||
// Split a DAT by available hashes
|
||||
else if (splitByHash)
|
||||
{
|
||||
InitHashSplit(inputs, outDir, inplace);
|
||||
InitSplit(inputs, outDir, inplace, ExternalSplitType.Hash, exta, extb, shortname, basedat);
|
||||
}
|
||||
|
||||
// Split a SuperDAT by lowest available level
|
||||
else if (splitByLevel)
|
||||
{
|
||||
InitLevelSplit(inputs, outDir, inplace, shortname, basedat);
|
||||
InitSplit(inputs, outDir, inplace, ExternalSplitType.Level, exta, extb, shortname, basedat);
|
||||
}
|
||||
|
||||
// Split a DAT by item type
|
||||
else if (splitByType)
|
||||
{
|
||||
InitTypeSplit(inputs, outDir, inplace);
|
||||
InitSplit(inputs, outDir, inplace, ExternalSplitType.Type, exta, extb, shortname, basedat);
|
||||
}
|
||||
|
||||
// Get statistics on input files
|
||||
|
||||
Reference in New Issue
Block a user