Merge SingleGame, part 3

This commit is contained in:
Matt Nadareski
2016-04-20 01:19:53 -07:00
parent 04fdd61134
commit 151ef235a5
4 changed files with 91 additions and 91 deletions

5
.gitignore vendored
View File

@@ -22,7 +22,4 @@
/SabreHelper/obj/Release /SabreHelper/obj/Release
/SabreToolsUI/obj /SabreToolsUI/obj
/SabreToolsUI/obj/Debug /SabreToolsUI/obj/Debug
/SabreToolsUI/obj/Release /SabreToolsUI/obj/Release
/SingleGame/obj
/SingleGame/obj/Debug
/SingleGame/obj/Release

View File

@@ -296,7 +296,7 @@ namespace SabreTools
{ {
foreach (string input in inputs) foreach (string input in inputs)
{ {
InitSingleGame(input, root, norename, disableForce); InitSingleGame(input, root, !norename, !disableForce);
} }
} }
@@ -646,7 +646,6 @@ Make a selection:
/// <remarks> /// <remarks>
/// At an unspecified future date, this will also include the following currently-separate programs: /// At an unspecified future date, this will also include the following currently-separate programs:
/// - DatSplit /// - DatSplit
/// - SingleGame
/// - MergeDAT /// - MergeDAT
/// - DATFromDir /// - DATFromDir
/// - DatToMiss /// - DatToMiss
@@ -664,7 +663,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 3) Trim all entries in DAT and optionally merge into a single game
B) Go back to the previous menu B) Go back to the previous menu
"); ");
Console.Write("Enter selection: "); Console.Write("Enter selection: ");
@@ -797,23 +796,73 @@ or 'b' to go back to the previous menu:
return; return;
} }
/// <summary>
/// Show the text-based SingleGame menu
/// </summary>
private static void SingleGameMenu() private static void SingleGameMenu()
{ {
string selection = "", input = "", root = "";
bool forceunzip = true, rename = true;
while (selection.ToLowerInvariant() != "b")
{
Console.Clear();
Build.Start("DATabase");
Console.WriteLine(@"SINGLE GAME MENU
===========================
Make a selection:
1) File or folder to process" + (input != "" ? ":\n\t" + input : "") + @"
2) Root folder for reference" + (root != "" ? ":\n\t" + root : "") + @"
3) " + (forceunzip ? "Remove 'forcepacking=\"unzip\"' from output" : "Add 'forcepacking=\"unzip\"' to output") + @"
4) " + (rename ? "Disable game renaming" : "Enable game renaming") + @"
5) Process the DAT
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 root folder name: ");
root = Console.ReadLine();
break;
case "3":
forceunzip = !forceunzip;
break;
case "4":
rename = !rename;
break;
case "5":
Console.Clear();
InitSingleGame(input, root, rename, forceunzip);
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
}
}
} }
/// <summary> /// <summary>
/// Wrap converting a DAT to single-game mode /// Wrap trimming and merging a single DAT
/// </summary> /// </summary>
/// <param name="input">Input file or folder to be converted</param> /// <param name="input">Input file or folder to be converted</param>
/// <param name="root">Root directory to base path lengths on</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="rename">True is games should not be renamed</param>
/// <param name="disableForce">True if forcepacking="unzip" should be omitted</param> /// <param name="force">True if forcepacking="unzip" should be included</param>
private static void InitSingleGame(string input, string root, bool norename, bool disableForce) private static void InitSingleGame(string input, string root, bool rename, bool force)
{ {
if (File.Exists(input) || Directory.Exists(input)) // Strip any quotations from the name
input = input.Replace("\"", "");
if (input != "" && File.Exists(input) || Directory.Exists(input))
{ {
SingleGame sg = new SingleGame(input, root, norename, disableForce); SingleGame sg = new SingleGame(input, root, rename, force, logger);
sg.Process(); sg.Process();
return; return;
} }

View File

@@ -9,75 +9,35 @@ namespace SabreTools
{ {
public class SingleGame public class SingleGame
{ {
// Instance variables
private static string _filename = ""; private static string _filename = "";
private static string _path = ""; private static string _path = "";
private static bool _rename = true; private static bool _rename;
private static bool _forceunpack = true; private static bool _forceunpack;
private static Logger logger; private static Logger _logger;
public static void Main(string[] args) /// <summary>
/// Create a new SingleGame object
/// </summary>
/// <param name="filename">Name of the file or folder to be processed</param>
/// <param name="path">Root path to use for trimming</param>
/// <param name="rename">True if games should be renamed into a uniform string, false otherwise</param>
/// <param name="forceunpack">True if forcepacking="unzip" should be set on the output, false otherwise</param>
/// <param name="logger">Logger object for console and file output</param>
public SingleGame(string filename, string path, bool rename, bool forceunpack, Logger logger)
{ {
Console.Clear(); _filename = filename;
_path = path;
// Credits take precidence over all _rename = rename;
if ((new List<string>(args)).Contains("--credits")) _forceunpack = forceunpack;
{ _logger = logger;
Build.Credits(); }
return;
}
if (args.Length == 0)
{
Build.Help();
return;
}
bool log = false;
foreach (string arg in args)
{
switch (arg)
{
case "-nr":
case "--no-rename":
_rename = false;
break;
case "-df":
case "--disable-force":
_forceunpack = false;
break;
case "-l":
case "--log":
log = true;
break;
default:
if (arg.StartsWith("-rd=") || arg.StartsWith("--root-dir="))
{
_path = arg.Split('=')[1];
}
else
{
_filename = arg;
}
break;
}
}
// 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
logger.ToFile = log;
/// <summary>
/// Trim and process the given DAT or folder of DATs
/// </summary>
public void Process()
{
_path = (_path == "" ? Environment.CurrentDirectory : _path); _path = (_path == "" ? Environment.CurrentDirectory : _path);
// Drag and drop means quotes; we don't want quotes // Drag and drop means quotes; we don't want quotes
@@ -89,7 +49,7 @@ namespace SabreTools
// If it's a single file, handle it as such // If it's a single file, handle it as such
if (!Directory.Exists(_filename) && File.Exists(_filename)) if (!Directory.Exists(_filename) && File.Exists(_filename))
{ {
logger.Log("File found: " + _filename); _logger.Log("File found: " + _filename);
ProcessDAT(_filename, _path, _rename); ProcessDAT(_filename, _path, _rename);
} }
// If it's a directory, loop through the files and see if any are DATs // If it's a directory, loop through the files and see if any are DATs
@@ -101,15 +61,15 @@ namespace SabreTools
_filename += Path.DirectorySeparatorChar; _filename += Path.DirectorySeparatorChar;
} }
logger.Log("Directory found: " + _filename); _logger.Log("Directory found: " + _filename);
foreach (string file in Directory.EnumerateFiles(_filename, "*", SearchOption.AllDirectories)) foreach (string file in Directory.EnumerateFiles(_filename, "*", SearchOption.AllDirectories))
{ {
logger.Log("File found: " + file); _logger.Log("File found: " + file);
ProcessDAT(file, _path, _rename); ProcessDAT(file, _path, _rename);
} }
} }
logger.Close(); _logger.Close();
} }
/// <summary> /// <summary>
@@ -120,7 +80,7 @@ namespace SabreTools
/// <param name="rename">True if roms are to be renamed</param> /// <param name="rename">True if roms are to be renamed</param>
private static void ProcessDAT(string filename, string path, bool rename) private static void ProcessDAT(string filename, string path, bool rename)
{ {
List<RomData> roms = RomManipulation.Parse(filename, 0, 0, logger); List<RomData> roms = RomManipulation.Parse(filename, 0, 0, _logger);
// Trim all file names according to the path that's set // Trim all file names according to the path that's set
List<RomData> outroms = new List<RomData>(); List<RomData> outroms = new List<RomData>();
@@ -149,7 +109,7 @@ namespace SabreTools
// Now write the file out accordingly // Now write the file out accordingly
Output.WriteToDat(Path.GetFileNameWithoutExtension(filename), Output.WriteToDat(Path.GetFileNameWithoutExtension(filename),
Path.GetFileNameWithoutExtension(filename), "", "", "", "", _forceunpack, !RomManipulation.IsXmlDat(filename), Path.GetDirectoryName(filename), outroms, logger); Path.GetFileNameWithoutExtension(filename), "", "", "", "", _forceunpack, !RomManipulation.IsXmlDat(filename), Path.GetDirectoryName(filename), outroms, _logger);
// Remove the original file if different and inform the user // Remove the original file if different and inform the user
if (Path.GetExtension(filename) != (RomManipulation.IsXmlDat(filename) ? ".xml" : ".dat")) if (Path.GetExtension(filename) != (RomManipulation.IsXmlDat(filename) ? ".xml" : ".dat"))
@@ -157,11 +117,11 @@ namespace SabreTools
try try
{ {
File.Delete(filename); File.Delete(filename);
logger.Log("Original file \"" + filename + "\" deleted"); _logger.Log("Original file \"" + filename + "\" deleted");
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Error(ex.ToString()); _logger.Error(ex.ToString());
} }
} }
} }

View File

@@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreToolsUI", "SabreToolsU
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatSplit", "DatSplit\DatSplit.csproj", "{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatSplit", "DatSplit\DatSplit.csproj", "{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleGame", "SingleGame\SingleGame.csproj", "{07EB8EA7-303A-407F-A881-060ED4595D7F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreHelper", "SabreHelper\SabreHelper.csproj", "{225A1AFD-0890-44E8-B779-7502665C23A5}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreHelper", "SabreHelper\SabreHelper.csproj", "{225A1AFD-0890-44E8-B779-7502665C23A5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATFromDir", "DATFromDir\DATFromDir.csproj", "{382B75D3-079E-49D5-A830-54DD6EB5A02D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DATFromDir", "DATFromDir\DATFromDir.csproj", "{382B75D3-079E-49D5-A830-54DD6EB5A02D}"
@@ -44,10 +42,6 @@ Global
{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Debug|Any CPU.Build.0 = Debug|Any CPU {9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Release|Any CPU.ActiveCfg = Release|Any CPU {9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Release|Any CPU.Build.0 = Release|Any CPU {9EB4738D-CAE7-420D-8A26-78A53CEA5E82}.Release|Any CPU.Build.0 = Release|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07EB8EA7-303A-407F-A881-060ED4595D7F}.Release|Any CPU.Build.0 = Release|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {225A1AFD-0890-44E8-B779-7502665C23A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Debug|Any CPU.Build.0 = Debug|Any CPU {225A1AFD-0890-44E8-B779-7502665C23A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{225A1AFD-0890-44E8-B779-7502665C23A5}.Release|Any CPU.ActiveCfg = Release|Any CPU {225A1AFD-0890-44E8-B779-7502665C23A5}.Release|Any CPU.ActiveCfg = Release|Any CPU