Merge SingleGame, part 1

This commit is contained in:
Matt Nadareski
2016-04-20 00:50:31 -07:00
parent a0df635133
commit 99731d3c64
3 changed files with 103 additions and 32 deletions

View File

@@ -49,10 +49,11 @@ namespace SabreTools
} }
// Set all default values // Set all default values
bool help = false, bool help = false,
add = false, add = false,
convertRV = false, convertRV = false,
convertXml = false, convertXml = false,
disableForce = false,
generate = false, generate = false,
genall = false, genall = false,
import = false, import = false,
@@ -62,11 +63,13 @@ namespace SabreTools
norename = false, norename = false,
old = false, old = false,
rem = false, rem = false,
single = false,
skip = false; skip = false;
string manu = "", string manu = "",
outdir = "", outdir = "",
sources = "", sources = "",
systems = "", systems = "",
root = "",
url = ""; url = "";
List<string> inputs = new List<string>(); List<string> inputs = new List<string>();
@@ -92,6 +95,10 @@ namespace SabreTools
case "--convert-xml": case "--convert-xml":
convertXml = true; convertXml = true;
break; break;
case "-df":
case "--disable-force":
disableForce = false;
break;
case "-g": case "-g":
case "--generate": case "--generate":
generate = true; generate = true;
@@ -128,6 +135,10 @@ namespace SabreTools
case "--remove": case "--remove":
rem = true; rem = true;
break; break;
case "-sg":
case "--single-game":
single = true;
break;
case "--skip": case "--skip":
skip = true; skip = true;
break; break;
@@ -152,6 +163,10 @@ namespace SabreTools
{ {
systems = arg.Split('=')[1]; systems = arg.Split('=')[1];
} }
else if(arg.StartsWith("-rd=") || arg.StartsWith("--root-dir="))
{
root = arg.Split('=')[1];
}
else if (arg.StartsWith("url=") && url == "") else if (arg.StartsWith("url=") && url == "")
{ {
url = arg.Split('=')[1]; url = arg.Split('=')[1];
@@ -171,7 +186,15 @@ namespace SabreTools
} }
// If more than one switch is enabled or help is set, show the help screen // If more than one switch is enabled or help is set, show the help screen
if (help || !(import ^ generate ^ listsys ^ listsrc ^ genall ^ add ^ rem ^ convertRV ^ convertXml)) if (help || !(add ^ convertRV ^ convertXml ^ generate ^ genall ^ import ^ listsrc ^ listsys ^ rem ^ single))
{
Build.Help();
logger.Close();
return;
}
// If a switch that requires a filename is set and no file is, show the help screen
if (inputs.Count == 0 && (convertRV || convertXml || import || single))
{ {
Build.Help(); Build.Help();
logger.Close(); logger.Close();
@@ -268,6 +291,15 @@ namespace SabreTools
} }
} }
// Consolodate and trim DAT
else if (single)
{
foreach (string input in inputs)
{
InitSingleGame(input, root, norename, disableForce);
}
}
logger.Close(); logger.Close();
return; return;
} }
@@ -632,6 +664,7 @@ Make a selection:
1) Convert XML DAT to RV 1) Convert XML DAT to RV
2) Convert RV DAT to XML 2) Convert RV DAT to XML
3) Merge all entries into a single game and trim
B) Go back to the previous menu B) Go back to the previous menu
"); ");
Console.Write("Enter selection: "); Console.Write("Enter selection: ");
@@ -644,6 +677,9 @@ Make a selection:
case "2": case "2":
ConvertXMLMenu(); ConvertXMLMenu();
break; break;
case "3":
SingleGameMenu();
break;
} }
} }
} }
@@ -761,6 +797,28 @@ or 'b' to go back to the previous menu:
return; return;
} }
private static void SingleGameMenu()
{
}
/// <summary>
/// Wrap converting a DAT to single-game mode
/// </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="norename">True is games should not be renamed</param>
/// <param name="disableForce">True if forcepacking="unzip" should be omitted</param>
private static void InitSingleGame(string input, string root, bool norename, bool disableForce)
{
if (File.Exists(input) || Directory.Exists(input))
{
SingleGame sg = new SingleGame(input, root, norename, disableForce);
sg.Process();
return;
}
}
/// <summary> /// <summary>
/// List sources in the database /// List sources in the database
/// </summary> /// </summary>

View File

@@ -70,33 +70,37 @@ namespace SabreTools.Helper
Console.Write(@" Console.Write(@"
DATabase - Import and Generate DAT files DATabase - Import and Generate DAT files
----------------------------------------- -----------------------------------------
Usage: DATabase [option] [filename|dirname] <filename|dirname> ... Usage: DATabase [option] <input=>[filename|dirname] <input=><filename|dirname> ...
Options: Options:
-?, -h, --help Show this help -?, -h, --help Show this help
-a, --add Add a new system or source to the database -a, --add Add a new system or source to the database
manu=mn Manufacturer name (system only) manu= Manufacturer name (system only)
system=sy System name (system only) system= System name (system only)
source=sr Source name (source only) source= Source name (source only)
url=ul URL (source only) url= URL (source only)
-cr, --convert-rv Convert an XML DAT to RV -cr, --convert-rv Convert an XML DAT to RV
out= Output directory
-cx, --convert-xml Convert a RV DAT to XML -cx, --convert-xml Convert a RV DAT to XML
Both converters require a filename or folder out= Output directory
-g, --generate Start tool in generate mode -g, --generate Start tool in generate mode
-ga, --generate-all Start tool in generate all mode -ga, --generate-all Start tool in generate all mode
system=sy,... List of system IDs system= Comma-separated list of system IDs
source=so,... List of source IDs source= Comma-separated list of source IDs
out=dir Output directory out= Output directoryComma-separated list
-nr, --no-rename Don't auto-rename games -nr, --no-rename Don't auto-rename games
-old, --romvault Produce a DAT in RV format -old, --romvault Produce a DAT in RV format
-i, --import Start tool in import mode -i, --import Start tool in import mode
A filename or folder is required to run
-l, --log Enable logging of program output -l, --log Enable logging of program output
-lso, --list-sources List all sources (id <= name) -lso, --list-sources List all sources (id <= name)
-lsy, --list-systems List all systems (id <= name) -lsy, --list-systems List all systems (id <= name)
-r, --remove Remove a system or source from the database -r, --remove Remove a system or source from the database
system=sy System ID system= System ID
source=so Source ID source= Source ID
-sg, --single-game Consolidate DAT into a single game and trim entries
-rd=, --root-dir= Set the directory name for path size
-nr, --no-rename Disable single-game mode
-df, --disable-force Disable forceunzipping
Filenames and directories can't start with '-', 'system=', or 'source=' Filenames and directories can't start with '-', 'system=', or 'source='
unless prefixed by 'input=' unless prefixed by 'input='
@@ -124,10 +128,10 @@ Options:
Usage: SingleGame.exe [option] [filename|dirname] Usage: SingleGame.exe [option] [filename|dirname]
Options: Options:
-rd= Set the directory name for path size -rd=, --root-dir= Set the directory name for path size
-l, --log Enable logging to file -l, --log Enable logging to file
-n Disable single-game mode -nr, --no-rename Disable single-game mode
-z Disable forceunzipping -df, --disable-force Disable forceunzipping
"); ");
break; break;
case "DATFromDir": case "DATFromDir":

View File

@@ -32,29 +32,25 @@ namespace SabreTools
return; return;
} }
logger = new Logger(false, "singlegame.log"); bool log = false;
logger.Start();
// Output the title
Build.Start("SingleGame");
bool tofile = false;
foreach (string arg in args) foreach (string arg in args)
{ {
switch (arg) switch (arg)
{ {
case "-n": case "-nr":
case "--no-rename":
_rename = false; _rename = false;
break; break;
case "-z": case "-df":
case "--disable-force":
_forceunpack = false; _forceunpack = false;
break; break;
case "-l": case "-l":
case "--log": case "--log":
tofile = true; log = true;
break; break;
default: default:
if (arg.StartsWith("-rd=")) if (arg.StartsWith("-rd=") || arg.StartsWith("--root-dir="))
{ {
_path = arg.Split('=')[1]; _path = arg.Split('=')[1];
} }
@@ -66,8 +62,21 @@ namespace SabreTools
} }
} }
// If the filename is blank, show the help and exit
if (_filename == "")
{
Build.Help();
return;
}
logger = new Logger(false, "singlegame.log");
logger.Start();
// Output the title
Build.Start("SingleGame");
// Set the possibly new value for logger // Set the possibly new value for logger
logger.ToFile = tofile; logger.ToFile = log;
_path = (_path == "" ? Environment.CurrentDirectory : _path); _path = (_path == "" ? Environment.CurrentDirectory : _path);