diff --git a/RombaSharp/RombaSharp.cs b/RombaSharp/RombaSharp.cs index 99f69841..9b17d875 100644 --- a/RombaSharp/RombaSharp.cs +++ b/RombaSharp/RombaSharp.cs @@ -51,30 +51,283 @@ namespace SabreTools public static void Main(string[] args) { - /* Commands to implement + // Perform initial setup and verification + Logger logger = new Logger(true, "romba.log"); + logger.Start(); - archive Adds ROM files from the specified directories to the ROM archive - -only-needed=false only archive ROM files actually referenced by DAT files from the DAT index - build For each specified DAT file it creates the torrentzip files - dbstats Prints db stats - diffdat Creates a DAT file with those entries that are in -new DAT - dir2dat Creates a DAT file for the specified input directory and saves it to -out filename - fixdat For each specified DAT file it creates a fix DAT - lookup For each specified hash it looks up any available information - memstats Prints memory stats - miss For each specified DAT file it creates a miss file and a have file - progress Shows progress of the currently running command - purge-backup Moves DAT index entries for orphaned DATs - purge-delete Deletes DAT index entries for orphaned DATs - refresh-dats Refreshes the DAT index fro mthe files in the DAT master directory tree - shutdown Gracefully shuts down server - */ + // If output is being redirected, don't allow clear screens + if (!Console.IsOutputRedirected) + { + Console.Clear(); + } + + // Credits take precidence over all + if ((new List(args)).Contains("--credits")) + { + Build.Credits(); + logger.Close(); + return; + } + + // If there's no arguments, show help + if (args.Length == 0) + { + Build.Help(); + logger.Close(); + return; + } + + // Set all default values + bool help = false, + archive = false, + build = false, + dbstats = false, + diffdat = false, + dir2dat = false, + fixdat = false, + lookup = false, + memstats = false, + miss = false, + onlyNeeded = false, + progress = false, + purgeBackup = false, + purgeDelete = false, + refreshDats = false, + rombaSharp = true, + shutdown = false; + string newdat ="", + outdat = ""; + List inputs = new List(); + + // Determine which switches are enabled (with values if necessary) + foreach (string arg in args) + { + switch (arg) + { + case "-?": + case "-h": + case "--help": + help = true; + break; + case "archive": + archive = true; + break; + case "build": + build = true; + break; + case "dbstats": + dbstats = true; + break; + case "diffdat": + diffdat = true; + break; + case "dir2dat": + dir2dat = true; + break; + case "fixdat": + fixdat = true; + break; + case "lookup": + lookup = true; + break; + case "memstats": + memstats = true; + break; + case "miss": + miss = true; + break; + case "purge-backup": + purgeBackup = true; + break; + case "purge-delete": + purgeDelete = true; + break; + case "progress": + progress = true; + break; + case "refresh-dats": + refreshDats = true; + break; + case "shutdown": + shutdown = true; + break; + default: + string temparg = arg.Replace("\"", "").Replace("file://", ""); + + if (temparg.StartsWith("-new=") || temparg.StartsWith("--new=")) + { + newdat = temparg.Split('=')[1]; + } + else if (temparg.StartsWith("-only-needed=")) + { + string temp = temparg.Split('=')[1].ToLowerInvariant(); + switch (temp) + { + case "true": + onlyNeeded = true; + break; + case "false": + onlyNeeded = false; + break; + default: + logger.Error("Invalid value detected: " + temp); + Console.WriteLine(); + Build.Help(); + Console.WriteLine(); + logger.Error("Invalid value detected: " + temp); + logger.Close(); + return; + } + } + else if (temparg.StartsWith("-out=") || temparg.StartsWith("--out=")) + { + outdat = temparg.Split('=')[1]; + } + else if (File.Exists(temparg) || Directory.Exists(temparg)) + { + inputs.Add(temparg); + } + else + { + logger.Error("Invalid input detected: " + arg); + Console.WriteLine(); + Build.Help(); + Console.WriteLine(); + logger.Error("Invalid input detected: " + arg); + logger.Close(); + return; + } + break; + } + } + + // If help is set, show the help screen + if (help) + { + Build.Help(); + logger.Close(); + return; + } + + // If more than one switch is enabled, show the help screen + if (!(archive ^ build ^ dbstats ^ diffdat ^ dir2dat ^ fixdat ^ lookup ^ memstats ^ miss ^ + progress ^ purgeBackup ^ purgeDelete ^ refreshDats ^ shutdown)) + { + logger.Error("Only one feature switch is allowed at a time"); + 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 && (archive || build || dir2dat || fixdat || lookup || miss)) + { + logger.Error("This feature requires at least one input"); + Build.Help(); + logger.Close(); + return; + } + + // Now take care of each mode in succesion + + // Adds ROM files from the specified directories to the ROM archive + if (archive) + { + logger.User("This feature is not yet implemented!"); + } + + // For each specified DAT file it creates the torrentzip files + else if (build) + { + logger.User("This feature is not yet implemented!"); + } + + // Prints db stats + else if (dbstats) + { + logger.User("This feature is not yet implemented!"); + } + + // Creates a DAT file with those entries that are in new DAT + else if (diffdat) + { + logger.User("This feature is not yet implemented!"); + } + + // Creates a DAT file for the specified input directory + else if (dir2dat) + { + + } + + // For each specified DAT file it creates a fix DAT + else if (fixdat) + { + logger.User("This feature is not yet implemented!"); + } + + // For each specified hash it looks up any available information + else if (lookup) + { + logger.User("This feature is not yet implemented!"); + } + + // Prints memory stats + else if (memstats) + { + logger.User("This feature is not yet implemented!"); + } + + // For each specified DAT file it creates a miss file and a have file + else if (miss) + { + logger.User("This feature is not yet implemented!"); + } + + // Shows progress of the currently running command + else if (progress) + { + logger.User("This feature is not yet implemented!"); + } + + // Moves DAT index entries for orphaned DATs + else if (purgeBackup) + { + logger.User("This feature is not yet implemented!"); + } + + // Deletes DAT index entries for orphaned DATs + else if (purgeDelete) + { + logger.User("This feature is not yet implemented!"); + } + + // Refreshes the DAT index from the files in the DAT master directory tree + else if (refreshDats) + { + RefreshDatabase(); + } + + // Gracefully shuts down server + else if (shutdown) + { + logger.User("This feature is not yet implemented!"); + } + + // If nothing is set, show the help + else + { + Build.Help(); + } + + logger.Close(); + return; } /// /// Initialize the Romba application from XML config /// - private void InitializeConfiguration() + private static void InitializeConfiguration() { // Get default values if they're not written int workers = 4, @@ -316,7 +569,7 @@ namespace SabreTools /// Populate or refresh the database information /// /// Each hash has the following attributes: size, crc, md5, sha-1, dathash, existss - private void RefreshDatabase() + private static void RefreshDatabase() { // Make sure the db is set if (String.IsNullOrEmpty(_db)) diff --git a/SabreTools.Helper/Data/Build.cs b/SabreTools.Helper/Data/Build.cs index efd13fb3..66d5bfbd 100644 --- a/SabreTools.Helper/Data/Build.cs +++ b/SabreTools.Helper/Data/Build.cs @@ -73,6 +73,31 @@ namespace SabreTools.Helper // Set the help text switch (className) { + case "RombaSharp": + helptext.Add(Resources.Resources.RombaSharp_Name + " - " + Resources.Resources.RombaSharp_Desc); + helptext.Add(barrier); + helptext.Add(Resources.Resources.Usage + ": " + Resources.Resources.RombaSharp_Name + " [option] [filename|dirname] ..."); + helptext.Add(""); + helptext.Add("Options:"); + helptext.Add(" -?, -h, --help Show this help"); + helptext.Add(" archive Adds ROM files from the specified directories to the ROM archive"); + helptext.Add(" -only-needed=(true|false) only archive ROM files actually referenced by DAT files from the DAT index"); + helptext.Add(" build For each specified DAT file it creates the torrentzip files"); + helptext.Add(" dbstats Prints db stats"); + helptext.Add(" diffdat Creates a DAT file with those entries that are in a new DAT"); + helptext.Add(" -new= DAT to compare to"); + helptext.Add(" dir2dat Creates a DAT file for the specified input directory"); + helptext.Add(" -out= Filename to save out to"); + helptext.Add(" fixdat For each specified DAT file it creates a fix DAT"); + helptext.Add(" lookup For each specified hash it looks up any available information"); + helptext.Add(" memstats Prints memory stats"); + helptext.Add(" miss For each specified DAT file it creates a miss file and a have file"); + helptext.Add(" progress Shows progress of the currently running command"); + helptext.Add(" purge-backup Moves DAT index entries for orphaned DATs"); + helptext.Add(" purge-delete Deletes DAT index entries for orphaned DATs"); + helptext.Add(" refresh-dats Refreshes the DAT index from the files in the DAT master directory tree"); + helptext.Add(" shutdown Gracefully shuts down server"); + break; case "SabreTools": helptext.Add(Resources.Resources.SabreTools_Name + " - " + Resources.Resources.SabreTools_Desc); helptext.Add(barrier); diff --git a/SabreTools.Helper/Resources/Resources.Designer.cs b/SabreTools.Helper/Resources/Resources.Designer.cs index dd67ff3e..5fc5cce2 100644 --- a/SabreTools.Helper/Resources/Resources.Designer.cs +++ b/SabreTools.Helper/Resources/Resources.Designer.cs @@ -61,7 +61,7 @@ namespace SabreTools.Helper.Resources { } /// - /// Looks up a localized string similar to This is the default help DatTools. + /// Looks up a localized string similar to This is the default help output. /// public static string Default_Desc { get { @@ -87,6 +87,24 @@ namespace SabreTools.Helper.Resources { } } + /// + /// Looks up a localized string similar to C#port of the Romba rom management tool. + /// + public static string RombaSharp_Desc { + get { + return ResourceManager.GetString("RombaSharp_Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to RombaSharp. + /// + public static string RombaSharp_Name { + get { + return ResourceManager.GetString("RombaSharp_Name", resourceCulture); + } + } + /// /// Looks up a localized string similar to Import, generate, manipulate DAT files. /// @@ -124,7 +142,7 @@ namespace SabreTools.Helper.Resources { } /// - /// Looks up a localized string similar to Convert files to TGZ DatTools. + /// Looks up a localized string similar to Convert files to TGZ output. /// public static string TGZTest_Desc { get { diff --git a/SabreTools.Helper/Resources/Resources.resx b/SabreTools.Helper/Resources/Resources.resx index 99e5eb42..c572bdc0 100644 --- a/SabreTools.Helper/Resources/Resources.resx +++ b/SabreTools.Helper/Resources/Resources.resx @@ -126,6 +126,12 @@ Headerer + + C#port of the Romba rom management tool + + + RombaSharp + Import, generate, manipulate DAT files diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index ab084438..a4db0cd9 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -27,7 +27,7 @@ namespace SabreTools private static string _datroot = "DATS"; private static string _outroot = "Output"; private static string _dbSchema = "dats"; - private static string _dbName = "dats.sqlite"; + private static string _dbName = "dats.sqlite"; private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;"; private static Logger _logger;