diff --git a/.gitignore b/.gitignore index b584f7ed..f808ff3f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,4 @@ /SabreHelper/obj/Release /SabreToolsUI/obj /SabreToolsUI/obj/Debug -/SabreToolsUI/obj/Release -/SingleGame/obj -/SingleGame/obj/Debug -/SingleGame/obj/Release \ No newline at end of file +/SabreToolsUI/obj/Release \ No newline at end of file diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 7c34602d..18d2d8cb 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -296,7 +296,7 @@ namespace SabreTools { foreach (string input in inputs) { - InitSingleGame(input, root, norename, disableForce); + InitSingleGame(input, root, !norename, !disableForce); } } @@ -646,7 +646,6 @@ Make a selection: /// /// At an unspecified future date, this will also include the following currently-separate programs: /// - DatSplit - /// - SingleGame /// - MergeDAT /// - DATFromDir /// - DatToMiss @@ -664,7 +663,7 @@ Make a selection: 1) Convert XML DAT to RV 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 "); Console.Write("Enter selection: "); @@ -797,23 +796,73 @@ or 'b' to go back to the previous menu: return; } + /// + /// Show the text-based SingleGame menu + /// 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; + } + } } /// - /// Wrap converting a DAT to single-game mode + /// Wrap trimming and merging a single DAT /// /// Input file or folder to be converted /// Root directory to base path lengths on - /// True is games should not be renamed - /// True if forcepacking="unzip" should be omitted - private static void InitSingleGame(string input, string root, bool norename, bool disableForce) + /// True is games should not be renamed + /// True if forcepacking="unzip" should be included + 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(); return; } diff --git a/DATabase/SingleGame.cs b/DATabase/SingleGame.cs index 66fa1b27..9cbc5ec5 100644 --- a/DATabase/SingleGame.cs +++ b/DATabase/SingleGame.cs @@ -9,75 +9,35 @@ namespace SabreTools { public class SingleGame { + // Instance variables private static string _filename = ""; private static string _path = ""; - private static bool _rename = true; - private static bool _forceunpack = true; - private static Logger logger; + private static bool _rename; + private static bool _forceunpack; + private static Logger _logger; - public static void Main(string[] args) + /// + /// Create a new SingleGame object + /// + /// Name of the file or folder to be processed + /// Root path to use for trimming + /// True if games should be renamed into a uniform string, false otherwise + /// True if forcepacking="unzip" should be set on the output, false otherwise + /// Logger object for console and file output + public SingleGame(string filename, string path, bool rename, bool forceunpack, Logger logger) { - Console.Clear(); - - // Credits take precidence over all - if ((new List(args)).Contains("--credits")) - { - 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; + _filename = filename; + _path = path; + _rename = rename; + _forceunpack = forceunpack; + _logger = logger; + } + /// + /// Trim and process the given DAT or folder of DATs + /// + public void Process() + { _path = (_path == "" ? Environment.CurrentDirectory : _path); // 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 (!Directory.Exists(_filename) && File.Exists(_filename)) { - logger.Log("File found: " + _filename); + _logger.Log("File found: " + _filename); ProcessDAT(_filename, _path, _rename); } // If it's a directory, loop through the files and see if any are DATs @@ -101,15 +61,15 @@ namespace SabreTools _filename += Path.DirectorySeparatorChar; } - logger.Log("Directory found: " + _filename); + _logger.Log("Directory found: " + _filename); foreach (string file in Directory.EnumerateFiles(_filename, "*", SearchOption.AllDirectories)) { - logger.Log("File found: " + file); + _logger.Log("File found: " + file); ProcessDAT(file, _path, _rename); } } - logger.Close(); + _logger.Close(); } /// @@ -120,7 +80,7 @@ namespace SabreTools /// True if roms are to be renamed private static void ProcessDAT(string filename, string path, bool rename) { - List roms = RomManipulation.Parse(filename, 0, 0, logger); + List roms = RomManipulation.Parse(filename, 0, 0, _logger); // Trim all file names according to the path that's set List outroms = new List(); @@ -149,7 +109,7 @@ namespace SabreTools // Now write the file out accordingly 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 if (Path.GetExtension(filename) != (RomManipulation.IsXmlDat(filename) ? ".xml" : ".dat")) @@ -157,11 +117,11 @@ namespace SabreTools try { File.Delete(filename); - logger.Log("Original file \"" + filename + "\" deleted"); + _logger.Log("Original file \"" + filename + "\" deleted"); } catch (Exception ex) { - logger.Error(ex.ToString()); + _logger.Error(ex.ToString()); } } } diff --git a/SabreTools.sln b/SabreTools.sln index 56153448..eebd4ae9 100644 --- a/SabreTools.sln +++ b/SabreTools.sln @@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SabreToolsUI", "SabreToolsU EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatSplit", "DatSplit\DatSplit.csproj", "{9EB4738D-CAE7-420D-8A26-78A53CEA5E82}" 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}" EndProject 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}.Release|Any CPU.ActiveCfg = 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.Build.0 = Debug|Any CPU {225A1AFD-0890-44E8-B779-7502665C23A5}.Release|Any CPU.ActiveCfg = Release|Any CPU