[RombaSharp, SabreTools] Better switch statements

This commit is contained in:
Matt Nadareski
2017-12-05 19:09:32 -08:00
parent 1025dd558e
commit 2dfb3f6e69
2 changed files with 223 additions and 291 deletions

View File

@@ -174,65 +174,6 @@ namespace RombaSharp
// Check all of the flag names and translate to arguments // Check all of the flag names and translate to arguments
switch (feat.Key) switch (feat.Key)
{ {
// Top-level features
case "Help":
// No-op as this should be caught
break;
case "Archive":
archive = true;
break;
case "Build":
build = true;
break;
case "Stats":
dbstats = true;
break;
case "Rescan Depots":
depotRescan = true;
break;
case "Diffdat":
diffdat = true;
break;
case "Dir2Dat":
dir2dat = true;
break;
case "Export":
export = true;
break;
case "Fixdat":
fixdat = true;
break;
case "Import":
import = true;
break;
case "Lookup":
lookup = true;
break;
case "Memstats":
memstats = true;
break;
case "Merge":
merge = true;
break;
case "Miss":
miss = true;
break;
case "Purge Backup":
purgeBackup = true;
break;
case "Purge Delete":
purgeDelete = true;
break;
case "Refresh DATs":
refreshDats = true;
break;
case "Progress":
progress = true;
break;
case "Shutdown":
shutdown = true;
break;
// User flags // User flags
case "copy": case "copy":
copy = true; copy = true;
@@ -257,133 +198,143 @@ namespace RombaSharp
} }
} }
// If a switch that requires a filename is set and no file is, show the help screen // Now take care of each mode in succesion
if (inputs.Count == 0 && (archive || build || depotRescan || dir2dat || fixdat || switch(feature)
import || lookup || merge || miss)) {
case "Help":
// No-op as this should be caught
break;
// Adds ROM files from the specified directories to the ROM archive
case "Archive":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input"); Globals.Logger.Error("This feature requires at least one input");
_help.OutputGenericHelp(); _help.OutputIndividualFeature(feature);
Globals.Logger.Close(); break;
return;
} }
// Now take care of each mode in succesion
// Adds ROM files from the specified directories to the ROM archive
if (archive)
{
InitArchive(inputs, onlyNeeded); InitArchive(inputs, onlyNeeded);
} break;
// For each specified DAT file it creates the torrentzip files // For each specified DAT file it creates the torrentzip files
else if (build) case "Build":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitBuild(inputs, copy); InitBuild(inputs, copy);
} break;
// Prints db stats // Prints db stats
else if (dbstats) case "Stats":
{
DisplayDBStats(); DisplayDBStats();
} break;
// Rescan a specific depot // Rescan a specific depot
else if (depotRescan) case "Rescan Depots":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
foreach (string input in inputs) foreach (string input in inputs)
{ {
Rescan(input); Rescan(input);
} }
} break;
// Creates a DAT file with those entries that are in new DAT // Creates a DAT file with those entries that are in new DAT
else if (diffdat) case "Diffdat":
{
InitDiffDat(newdat); InitDiffDat(newdat);
} break;
// Creates a DAT file for the specified input directory // Creates a DAT file for the specified input directory
else if (dir2dat) case "Dir2Dat":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitDir2Dat(inputs); InitDir2Dat(inputs);
} break;
// Export the database to file // Export the database to file
else if (export) case "Export":
{
ExportDatabase(); ExportDatabase();
} break;
// For each specified DAT file it creates a fix DAT // For each specified DAT file it creates a fix DAT
else if (fixdat) case "Fixdat":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitFixdat(inputs); InitFixdat(inputs);
} break;
// Import a CSV into the database // Import a CSV into the database
else if (import) case "Import":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitImport(inputs); InitImport(inputs);
} break;
// For each specified hash it looks up any available information // For each specified hash it looks up any available information
else if (lookup) case "Lookup":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitLookup(inputs); InitLookup(inputs);
} break;
// Prints memory stats // Prints memory stats
else if (memstats) case "Memstats":
{
DisplayMemoryStats(); DisplayMemoryStats();
} break;
// Merges depots // Merges depots
else if (merge) case "Merge":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitMerge(inputs, depotPath, onlyNeeded); InitMerge(inputs, depotPath, onlyNeeded);
} break;
// For each specified DAT file it creates a miss file and a have file // For each specified DAT file it creates a miss file and a have file
else if (miss) case "Miss":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitMiss(inputs); InitMiss(inputs);
} break;
// Shows progress of the currently running command
else if (progress)
{
Globals.Logger.User("This feature is not used in RombaSharp: progress");
}
// Moves DAT index entries for orphaned DATs // Moves DAT index entries for orphaned DATs
else if (purgeBackup) case "Purge Backup":
{
PurgeBackup(logOnly); PurgeBackup(logOnly);
} break;
// Deletes DAT index entries for orphaned DATs // Deletes DAT index entries for orphaned DATs
else if (purgeDelete) case "Purge Delete":
{
PurgeDelete(logOnly); PurgeDelete(logOnly);
} break;
// Refreshes the DAT index from the files in the DAT master directory tree // Refreshes the DAT index from the files in the DAT master directory tree
else if (refreshDats) case "Refresh DATs":
{
RefreshDatabase(); RefreshDatabase();
} break;
// Shows progress of the currently running command
// Gracefully shuts down server case "Progress":
else if (shutdown) Globals.Logger.User("This feature is not used in RombaSharp: progress");
{ break;
case "Shutdown":
Globals.Logger.User("This feature is not used in RombaSharp: shutdown"); Globals.Logger.User("This feature is not used in RombaSharp: shutdown");
} break;
default:
// If nothing is set, show the help
else
{
_help.OutputGenericHelp(); _help.OutputGenericHelp();
break;
} }
Globals.Logger.Close(); Globals.Logger.Close();

View File

@@ -71,16 +71,6 @@ namespace SabreTools
return; return;
} }
// Feature flags
bool datFromDir = false,
extract = false,
restore = false,
sort = false,
split = false,
stats = false,
update = false,
verify = false;
// User flags // User flags
bool addBlankFilesForEmptyFolder = false, bool addBlankFilesForEmptyFolder = false,
addFileDates = false, addFileDates = false,
@@ -187,38 +177,6 @@ namespace SabreTools
// Check all of the flag names and translate to arguments // Check all of the flag names and translate to arguments
switch (feat.Key) switch (feat.Key)
{ {
// Top-level features
case "Help":
// No-op as this should be caught
break;
case "DATFromDir":
datFromDir = true;
break;
case "Extract":
extract = true;
break;
case "Restore":
restore = true;
break;
case "Script":
// No-op as this should be caught
break;
case "Split":
split = true;
break;
case "Sort":
sort = true;
break;
case "Stats":
stats = true;
break;
case "Update":
update = true;
break;
case "Verify":
verify = true;
break;
// User flags // User flags
case "add-blank": case "add-blank":
addBlankFilesForEmptyFolder = true; addBlankFilesForEmptyFolder = true;
@@ -714,73 +672,96 @@ namespace SabreTools
} }
} }
// If a switch that requires a filename is set and no file is, show the help screen // Now take care of each mode in succesion
if (inputs.Count == 0 switch (feature)
&& (datFromDir || extract || restore || split || stats || update || verify)) {
case "Help":
// No-op as this should be caught
break;
// Create a DAT from a directory or set of directories
case "DATFromDir":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input"); Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature); _help.OutputIndividualFeature(feature);
Globals.Logger.Close(); break;
return;
} }
// Now take care of each mode in succesion
// Create a DAT from a directory or set of directories
if (datFromDir)
{
InitDatFromDir(inputs, datHeader, omitFromScan, removeDateFromAutomaticName, archivesAsFiles, chdsAsFiles, InitDatFromDir(inputs, datHeader, omitFromScan, removeDateFromAutomaticName, archivesAsFiles, chdsAsFiles,
skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, outDir, copyFiles); skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, outDir, copyFiles);
} break;
// If we're in header extract and remove mode // If we're in header extract and remove mode
else if (extract) case "Extract":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitExtractRemoveHeader(inputs, outDir, nostore); InitExtractRemoveHeader(inputs, outDir, nostore);
} break;
// If we're in header restore mode // If we're in header restore mode
else if (restore) case "Restore":
if (inputs.Count == 0)
{ {
InitReplaceHeader(inputs, outDir); Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
} }
InitReplaceHeader(inputs, outDir);
break;
case "Script":
// No-op as this should be caught
break;
// If we're using the sorter // If we're using the sorter
else if (sort) case "Sort":
{
InitSort(datfiles, inputs, outDir, depot, quickScan, addFileDates, delete, inverse, InitSort(datfiles, inputs, outDir, depot, quickScan, addFileDates, delete, inverse,
outputFormat, datHeader.Romba, sevenzip, gz, rar, zip, updateDat, datHeader.Header, splitType, chdsAsFiles); outputFormat, datHeader.Romba, sevenzip, gz, rar, zip, updateDat, datHeader.Header, splitType, chdsAsFiles);
} break;
// Split a DAT by the split type // Split a DAT by the split type
else if (split) case "Split":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitSplit(inputs, outDir, inplace, datHeader.DatFormat, splittingMode, exta, extb, shortname, basedat); InitSplit(inputs, outDir, inplace, datHeader.DatFormat, splittingMode, exta, extb, shortname, basedat);
} break;
// Get statistics on input files // Get statistics on input files
else if (stats) case "Stats":
if (inputs.Count == 0)
{ {
InitStats(inputs, datHeader.FileName, outDir, filter.Single, showBaddumpColumn, showNodumpColumn, statDatFormat); Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
} }
InitStats(inputs, datHeader.FileName, outDir, filter.Single, showBaddumpColumn, showNodumpColumn, statDatFormat);
break;
// Convert, update, merge, diff, and filter a DAT or folder of DATs // Convert, update, merge, diff, and filter a DAT or folder of DATs
else if (update) case "Update":
if (inputs.Count == 0)
{ {
Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
}
InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skip, removeDateFromAutomaticName, filter, InitUpdate(inputs, basePaths, datHeader, updateMode, inplace, skip, removeDateFromAutomaticName, filter,
splitType, outDir, cleanGameNames, removeUnicode, descAsName); splitType, outDir, cleanGameNames, removeUnicode, descAsName);
} break;
// If we're using the verifier // If we're using the verifier
else if (verify) case "Verify":
if (inputs.Count == 0)
{ {
InitVerify(datfiles, inputs, depot, hashOnly, quickScan, datHeader.Header, splitType, chdsAsFiles); Globals.Logger.Error("This feature requires at least one input");
_help.OutputIndividualFeature(feature);
break;
} }
InitVerify(datfiles, inputs, depot, hashOnly, quickScan, datHeader.Header, splitType, chdsAsFiles);
break;
// If nothing is set, show the help // If nothing is set, show the help
else default:
{
_help.OutputGenericHelp(); _help.OutputGenericHelp();
break;
} }
Globals.Logger.Close(); Globals.Logger.Close();