Merge DatSplit, part 2

This commit is contained in:
Matt Nadareski
2016-04-20 11:27:17 -07:00
parent 9ec79c4bef
commit f07364d527
3 changed files with 114 additions and 50 deletions

View File

@@ -54,6 +54,7 @@ namespace SabreTools
convertRV = false,
convertXml = false,
disableForce = false,
extsplit = false,
generate = false,
genall = false,
import = false,
@@ -65,7 +66,9 @@ namespace SabreTools
rem = false,
trim = false,
skip = false;
string manu = "",
string exta = "",
extb = "",
manu = "",
outdir = "",
sources = "",
systems = "",
@@ -97,7 +100,11 @@ namespace SabreTools
break;
case "-df":
case "--disable-force":
disableForce = false;
disableForce = true;
break;
case "-es":
case "--ext-split":
extsplit = true;
break;
case "-g":
case "--generate":
@@ -143,7 +150,15 @@ namespace SabreTools
trim = true;
break;
default:
if (arg.StartsWith("input="))
if (arg.StartsWith("exta="))
{
exta = arg.Split('=')[1];
}
else if (arg.StartsWith("extb"))
{
extb = arg.Split('=')[1];
}
else if (arg.StartsWith("input="))
{
inputs.Add(arg.Split('=')[1]);
}
@@ -186,7 +201,7 @@ namespace SabreTools
}
// If more than one switch is enabled or help is set, show the help screen
if (help || !(add ^ convertRV ^ convertXml ^ generate ^ genall ^ import ^ listsrc ^ listsys ^ rem ^ trim))
if (help || !(add ^ convertRV ^ convertXml ^ extsplit ^ generate ^ genall ^ import ^ listsrc ^ listsys ^ rem ^ trim))
{
Build.Help();
logger.Close();
@@ -194,7 +209,7 @@ namespace SabreTools
}
// If a switch that requires a filename is set and no file is, show the help screen
if (inputs.Count == 0 && (convertRV || convertXml || import || trim))
if (inputs.Count == 0 && (convertRV || convertXml || extsplit || import || trim))
{
Build.Help();
logger.Close();
@@ -667,6 +682,7 @@ Make a selection:
1) Convert XML DAT to RV
2) Convert RV DAT to XML
3) Trim all entries in DAT and merge into a single game
4) Split DAT using 2 extensions
B) Go back to the previous menu
");
Console.Write("Enter selection: ");
@@ -682,6 +698,9 @@ Make a selection:
case "3":
TrimMergeMenu();
break;
case "4":
ExtSplitMenu();
break;
}
}
}
@@ -871,6 +890,81 @@ Make a selection:
}
}
/// <summary>
/// Show the text-based ExtSplit menu
/// </summary>
private static void ExtSplitMenu()
{
string selection = "", input = "", exta = "", extb = "", outdir = "";
while (selection.ToLowerInvariant() != "b")
{
Console.Clear();
Build.Start("DATabase");
Console.WriteLine(@"EXTENSION SPLIT MENU
===========================
Make a selection:
1) File to split" + (input != "" ? ":\n\t" + input : "") + @"
2) First file extension" + (exta != "" ? ":\t" + exta : "") + @"
3) Second file extension" + (extb != "" ? ":\t" + extb : "") + @"
4) Output directory" + (outdir != "" ? ":\n\t" + outdir : "") + @"
5) 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 name: ");
input = Console.ReadLine();
break;
case "2":
Console.Clear();
Console.Write("Please enter the first extension: ");
exta = Console.ReadLine();
break;
case "3":
Console.Clear();
Console.Write("Please enter the second extension: ");
extb = Console.ReadLine();
break;
case "4":
Console.Clear();
Console.Write("Please enter the output directory: ");
exta = Console.ReadLine();
break;
case "5":
Console.Clear();
InitTrimMerge(input, root, rename, forceunzip);
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
}
}
}
/// <summary>
/// Wrap trimming and merging a single DAT
/// </summary>
/// <param name="input">Input file or folder to be converted</param>
/// <param name="root">Root directory to base path lengths on</param>
/// <param name="rename">True is games should not be renamed</param>
/// <param name="force">True if forcepacking="unzip" should be included</param>
private static void InitTrimMerge(string input, string root, bool rename, bool force)
{
// Strip any quotations from the name
input = input.Replace("\"", "");
if (input != "" && (File.Exists(input) || Directory.Exists(input)))
{
TrimMerge sg = new TrimMerge(input, root, rename, force, logger);
sg.Process();
return;
}
}
/// <summary>
/// List sources in the database
/// </summary>

View File

@@ -9,9 +9,10 @@ namespace SabreTools
public class DatSplit
{
// Instance variables
private static string _extA;
private static string _extB;
private static string _filename;
private string _extA;
private string _extB;
private string _filename;
private string _outdir;
private static Logger _logger;
/// <summary>
@@ -21,50 +22,15 @@ namespace SabreTools
/// <param name="extA">First extension to split on</param>
/// <param name="extB">Second extension to split on</param>
/// <param name="logger">Logger object for console and file writing</param>
public DatSplit(string filename, string extA, string extB, Logger logger)
public DatSplit(string filename, string extA, string extB, string outdir, Logger logger)
{
_filename = filename.Replace("\"", "");
_extA = (extA.StartsWith(".") ? extA : "." + extA).ToUpperInvariant();
_extB = (extB.StartsWith(".") ? extB : "." + extB).ToUpperInvariant();
_outdir = outdir.Replace("\"", "");
_logger = logger;
}
public static void Main(string[] args)
{
Console.Clear();
// Credits take precidence over all
if ((new List<string>(args)).Contains("--credits"))
{
Build.Credits();
return;
}
// If we don't have arguments, show help
if (args.Length == 0 && args.Length != 3)
{
Build.Help();
return;
}
Logger logger = new Logger(false, "datsplit.log");
logger.Start();
// Output the title
Build.Start("DatSplit");
// Set needed variables
_filename = args[0];
_extA = (args[1].StartsWith(".") ? args[1] : "." + args[1]).ToUpperInvariant();
_extB = (args[2].StartsWith(".") ? args[2] : "." + args[2]).ToUpperInvariant();
// Split the DAT
DatSplit ds = new DatSplit(_filename, _extA, _extB, logger);
ds.Split();
logger.Close();
}
/// <summary>
/// Split a DAT based on filtering by 2 extensions
/// </summary>
@@ -78,6 +44,12 @@ namespace SabreTools
return false;
}
// If the output directory doesn't exist, create it
if (!Directory.Exists(_outdir))
{
Directory.CreateDirectory(_outdir);
}
List<RomData> romsA = new List<RomData>();
List<RomData> romsB = new List<RomData>();

View File

@@ -82,6 +82,9 @@ Options:
out= Output directory
-cx, --convert-xml Convert a RV DAT to XML
out= Output directory
-es, --ext-split Split a DAT by two file extensions
exta= First extension to split by
extb= Second extension to split by
-g, --generate Start tool in generate mode
-ga, --generate-all Start tool in generate all mode
system= Comma-separated list of system IDs
@@ -105,11 +108,6 @@ Filenames and directories can't start with a reserved string
unless prefixed by 'input='
");
break;
case "DatSplit":
Console.WriteLine(@"DatSplit - Split DAT files by file extension
-----------------------------------------
Usage: DatSplit.exe <filename> <ext> <ext>");
break;
case "Headerer":
Console.WriteLine(@"Headerer - Remove and restore rom headers
-----------------------------------------