[RombaSharp] Help text and main method framework

This commit is contained in:
Matt Nadareski
2016-09-02 13:42:18 -07:00
parent 75889b7b26
commit 0cd008e1c7
5 changed files with 324 additions and 22 deletions

View File

@@ -51,30 +51,283 @@ namespace SabreTools
public static void Main(string[] args) 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 // If output is being redirected, don't allow clear screens
-only-needed=false only archive ROM files actually referenced by DAT files from the DAT index if (!Console.IsOutputRedirected)
build For each specified DAT file it creates the torrentzip files {
dbstats Prints db stats Console.Clear();
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 // Credits take precidence over all
lookup For each specified hash it looks up any available information if ((new List<string>(args)).Contains("--credits"))
memstats Prints memory stats {
miss For each specified DAT file it creates a miss file and a have file Build.Credits();
progress Shows progress of the currently running command logger.Close();
purge-backup Moves DAT index entries for orphaned DATs return;
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 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<string> inputs = new List<string>();
// 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;
} }
/// <summary> /// <summary>
/// Initialize the Romba application from XML config /// Initialize the Romba application from XML config
/// </summary> /// </summary>
private void InitializeConfiguration() private static void InitializeConfiguration()
{ {
// Get default values if they're not written // Get default values if they're not written
int workers = 4, int workers = 4,
@@ -316,7 +569,7 @@ namespace SabreTools
/// Populate or refresh the database information /// Populate or refresh the database information
/// </summary> /// </summary>
/// <remarks>Each hash has the following attributes: size, crc, md5, sha-1, dathash, existss</remarks> /// <remarks>Each hash has the following attributes: size, crc, md5, sha-1, dathash, existss</remarks>
private void RefreshDatabase() private static void RefreshDatabase()
{ {
// Make sure the db is set // Make sure the db is set
if (String.IsNullOrEmpty(_db)) if (String.IsNullOrEmpty(_db))

View File

@@ -73,6 +73,31 @@ namespace SabreTools.Helper
// Set the help text // Set the help text
switch (className) 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": case "SabreTools":
helptext.Add(Resources.Resources.SabreTools_Name + " - " + Resources.Resources.SabreTools_Desc); helptext.Add(Resources.Resources.SabreTools_Name + " - " + Resources.Resources.SabreTools_Desc);
helptext.Add(barrier); helptext.Add(barrier);

View File

@@ -61,7 +61,7 @@ namespace SabreTools.Helper.Resources {
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public static string Default_Desc { public static string Default_Desc {
get { get {
@@ -87,6 +87,24 @@ namespace SabreTools.Helper.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to C#port of the Romba rom management tool.
/// </summary>
public static string RombaSharp_Desc {
get {
return ResourceManager.GetString("RombaSharp_Desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to RombaSharp.
/// </summary>
public static string RombaSharp_Name {
get {
return ResourceManager.GetString("RombaSharp_Name", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Import, generate, manipulate DAT files. /// Looks up a localized string similar to Import, generate, manipulate DAT files.
/// </summary> /// </summary>
@@ -124,7 +142,7 @@ namespace SabreTools.Helper.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Convert files to TGZ DatTools. /// Looks up a localized string similar to Convert files to TGZ output.
/// </summary> /// </summary>
public static string TGZTest_Desc { public static string TGZTest_Desc {
get { get {

View File

@@ -126,6 +126,12 @@
<data name="Headerer_Name" xml:space="preserve"> <data name="Headerer_Name" xml:space="preserve">
<value>Headerer</value> <value>Headerer</value>
</data> </data>
<data name="RombaSharp_Desc" xml:space="preserve">
<value>C#port of the Romba rom management tool</value>
</data>
<data name="RombaSharp_Name" xml:space="preserve">
<value>RombaSharp</value>
</data>
<data name="SabreTools_Desc" xml:space="preserve"> <data name="SabreTools_Desc" xml:space="preserve">
<value>Import, generate, manipulate DAT files</value> <value>Import, generate, manipulate DAT files</value>
</data> </data>

View File

@@ -27,7 +27,7 @@ namespace SabreTools
private static string _datroot = "DATS"; private static string _datroot = "DATS";
private static string _outroot = "Output"; private static string _outroot = "Output";
private static string _dbSchema = "dats"; 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 string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
private static Logger _logger; private static Logger _logger;