Add a couple new features

Added HashSplit to DATabase (commandline and menu)
Make DATFromDir properly use DatData objects
Add "Romba" option to DATFromDir to allow GZIP files to be read as archives
This commit is contained in:
Matt Nadareski
2016-05-22 12:45:20 -07:00
parent 3fe787dc61
commit e0bad9eccf
10 changed files with 153 additions and 324 deletions

View File

@@ -67,6 +67,7 @@ namespace SabreTools
forceunpack = false,
generate = false,
genall = false,
hashsplit = false,
import = false,
listsrc = false,
listsys = false,
@@ -169,6 +170,10 @@ namespace SabreTools
case "--game-prefix":
gamename = true;
break;
case "-hs":
case "--hash-split":
hashsplit = true;
break;
case "-i":
case "--import":
import = true;
@@ -321,7 +326,7 @@ namespace SabreTools
// If more than one switch is enabled or help is set, show the help screen
if (help || !(add ^ (convertMiss || romba) ^ convertCMP ^ convertRC ^ convertSD ^ convertXml ^ extsplit ^ generate ^
genall ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ rem ^ trim))
genall ^ hashsplit ^ import ^ listsrc ^ listsys ^ (merge || diff) ^ rem ^ trim))
{
Build.Help();
logger.Close();
@@ -329,7 +334,8 @@ namespace SabreTools
}
// If a switch that requires a filename is set and no file is, show the help screen
if (inputs.Count == 0 && ((convertMiss || romba) || convertCMP || convertRC || convertSD || convertXml || extsplit || import || (merge || diff) || trim))
if (inputs.Count == 0 && ((convertMiss || romba) || convertCMP || convertRC || convertSD
|| convertXml || extsplit || hashsplit || import || (merge || diff) || trim))
{
Build.Help();
logger.Close();
@@ -474,6 +480,12 @@ namespace SabreTools
InitMergeDiff(inputs, name, desc, cat, version, author, diff, dedup, bare, forceunpack, old, superdat, cascade);
}
// Split a DAT by available hashes
else if (hashsplit)
{
InitHashSplit(inputs, outdir);
}
logger.Close();
return;
}
@@ -675,6 +687,7 @@ Make a selection:
3) Trim all entries in DAT and merge into a single game
4) Merge, diff, and/or dedup 2 or more DAT files
5) Split DAT using 2 extensions
6) Split DATs by best available hash values
B) Go back to the previous menu
");
Console.Write("Enter selection: ");
@@ -696,6 +709,9 @@ Make a selection:
case "5":
ExtSplitMenu();
break;
case "6":
HashSplitMenu();
break;
}
}
}
@@ -1061,7 +1077,7 @@ Make a selection:
case "4":
Console.Clear();
Console.Write("Please enter the output directory: ");
exta = Console.ReadLine();
outdir = Console.ReadLine();
break;
case "5":
Console.Clear();
@@ -1074,6 +1090,52 @@ Make a selection:
}
}
/// <summary>
/// Show the text-based HashSplit menu
/// </summary>
private static void HashSplitMenu()
{
string selection = "", input = "", outdir = "";
while (selection.ToLowerInvariant() != "b")
{
Console.Clear();
Build.Start("DATabase");
Console.WriteLine(@"HASH SPLIT MENU
===========================
Make a selection:
1) File or folder to split" + (input != "" ? ":\n\t" + input : "") + @"
2) Output directory" + (outdir != "" ? ":\n\t" + outdir : "") + @"
3) Split the file
B) Go back to the previous menu
");
Console.Write("Enter selection: ");
selection = Console.ReadLine();
switch (selection)
{
case "1":
Console.Clear();
Console.Write("Please enter the file or folder name: ");
input = Console.ReadLine();
break;
case "2":
Console.Clear();
Console.Write("Please enter the output directory: ");
outdir = Console.ReadLine();
break;
case "3":
Console.Clear();
List<string> inputs = new List<string>();
inputs.Add(input);
InitHashSplit(inputs, outdir);
Console.Write("\nPress any key to continue...");
Console.ReadKey();
input = ""; outdir = "";
break;
}
}
}
/// <summary>
/// Show the text-based add and remove menu
/// </summary>
@@ -1562,6 +1624,33 @@ Make a selection:
}
}
/// <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>
private static void InitHashSplit(List<string> inputs, string outdir)
{
// Strip any quotations from the names
outdir = outdir.Replace("\"", "");
// Verify the input files
foreach (string input in inputs)
{
if (!File.Exists(input.Replace("\"", "")) && !Directory.Exists(input.Replace("\"", "")))
{
logger.Error(input + " is not a valid file or folder!");
Console.WriteLine();
Build.Help();
return;
}
}
// If so, run the program
HashSplit hs = new HashSplit(inputs, outdir, logger);
hs.Split();
}
/// <summary>
/// Wrap adding a new source to the database
/// </summary>