2016-03-18 01:17:39 -07:00
|
|
|
|
using System;
|
2016-04-18 16:32:17 -07:00
|
|
|
|
using System.Collections.Generic;
|
2016-03-18 01:17:39 -07:00
|
|
|
|
using System.Data.SQLite;
|
|
|
|
|
|
using System.IO;
|
2016-04-06 16:23:46 -07:00
|
|
|
|
using System.IO.Compression;
|
2016-04-03 03:05:51 -07:00
|
|
|
|
using System.Xml;
|
2016-03-19 02:16:26 -07:00
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
2016-03-29 13:48:10 -07:00
|
|
|
|
using SabreTools.Helper;
|
2016-03-24 14:03:22 -07:00
|
|
|
|
|
2016-03-29 13:48:10 -07:00
|
|
|
|
namespace SabreTools
|
2016-03-18 01:17:39 -07:00
|
|
|
|
{
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Entry class for the DATabase application
|
|
|
|
|
|
/// </summary>
|
2016-03-28 02:06:14 -07:00
|
|
|
|
class DATabase
|
2016-03-18 01:17:39 -07:00
|
|
|
|
{
|
2016-03-28 18:40:35 -07:00
|
|
|
|
private static Logger logger;
|
2016-03-24 16:17:33 -07:00
|
|
|
|
private static string _dbName = "DATabase.sqlite";
|
|
|
|
|
|
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
2016-03-18 01:17:39 -07:00
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Start menu or use supplied parameters
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="args">String array representing command line parameters</param>
|
|
|
|
|
|
public static void Main(string[] args)
|
2016-03-18 01:17:39 -07:00
|
|
|
|
{
|
2016-03-24 16:17:33 -07:00
|
|
|
|
// Perform initial setup and verification
|
2016-03-28 18:40:35 -07:00
|
|
|
|
logger = new Logger(false, "database.log");
|
2016-03-28 17:54:24 -07:00
|
|
|
|
logger.Start();
|
2016-03-29 12:11:58 -07:00
|
|
|
|
DBTools.EnsureDatabase(_dbName, _connectionString);
|
|
|
|
|
|
Remapping.CreateRemappings();
|
2016-03-24 16:25:43 -07:00
|
|
|
|
Console.Clear();
|
2016-03-18 01:17:39 -07:00
|
|
|
|
|
2016-04-18 16:32:17 -07:00
|
|
|
|
// Credits take precidence over all
|
|
|
|
|
|
if ((new List<string>(args)).Contains("--credits"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Build.Credits();
|
|
|
|
|
|
logger.Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-24 22:25:56 -07:00
|
|
|
|
// If there's no arguments, show the menu
|
2016-03-24 13:23:25 -07:00
|
|
|
|
if (args.Length == 0)
|
2016-03-18 01:17:39 -07:00
|
|
|
|
{
|
2016-03-24 22:25:56 -07:00
|
|
|
|
ShowMainMenu();
|
2016-03-28 17:54:24 -07:00
|
|
|
|
logger.Close();
|
2016-03-18 01:17:39 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-20 00:15:02 -07:00
|
|
|
|
// Set all default values
|
2016-04-20 00:50:31 -07:00
|
|
|
|
bool help = false,
|
2016-04-20 00:15:02 -07:00
|
|
|
|
add = false,
|
|
|
|
|
|
convertRV = false,
|
|
|
|
|
|
convertXml = false,
|
2016-04-20 00:50:31 -07:00
|
|
|
|
disableForce = false,
|
2016-04-20 11:27:17 -07:00
|
|
|
|
extsplit = false,
|
2016-04-20 00:15:02 -07:00
|
|
|
|
generate = false,
|
|
|
|
|
|
genall = false,
|
|
|
|
|
|
import = false,
|
|
|
|
|
|
log = false,
|
|
|
|
|
|
listsrc = false,
|
|
|
|
|
|
listsys = false,
|
|
|
|
|
|
norename = false,
|
|
|
|
|
|
old = false,
|
|
|
|
|
|
rem = false,
|
2016-04-20 01:27:15 -07:00
|
|
|
|
trim = false,
|
2016-04-20 00:15:02 -07:00
|
|
|
|
skip = false;
|
2016-04-20 11:27:17 -07:00
|
|
|
|
string exta = "",
|
|
|
|
|
|
extb = "",
|
|
|
|
|
|
manu = "",
|
2016-04-20 00:15:02 -07:00
|
|
|
|
outdir = "",
|
|
|
|
|
|
sources = "",
|
|
|
|
|
|
systems = "",
|
2016-04-20 00:50:31 -07:00
|
|
|
|
root = "",
|
2016-04-20 00:15:02 -07:00
|
|
|
|
url = "";
|
|
|
|
|
|
List<string> inputs = new List<string>();
|
|
|
|
|
|
|
2016-03-24 13:23:25 -07:00
|
|
|
|
// Determine which switches are enabled (with values if necessary)
|
|
|
|
|
|
foreach (string arg in args)
|
2016-03-18 01:17:39 -07:00
|
|
|
|
{
|
2016-04-19 01:57:29 -07:00
|
|
|
|
switch (arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "-?":
|
2016-04-20 00:15:02 -07:00
|
|
|
|
case "-h":
|
2016-04-19 01:57:29 -07:00
|
|
|
|
case "--help":
|
|
|
|
|
|
help = true;
|
|
|
|
|
|
break;
|
2016-04-20 00:15:02 -07:00
|
|
|
|
case "-a":
|
|
|
|
|
|
case "--add":
|
|
|
|
|
|
add = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "-cr":
|
|
|
|
|
|
case "--convert-rv":
|
|
|
|
|
|
convertRV = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "-cx":
|
|
|
|
|
|
case "--convert-xml":
|
|
|
|
|
|
convertXml = true;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
break;
|
2016-04-20 00:50:31 -07:00
|
|
|
|
case "-df":
|
|
|
|
|
|
case "--disable-force":
|
2016-04-20 11:27:17 -07:00
|
|
|
|
disableForce = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "-es":
|
|
|
|
|
|
case "--ext-split":
|
|
|
|
|
|
extsplit = true;
|
2016-04-20 00:50:31 -07:00
|
|
|
|
break;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
case "-g":
|
|
|
|
|
|
case "--generate":
|
|
|
|
|
|
generate = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "-ga":
|
|
|
|
|
|
case "--generate-all":
|
|
|
|
|
|
genall = true;
|
|
|
|
|
|
break;
|
2016-04-20 00:15:02 -07:00
|
|
|
|
case "-i":
|
|
|
|
|
|
case "--import":
|
|
|
|
|
|
import = true;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
break;
|
2016-04-20 00:15:02 -07:00
|
|
|
|
case "-l":
|
|
|
|
|
|
case "--log":
|
|
|
|
|
|
log = true;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "-lso":
|
|
|
|
|
|
case "--list-sources":
|
|
|
|
|
|
listsrc = true;
|
|
|
|
|
|
break;
|
2016-04-20 00:15:02 -07:00
|
|
|
|
case "-lsy":
|
|
|
|
|
|
case "--list-systems":
|
|
|
|
|
|
listsys = true;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
break;
|
2016-04-20 00:15:02 -07:00
|
|
|
|
case "-nr":
|
|
|
|
|
|
case "--no-rename":
|
|
|
|
|
|
norename = true;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "-old":
|
|
|
|
|
|
case "--romvault":
|
|
|
|
|
|
old = true;
|
|
|
|
|
|
break;
|
2016-04-20 00:15:02 -07:00
|
|
|
|
case "-r":
|
|
|
|
|
|
case "--remove":
|
|
|
|
|
|
rem = true;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "--skip":
|
|
|
|
|
|
skip = true;
|
|
|
|
|
|
break;
|
2016-04-20 01:27:15 -07:00
|
|
|
|
case "-tm":
|
|
|
|
|
|
case "--trim-merge":
|
|
|
|
|
|
trim = true;
|
|
|
|
|
|
break;
|
2016-04-19 01:57:29 -07:00
|
|
|
|
default:
|
2016-04-20 11:27:17 -07:00
|
|
|
|
if (arg.StartsWith("exta="))
|
|
|
|
|
|
{
|
|
|
|
|
|
exta = arg.Split('=')[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (arg.StartsWith("extb"))
|
|
|
|
|
|
{
|
|
|
|
|
|
extb = arg.Split('=')[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (arg.StartsWith("input="))
|
2016-04-19 01:57:29 -07:00
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
inputs.Add(arg.Split('=')[1]);
|
2016-04-19 01:57:29 -07:00
|
|
|
|
}
|
2016-04-20 00:15:02 -07:00
|
|
|
|
else if (arg.StartsWith("manu=") && manu == "")
|
2016-04-19 01:57:29 -07:00
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
manu = arg.Split('=')[1];
|
2016-04-19 01:57:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (arg.StartsWith("out=") && outdir == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
outdir = arg.Split('=')[1];
|
|
|
|
|
|
}
|
2016-04-20 00:15:02 -07:00
|
|
|
|
else if (arg.StartsWith("source=") && sources == "")
|
2016-04-19 01:57:29 -07:00
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
sources = arg.Split('=')[1];
|
2016-04-19 01:57:29 -07:00
|
|
|
|
}
|
2016-04-20 00:15:02 -07:00
|
|
|
|
else if (arg.StartsWith("system=") && systems == "")
|
2016-04-19 01:57:29 -07:00
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
systems = arg.Split('=')[1];
|
2016-04-19 01:57:29 -07:00
|
|
|
|
}
|
2016-04-20 00:50:31 -07:00
|
|
|
|
else if(arg.StartsWith("-rd=") || arg.StartsWith("--root-dir="))
|
|
|
|
|
|
{
|
|
|
|
|
|
root = arg.Split('=')[1];
|
|
|
|
|
|
}
|
2016-04-20 00:15:02 -07:00
|
|
|
|
else if (arg.StartsWith("url=") && url == "")
|
2016-04-19 01:57:29 -07:00
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
url = arg.Split('=')[1];
|
2016-04-19 01:57:29 -07:00
|
|
|
|
}
|
2016-04-20 00:15:02 -07:00
|
|
|
|
else
|
2016-04-19 01:57:29 -07:00
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
inputs.Add(arg);
|
2016-04-19 01:57:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-03-24 13:23:25 -07:00
|
|
|
|
}
|
2016-03-18 01:17:39 -07:00
|
|
|
|
|
2016-03-29 21:23:22 -07:00
|
|
|
|
// If skip is set, it's being called from the UI so we just exit
|
|
|
|
|
|
if (skip)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-24 16:29:27 -07:00
|
|
|
|
// If more than one switch is enabled or help is set, show the help screen
|
2016-04-20 11:27:17 -07:00
|
|
|
|
if (help || !(add ^ convertRV ^ convertXml ^ extsplit ^ generate ^ genall ^ import ^ listsrc ^ listsys ^ rem ^ trim))
|
2016-04-20 00:50:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
Build.Help();
|
|
|
|
|
|
logger.Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If a switch that requires a filename is set and no file is, show the help screen
|
2016-04-20 11:27:17 -07:00
|
|
|
|
if (inputs.Count == 0 && (convertRV || convertXml || extsplit || import || trim))
|
2016-03-24 13:23:25 -07:00
|
|
|
|
{
|
2016-04-06 14:19:01 -07:00
|
|
|
|
Build.Help();
|
2016-03-28 17:54:24 -07:00
|
|
|
|
logger.Close();
|
2016-03-24 13:23:25 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-03-18 01:17:39 -07:00
|
|
|
|
|
2016-03-28 17:54:24 -07:00
|
|
|
|
// Update the logger with the new value
|
|
|
|
|
|
logger.ToFile = log;
|
|
|
|
|
|
|
2016-03-24 13:23:25 -07:00
|
|
|
|
// Now take care of each mode in succesion
|
|
|
|
|
|
|
|
|
|
|
|
// Import a file or folder
|
|
|
|
|
|
if (import)
|
|
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
foreach (string input in inputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitImport(input);
|
|
|
|
|
|
}
|
2016-03-24 13:23:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Generate a DAT
|
|
|
|
|
|
else if (generate)
|
|
|
|
|
|
{
|
2016-03-31 16:24:58 -07:00
|
|
|
|
InitGenerate(systems, sources, outdir, norename, old);
|
2016-03-24 13:23:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-28 19:44:10 -07:00
|
|
|
|
// Generate all DATs
|
|
|
|
|
|
else if (genall)
|
|
|
|
|
|
{
|
2016-03-31 16:24:58 -07:00
|
|
|
|
InitGenerateAll(outdir, norename, old);
|
2016-03-28 19:44:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-24 13:23:25 -07:00
|
|
|
|
// List all available sources
|
|
|
|
|
|
else if (listsrc)
|
|
|
|
|
|
{
|
2016-03-24 22:25:56 -07:00
|
|
|
|
ListSources();
|
2016-03-24 13:23:25 -07:00
|
|
|
|
}
|
2016-03-18 01:17:39 -07:00
|
|
|
|
|
2016-03-24 13:23:25 -07:00
|
|
|
|
// List all available systems
|
|
|
|
|
|
else if (listsys)
|
|
|
|
|
|
{
|
2016-03-24 22:25:56 -07:00
|
|
|
|
ListSystems();
|
2016-03-24 13:23:25 -07:00
|
|
|
|
}
|
2016-03-19 02:16:26 -07:00
|
|
|
|
|
2016-04-03 03:05:51 -07:00
|
|
|
|
// Convert XML DAT to RV DAT
|
|
|
|
|
|
else if (convertRV)
|
|
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
foreach (string input in inputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitConvertRV(input);
|
|
|
|
|
|
}
|
2016-04-03 03:05:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-24 13:23:25 -07:00
|
|
|
|
// Convert RV DAT to XML DAT
|
2016-04-03 03:05:51 -07:00
|
|
|
|
else if (convertXml)
|
2016-03-24 13:23:25 -07:00
|
|
|
|
{
|
2016-04-20 00:15:02 -07:00
|
|
|
|
foreach (string input in inputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitConvertXML(input);
|
|
|
|
|
|
}
|
2016-03-24 22:25:56 -07:00
|
|
|
|
}
|
2016-03-29 03:09:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Add a source or system
|
|
|
|
|
|
else if (add)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (manu != "" && systems != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
InitAddSystem(manu, systems);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (sources != "" && url != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
InitAddSource(manu, systems);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-04-06 14:19:01 -07:00
|
|
|
|
Build.Help();
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove a source or system
|
|
|
|
|
|
else if (rem)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (systems != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
InitRemoveSystem(systems);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (sources != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
InitRemoveSource(sources);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-04-06 14:19:01 -07:00
|
|
|
|
Build.Help();
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-20 00:50:31 -07:00
|
|
|
|
// Consolodate and trim DAT
|
2016-04-20 01:27:15 -07:00
|
|
|
|
else if (trim)
|
2016-04-20 00:50:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
foreach (string input in inputs)
|
|
|
|
|
|
{
|
2016-04-20 01:27:15 -07:00
|
|
|
|
InitTrimMerge(input, root, !norename, !disableForce);
|
2016-04-20 00:50:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-28 17:54:24 -07:00
|
|
|
|
logger.Close();
|
2016-03-24 22:25:56 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Show the text-based main menu
|
|
|
|
|
|
/// </summary>
|
2016-03-24 22:25:56 -07:00
|
|
|
|
private static void ShowMainMenu()
|
|
|
|
|
|
{
|
2016-03-25 00:24:30 -07:00
|
|
|
|
Console.Clear();
|
2016-03-24 22:25:56 -07:00
|
|
|
|
string selection = "";
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "x")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-03-25 00:24:30 -07:00
|
|
|
|
Console.WriteLine(@"MAIN MENU
|
2016-03-24 22:25:56 -07:00
|
|
|
|
===========================
|
|
|
|
|
|
Make a selection:
|
|
|
|
|
|
|
2016-03-25 00:26:42 -07:00
|
|
|
|
1) Show command line usage
|
2016-03-24 22:25:56 -07:00
|
|
|
|
2) Import a DAT file or folder
|
2016-04-20 00:01:58 -07:00
|
|
|
|
3) Generate DAT files
|
|
|
|
|
|
4) DAT file tools
|
|
|
|
|
|
5) List all available sources
|
|
|
|
|
|
6) List all available systems
|
|
|
|
|
|
7) Add and remove systems and sources
|
|
|
|
|
|
8) " + (logger.ToFile ? "Disable Logging" : "Enable Logging") + @"
|
|
|
|
|
|
9) Show credits
|
2016-03-25 00:26:42 -07:00
|
|
|
|
X) Exit Program
|
2016-03-24 22:25:56 -07:00
|
|
|
|
");
|
|
|
|
|
|
Console.Write("Enter selection: ");
|
|
|
|
|
|
selection = Console.ReadLine();
|
|
|
|
|
|
|
|
|
|
|
|
switch (selection)
|
2016-03-24 13:23:25 -07:00
|
|
|
|
{
|
2016-03-24 22:25:56 -07:00
|
|
|
|
case "1":
|
2016-04-20 02:53:24 -07:00
|
|
|
|
Console.Clear();
|
2016-04-06 14:19:01 -07:00
|
|
|
|
Build.Help();
|
2016-04-20 01:47:44 -07:00
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
2016-03-24 22:25:56 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "2":
|
|
|
|
|
|
ImportMenu();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "3":
|
|
|
|
|
|
GenerateMenu();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "4":
|
2016-04-20 00:01:58 -07:00
|
|
|
|
DatToolsMenu();
|
2016-03-24 22:25:56 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "5":
|
2016-03-25 00:28:39 -07:00
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
ListSources();
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
2016-04-20 00:01:58 -07:00
|
|
|
|
case "6":
|
2016-03-25 00:28:39 -07:00
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
ListSystems();
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
2016-04-20 00:01:58 -07:00
|
|
|
|
case "7":
|
2016-03-29 02:45:39 -07:00
|
|
|
|
AddRemoveMenu();
|
|
|
|
|
|
break;
|
2016-04-20 00:01:58 -07:00
|
|
|
|
case "8":
|
2016-03-28 17:54:24 -07:00
|
|
|
|
logger.ToFile = !logger.ToFile;
|
|
|
|
|
|
break;
|
2016-04-20 00:01:58 -07:00
|
|
|
|
case "9":
|
2016-04-18 16:38:54 -07:00
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Build.Credits();
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
2016-03-24 13:23:25 -07:00
|
|
|
|
}
|
2016-03-18 01:17:39 -07:00
|
|
|
|
}
|
2016-03-24 22:25:56 -07:00
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Console.WriteLine("Thank you for using DATabase!");
|
2016-03-18 01:17:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Show the text-based import menu
|
|
|
|
|
|
/// </summary>
|
2016-03-24 22:25:56 -07:00
|
|
|
|
private static void ImportMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
string selection = "";
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-03-25 00:24:30 -07:00
|
|
|
|
Console.WriteLine( @"IMPORT MENU
|
2016-03-24 22:25:56 -07:00
|
|
|
|
===========================
|
|
|
|
|
|
Enter the name of a DAT file or folder containing DAT files
|
|
|
|
|
|
or 'b' to go back to the previous menu:");
|
|
|
|
|
|
Console.Write("Enter selection: ");
|
|
|
|
|
|
selection = Console.ReadLine();
|
|
|
|
|
|
if (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
InitImport(selection);
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap importing a file or folder into the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filename">File or folder to be imported</param>
|
2016-03-24 22:25:56 -07:00
|
|
|
|
private static void InitImport(string filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
|
2016-04-19 11:25:59 -07:00
|
|
|
|
// Drag and drop means quotes; we don't want quotes
|
|
|
|
|
|
filename = filename.Replace("\"", "");
|
|
|
|
|
|
|
2016-03-24 22:25:56 -07:00
|
|
|
|
// Check to see if the second argument is a file that exists
|
|
|
|
|
|
if (filename != "" && File.Exists(filename))
|
|
|
|
|
|
{
|
2016-03-29 23:28:50 -07:00
|
|
|
|
logger.Log("Beginning import of " + filename);
|
2016-03-28 17:54:24 -07:00
|
|
|
|
Import imp = new Import(filename, _connectionString, logger);
|
2016-03-24 22:25:56 -07:00
|
|
|
|
imp.ImportData();
|
2016-03-29 23:28:50 -07:00
|
|
|
|
logger.Log(filename + " imported!");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
// Check to see if the second argument is a directory that exists
|
|
|
|
|
|
else if (filename != "" && Directory.Exists(filename))
|
|
|
|
|
|
{
|
2016-03-31 12:27:30 -07:00
|
|
|
|
foreach (string file in Directory.GetFiles(filename, "*", SearchOption.AllDirectories))
|
2016-03-24 22:25:56 -07:00
|
|
|
|
{
|
2016-03-29 23:28:50 -07:00
|
|
|
|
logger.Log("Beginning import of " + file);
|
2016-03-28 17:54:24 -07:00
|
|
|
|
Import imp = new Import(file, _connectionString, logger);
|
2016-03-24 22:25:56 -07:00
|
|
|
|
imp.ImportData();
|
2016-03-29 23:28:50 -07:00
|
|
|
|
logger.Log(file + " imported!");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-04-19 11:25:59 -07:00
|
|
|
|
logger.Error("I'm sorry but " + filename + " doesn't exist!");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Show the text-based generate menu
|
|
|
|
|
|
/// </summary>
|
2016-03-24 22:25:56 -07:00
|
|
|
|
private static void GenerateMenu()
|
|
|
|
|
|
{
|
2016-03-31 16:24:58 -07:00
|
|
|
|
string selection = "", systems = "", sources = "", outdir = "";
|
2016-03-24 22:25:56 -07:00
|
|
|
|
bool norename = false, old = false;
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-03-25 00:24:30 -07:00
|
|
|
|
Console.WriteLine(@"GENERATE MENU
|
2016-03-24 22:25:56 -07:00
|
|
|
|
===========================
|
|
|
|
|
|
Make a selection:
|
|
|
|
|
|
|
|
|
|
|
|
1) " + (norename ? "Enable game renaming" : "Disable game renaming") + @"
|
|
|
|
|
|
2) " + (old ? "Enable XML output" : "Enable RomVault output") + @"
|
2016-04-20 00:01:58 -07:00
|
|
|
|
3) List of systems to generate from" + (systems != "" ? ": " + systems : "") + @"
|
|
|
|
|
|
4) List of sources to generate from" + (sources != "" ? ": " + sources : "") + @"
|
|
|
|
|
|
5) Enter an output folder" + (outdir != "" ? ":\n\t" + outdir : "") + @"
|
2016-03-31 16:24:58 -07:00
|
|
|
|
6) Generate the DAT file
|
2016-04-20 00:01:58 -07:00
|
|
|
|
7) Generate all available DAT files
|
2016-03-24 22:25:56 -07:00
|
|
|
|
B) Go back to the previous menu
|
|
|
|
|
|
");
|
|
|
|
|
|
Console.Write("Enter selection: ");
|
|
|
|
|
|
selection = Console.ReadLine();
|
|
|
|
|
|
switch (selection)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "1":
|
|
|
|
|
|
norename = !norename;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "2":
|
|
|
|
|
|
old = !old;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "3":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
ListSystems();
|
|
|
|
|
|
Console.Write("Please enter the systems separated by commas: ");
|
|
|
|
|
|
systems = Console.ReadLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "4":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
ListSources();
|
|
|
|
|
|
Console.Write("Please enter the sources separated by commas: ");
|
|
|
|
|
|
sources = Console.ReadLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "5":
|
|
|
|
|
|
Console.Clear();
|
2016-03-31 16:24:58 -07:00
|
|
|
|
Console.Write("Please enter a folder name: ");
|
|
|
|
|
|
outdir = Console.ReadLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "6":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
InitGenerate(systems, sources, outdir, norename, old);
|
2016-03-24 22:25:56 -07:00
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
2016-04-20 00:01:58 -07:00
|
|
|
|
case "7":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
InitGenerateAll(outdir, norename, old);
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
2016-03-24 22:25:56 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap generating a DAT from the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="systems">Comma-separated list of systems to be included in the DAT (blank means all)</param>
|
|
|
|
|
|
/// <param name="sources">Comma-separated list of sources to be included in the DAT (blank means all)</param>
|
|
|
|
|
|
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
|
|
|
|
|
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
2016-03-31 16:24:58 -07:00
|
|
|
|
private static void InitGenerate(string systems, string sources, string outdir, bool norename, bool old)
|
2016-03-29 14:49:03 -07:00
|
|
|
|
{
|
2016-03-31 16:24:58 -07:00
|
|
|
|
Generate gen = new Generate(systems, sources, outdir, _connectionString, logger, norename, old);
|
2016-03-29 14:49:03 -07:00
|
|
|
|
gen.Export();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap generating all standard DATs from the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="norename">True if files should not be renamed with system and/or source in merged mode (default false)</param>
|
|
|
|
|
|
/// <param name="old">True if the output file should be in RomVault format (default false)</param>
|
2016-03-31 16:24:58 -07:00
|
|
|
|
private static void InitGenerateAll(string outdir, bool norename, bool old)
|
2016-03-28 19:44:10 -07:00
|
|
|
|
{
|
2016-04-06 17:09:51 -07:00
|
|
|
|
string actualdir = (outdir == "" ? Environment.CurrentDirectory + "/" : outdir + "/");
|
|
|
|
|
|
outdir = actualdir + "/temp/";
|
2016-04-06 16:23:46 -07:00
|
|
|
|
|
2016-03-28 19:44:10 -07:00
|
|
|
|
// Generate system-merged
|
|
|
|
|
|
string query = @"SELECT DISTINCT systems.id
|
|
|
|
|
|
FROM systems
|
|
|
|
|
|
JOIN games
|
|
|
|
|
|
ON systems.id=games.system
|
|
|
|
|
|
ORDER BY systems.manufacturer, systems.system";
|
|
|
|
|
|
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
dbc.Open();
|
|
|
|
|
|
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
|
|
|
|
|
{
|
|
|
|
|
|
// If nothing is found, tell the user and exit
|
|
|
|
|
|
if (!sldr.HasRows)
|
|
|
|
|
|
{
|
2016-03-30 14:18:37 -07:00
|
|
|
|
logger.Error("No systems found! Please add a source and then try again.");
|
2016-03-28 19:44:10 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (sldr.Read())
|
|
|
|
|
|
{
|
2016-03-31 16:24:58 -07:00
|
|
|
|
InitGenerate(sldr.GetInt32(0).ToString(), "", outdir, norename, old);
|
2016-03-28 19:44:10 -07:00
|
|
|
|
|
|
|
|
|
|
// Generate custom
|
|
|
|
|
|
string squery = @"SELECT DISTINCT sources.id
|
|
|
|
|
|
FROM systems
|
|
|
|
|
|
JOIN games
|
|
|
|
|
|
ON systems.id=games.system
|
|
|
|
|
|
JOIN sources
|
|
|
|
|
|
ON games.source=sources.id
|
|
|
|
|
|
WHERE systems.id=" + sldr.GetInt32(0).ToString() + @"
|
2016-04-04 23:11:29 -07:00
|
|
|
|
ORDER BY sources.name";
|
2016-03-28 19:44:10 -07:00
|
|
|
|
|
|
|
|
|
|
using (SQLiteCommand sslc = new SQLiteCommand(squery, dbc))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (SQLiteDataReader ssldr = sslc.ExecuteReader())
|
|
|
|
|
|
{
|
|
|
|
|
|
// If nothing is found, tell the user and exit
|
|
|
|
|
|
if (!ssldr.HasRows)
|
|
|
|
|
|
{
|
2016-03-30 14:18:37 -07:00
|
|
|
|
logger.Error("No sources found! Please add a source and then try again.");
|
2016-03-28 19:44:10 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (ssldr.Read())
|
|
|
|
|
|
{
|
2016-03-31 16:24:58 -07:00
|
|
|
|
InitGenerate(sldr.GetInt32(0).ToString(), ssldr.GetInt32(0).ToString(), outdir, norename, old);
|
2016-03-28 19:44:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Generate source-merged
|
|
|
|
|
|
query = @"SELECT DISTINCT sources.id, sources.name
|
|
|
|
|
|
FROM sources
|
|
|
|
|
|
JOIN games
|
|
|
|
|
|
ON sources.id=games.source
|
|
|
|
|
|
ORDER BY sources.name";
|
|
|
|
|
|
|
|
|
|
|
|
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
|
|
|
|
|
{
|
|
|
|
|
|
// If nothing is found, tell the user and exit
|
|
|
|
|
|
if (!sldr.HasRows)
|
|
|
|
|
|
{
|
2016-03-30 14:18:37 -07:00
|
|
|
|
logger.Error("No sources found! Please add a source and then try again.");
|
2016-03-28 19:44:10 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (sldr.Read())
|
|
|
|
|
|
{
|
2016-03-31 16:24:58 -07:00
|
|
|
|
InitGenerate("", sldr.GetInt32(0).ToString(), outdir, norename, old);
|
2016-03-28 19:44:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Generate MEGAMERGED
|
2016-03-31 16:24:58 -07:00
|
|
|
|
InitGenerate("", "", outdir, norename, old);
|
2016-04-06 16:23:46 -07:00
|
|
|
|
|
|
|
|
|
|
// Zip up all of the files that were generated
|
2016-04-06 17:32:58 -07:00
|
|
|
|
logger.Log("Creating zip archive");
|
2016-04-06 16:23:46 -07:00
|
|
|
|
ZipArchive zip = ZipFile.Open(actualdir + "dats-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip", ZipArchiveMode.Create);
|
|
|
|
|
|
foreach (String filename in Directory.EnumerateFiles(outdir))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (filename.EndsWith(".xml") || filename.EndsWith(".dat"))
|
|
|
|
|
|
{
|
2016-04-06 20:25:33 -07:00
|
|
|
|
string internalFolder = (filename.Contains("ALL (Merged") ? "" :
|
2016-04-06 20:12:34 -07:00
|
|
|
|
filename.Contains("Merged") ? "merged-system/" :
|
2016-04-06 16:23:46 -07:00
|
|
|
|
filename.Contains("ALL") ? "merged-source/" : "custom/");
|
2016-04-06 20:11:10 -07:00
|
|
|
|
zip.CreateEntryFromFile(filename, internalFolder + Path.GetFileName(filename), CompressionLevel.Optimal);
|
2016-04-06 16:23:46 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
zip.Dispose();
|
2016-04-06 17:32:58 -07:00
|
|
|
|
logger.Log("Zip archive created!");
|
2016-04-06 16:23:46 -07:00
|
|
|
|
|
|
|
|
|
|
// Remove all of the DATs from the folder
|
|
|
|
|
|
Directory.Delete(outdir, true);
|
|
|
|
|
|
|
2016-03-28 19:44:10 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-20 00:01:58 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Show the text-based DAT tools menu
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// At an unspecified future date, this will also include the following currently-separate programs:
|
2016-04-20 01:55:41 -07:00
|
|
|
|
/// - DatSplit*
|
2016-04-20 00:01:58 -07:00
|
|
|
|
/// - MergeDAT
|
|
|
|
|
|
/// - DATFromDir
|
|
|
|
|
|
/// - DatToMiss
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
private static void DatToolsMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
string selection = "";
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Build.Start("DATabase");
|
|
|
|
|
|
Console.WriteLine(@"DAT TOOLS MENU
|
|
|
|
|
|
===========================
|
|
|
|
|
|
Make a selection:
|
|
|
|
|
|
|
|
|
|
|
|
1) Convert XML DAT to RV
|
|
|
|
|
|
2) Convert RV DAT to XML
|
2016-04-20 01:55:41 -07:00
|
|
|
|
3) Trim all entries in DAT and merge into a single game
|
2016-04-20 11:27:17 -07:00
|
|
|
|
4) Split DAT using 2 extensions
|
2016-04-20 00:01:58 -07:00
|
|
|
|
B) Go back to the previous menu
|
|
|
|
|
|
");
|
|
|
|
|
|
Console.Write("Enter selection: ");
|
|
|
|
|
|
selection = Console.ReadLine();
|
|
|
|
|
|
switch (selection)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "1":
|
|
|
|
|
|
ConvertRVMenu();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "2":
|
|
|
|
|
|
ConvertXMLMenu();
|
|
|
|
|
|
break;
|
2016-04-20 00:50:31 -07:00
|
|
|
|
case "3":
|
2016-04-20 01:27:15 -07:00
|
|
|
|
TrimMergeMenu();
|
2016-04-20 00:50:31 -07:00
|
|
|
|
break;
|
2016-04-20 11:27:17 -07:00
|
|
|
|
case "4":
|
|
|
|
|
|
ExtSplitMenu();
|
|
|
|
|
|
break;
|
2016-04-20 00:01:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
2016-04-03 03:05:51 -07:00
|
|
|
|
/// Show the text-based XML to RV conversion menu
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static void ConvertRVMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
string selection = "";
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-04-03 03:05:51 -07:00
|
|
|
|
Console.WriteLine(@"XML -> RV CONVERT MENU
|
|
|
|
|
|
===========================
|
|
|
|
|
|
Enter the name of a DAT file to convert from XML to RV
|
|
|
|
|
|
or 'b' to go back to the previous menu:
|
|
|
|
|
|
");
|
|
|
|
|
|
selection = Console.ReadLine();
|
|
|
|
|
|
if (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-03 03:09:55 -07:00
|
|
|
|
InitConvertRV(selection);
|
2016-04-03 03:05:51 -07:00
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap converting DAT file from XML to RomVault
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filename"></param>
|
|
|
|
|
|
private static void InitConvertRV(string filename)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(filename))
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Converting " + filename);
|
|
|
|
|
|
XmlDocument doc = new XmlDocument();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
doc.LoadXml(File.ReadAllText(filename));
|
|
|
|
|
|
string conv = Converters.XMLToRomVault(doc);
|
|
|
|
|
|
FileStream fs = File.OpenWrite(Path.GetFileNameWithoutExtension(filename) + ".new.dat");
|
|
|
|
|
|
StreamWriter sw = new StreamWriter(fs);
|
|
|
|
|
|
sw.Write(conv);
|
|
|
|
|
|
sw.Close();
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
Console.WriteLine("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat");
|
|
|
|
|
|
}
|
2016-04-06 00:01:54 -07:00
|
|
|
|
catch (XmlException)
|
2016-04-03 03:05:51 -07:00
|
|
|
|
{
|
2016-04-06 00:01:54 -07:00
|
|
|
|
logger.Warning("The file " + filename + " could not be parsed as an XML file");
|
2016-04-03 03:05:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-04-06 16:23:46 -07:00
|
|
|
|
Console.WriteLine("I'm sorry but " + filename + " doesn't exist!");
|
2016-04-03 03:05:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Show the text-based RV to XML conversion menu
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// </summary>
|
2016-04-03 03:05:51 -07:00
|
|
|
|
private static void ConvertXMLMenu()
|
2016-03-24 22:25:56 -07:00
|
|
|
|
{
|
|
|
|
|
|
string selection = "";
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-04-03 03:05:51 -07:00
|
|
|
|
Console.WriteLine(@"RV -> XML CONVERT MENU
|
2016-03-24 22:25:56 -07:00
|
|
|
|
===========================
|
|
|
|
|
|
Enter the name of a DAT file to convert from RV to XML
|
|
|
|
|
|
or 'b' to go back to the previous menu:
|
|
|
|
|
|
");
|
|
|
|
|
|
selection = Console.ReadLine();
|
|
|
|
|
|
if (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-03 03:05:51 -07:00
|
|
|
|
InitConvertXML(selection);
|
2016-03-24 22:25:56 -07:00
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
2016-04-03 03:05:51 -07:00
|
|
|
|
/// Wrap converting DAT file from RomVault to XML
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filename"></param>
|
2016-04-03 03:05:51 -07:00
|
|
|
|
private static void InitConvertXML(string filename)
|
2016-03-24 22:25:56 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(filename))
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Converting " + filename);
|
|
|
|
|
|
XElement conv = Converters.RomVaultToXML(File.ReadAllLines(filename));
|
|
|
|
|
|
FileStream fs = File.OpenWrite(Path.GetFileNameWithoutExtension(filename) + ".new.xml");
|
|
|
|
|
|
StreamWriter sw = new StreamWriter(fs);
|
2016-03-25 09:23:32 -07:00
|
|
|
|
sw.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
|
|
|
|
"<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">\n\n");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
sw.Write(conv);
|
|
|
|
|
|
sw.Close();
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
Console.WriteLine("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.xml");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("I'm sorry but " + filename + "doesn't exist!");
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-20 01:19:53 -07:00
|
|
|
|
/// <summary>
|
2016-04-20 01:27:15 -07:00
|
|
|
|
/// Show the text-based TrimMerge menu
|
2016-04-20 01:19:53 -07:00
|
|
|
|
/// </summary>
|
2016-04-20 01:27:15 -07:00
|
|
|
|
private static void TrimMergeMenu()
|
2016-04-20 00:50:31 -07:00
|
|
|
|
{
|
2016-04-20 01:19:53 -07:00
|
|
|
|
string selection = "", input = "", root = "";
|
|
|
|
|
|
bool forceunzip = true, rename = true;
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Build.Start("DATabase");
|
2016-04-20 01:27:15 -07:00
|
|
|
|
Console.WriteLine(@"DAT TRIM MENU
|
2016-04-20 01:19:53 -07:00
|
|
|
|
===========================
|
|
|
|
|
|
Make a selection:
|
2016-04-20 00:50:31 -07:00
|
|
|
|
|
2016-04-20 01:19:53 -07:00
|
|
|
|
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") + @"
|
2016-04-20 01:27:15 -07:00
|
|
|
|
5) Process the file or folder
|
2016-04-20 01:19:53 -07:00
|
|
|
|
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();
|
2016-04-20 01:27:15 -07:00
|
|
|
|
InitTrimMerge(input, root, rename, forceunzip);
|
2016-04-20 01:19:53 -07:00
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-04-20 00:50:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-04-20 01:19:53 -07:00
|
|
|
|
/// Wrap trimming and merging a single DAT
|
2016-04-20 00:50:31 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input">Input file or folder to be converted</param>
|
|
|
|
|
|
/// <param name="root">Root directory to base path lengths on</param>
|
2016-04-20 01:19:53 -07:00
|
|
|
|
/// <param name="rename">True is games should not be renamed</param>
|
|
|
|
|
|
/// <param name="force">True if forcepacking="unzip" should be included</param>
|
2016-04-20 01:27:15 -07:00
|
|
|
|
private static void InitTrimMerge(string input, string root, bool rename, bool force)
|
2016-04-20 00:50:31 -07:00
|
|
|
|
{
|
2016-04-20 01:19:53 -07:00
|
|
|
|
// Strip any quotations from the name
|
|
|
|
|
|
input = input.Replace("\"", "");
|
|
|
|
|
|
|
2016-04-20 10:46:10 -07:00
|
|
|
|
if (input != "" && (File.Exists(input) || Directory.Exists(input)))
|
2016-04-20 00:50:31 -07:00
|
|
|
|
{
|
2016-04-20 01:27:15 -07:00
|
|
|
|
TrimMerge sg = new TrimMerge(input, root, rename, force, logger);
|
2016-04-20 11:27:17 -07:00
|
|
|
|
sg.Process();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Show the text-based ExtSplit menu
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static void ExtSplitMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
string selection = "", input = "", exta = "", extb = "", outdir = "";
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Build.Start("DATabase");
|
|
|
|
|
|
Console.WriteLine(@"EXTENSION SPLIT MENU
|
|
|
|
|
|
===========================
|
|
|
|
|
|
Make a selection:
|
|
|
|
|
|
|
|
|
|
|
|
1) File to split" + (input != "" ? ":\n\t" + input : "") + @"
|
|
|
|
|
|
2) First file extension" + (exta != "" ? ":\t" + exta : "") + @"
|
|
|
|
|
|
3) Second file extension" + (extb != "" ? ":\t" + extb : "") + @"
|
|
|
|
|
|
4) Output directory" + (outdir != "" ? ":\n\t" + outdir : "") + @"
|
|
|
|
|
|
5) Split the file
|
|
|
|
|
|
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 name: ");
|
|
|
|
|
|
input = Console.ReadLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "2":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Console.Write("Please enter the first extension: ");
|
|
|
|
|
|
exta = Console.ReadLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "3":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Console.Write("Please enter the second extension: ");
|
|
|
|
|
|
extb = Console.ReadLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "4":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Console.Write("Please enter the output directory: ");
|
|
|
|
|
|
exta = Console.ReadLine();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "5":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
InitTrimMerge(input, root, rename, forceunzip);
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap trimming and merging a single DAT
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input">Input file or folder to be converted</param>
|
|
|
|
|
|
/// <param name="root">Root directory to base path lengths on</param>
|
|
|
|
|
|
/// <param name="rename">True is games should not be renamed</param>
|
|
|
|
|
|
/// <param name="force">True if forcepacking="unzip" should be included</param>
|
|
|
|
|
|
private static void InitTrimMerge(string input, string root, bool rename, bool force)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Strip any quotations from the name
|
|
|
|
|
|
input = input.Replace("\"", "");
|
|
|
|
|
|
|
|
|
|
|
|
if (input != "" && (File.Exists(input) || Directory.Exists(input)))
|
|
|
|
|
|
{
|
|
|
|
|
|
TrimMerge sg = new TrimMerge(input, root, rename, force, logger);
|
2016-04-20 00:50:31 -07:00
|
|
|
|
sg.Process();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List sources in the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="all">True to list all sources regardless if there is a game associated or not</param>
|
2016-03-29 10:32:12 -07:00
|
|
|
|
private static void ListSources(bool all = false)
|
2016-03-24 22:25:56 -07:00
|
|
|
|
{
|
|
|
|
|
|
string query = @"
|
|
|
|
|
|
SELECT DISTINCT sources.id, sources.name
|
2016-03-29 10:32:12 -07:00
|
|
|
|
FROM sources " + (!all ? "JOIN games on sources.id=games.source" : "") + @"
|
2016-03-24 22:25:56 -07:00
|
|
|
|
ORDER BY sources.name COLLATE NOCASE";
|
|
|
|
|
|
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
dbc.Open();
|
|
|
|
|
|
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
|
|
|
|
|
{
|
|
|
|
|
|
// If nothing is found, tell the user and exit
|
|
|
|
|
|
if (!sldr.HasRows)
|
|
|
|
|
|
{
|
2016-03-30 14:18:37 -07:00
|
|
|
|
logger.Warning("No sources found! Please add a source and then try again.");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Available Sources (id <= name):\n");
|
|
|
|
|
|
while (sldr.Read())
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(sldr.GetInt32(0) + "\t<=\t" + sldr.GetString(1));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List systems in the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="all">True to list all systems regardless if there is a game associated or not</param>
|
2016-03-29 10:32:12 -07:00
|
|
|
|
private static void ListSystems(bool all = false)
|
2016-03-24 22:25:56 -07:00
|
|
|
|
{
|
|
|
|
|
|
string query = @"
|
|
|
|
|
|
SELECT DISTINCT systems.id, systems.manufacturer, systems.system
|
2016-03-29 10:32:12 -07:00
|
|
|
|
FROM systems " + (!all ? "JOIN games ON systems.id=games.system" : "") + @"
|
2016-03-24 22:25:56 -07:00
|
|
|
|
ORDER BY systems.manufacturer, systems.system";
|
|
|
|
|
|
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
dbc.Open();
|
|
|
|
|
|
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
|
|
|
|
|
{
|
|
|
|
|
|
// If nothing is found, tell the user and exit
|
|
|
|
|
|
if (!sldr.HasRows)
|
|
|
|
|
|
{
|
2016-03-30 14:18:37 -07:00
|
|
|
|
logger.Warning("No systems found! Please add a system and then try again.");
|
2016-03-24 22:25:56 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Available Systems (id <= name):\n");
|
|
|
|
|
|
while (sldr.Read())
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(sldr.GetInt32(0) + "\t<=\t" + sldr.GetString(1) + " - " + sldr.GetString(2));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
2016-03-18 01:17:39 -07:00
|
|
|
|
}
|
2016-03-29 02:45:39 -07:00
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Show the text-based add and remove menu
|
|
|
|
|
|
/// </summary>
|
2016-03-29 02:45:39 -07:00
|
|
|
|
private static void AddRemoveMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
string selection = "", manufacturer = "", system = "", name = "", url = "";
|
|
|
|
|
|
while (selection.ToLowerInvariant() != "b")
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Clear();
|
2016-04-18 20:04:38 -07:00
|
|
|
|
Build.Start("DATabase");
|
2016-03-29 03:09:45 -07:00
|
|
|
|
Console.WriteLine(@"ADD AND REMOVE MENU
|
2016-03-29 02:45:39 -07:00
|
|
|
|
===========================
|
|
|
|
|
|
Make a selection:
|
|
|
|
|
|
|
|
|
|
|
|
1) Add a source
|
|
|
|
|
|
2) Remove a source
|
|
|
|
|
|
3) Add a system
|
|
|
|
|
|
4) Remove a system
|
|
|
|
|
|
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 source name: ");
|
|
|
|
|
|
name = Console.ReadLine();
|
|
|
|
|
|
Console.Write("\nPlease enter the source URL: ");
|
|
|
|
|
|
url = Console.ReadLine();
|
2016-03-29 03:09:45 -07:00
|
|
|
|
InitAddSource(name, url);
|
2016-03-29 02:45:39 -07:00
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "2":
|
2016-03-29 03:09:45 -07:00
|
|
|
|
Console.Clear();
|
2016-03-29 10:32:12 -07:00
|
|
|
|
ListSources(true);
|
2016-03-29 03:09:45 -07:00
|
|
|
|
Console.Write("Please enter the source: ");
|
|
|
|
|
|
InitRemoveSource(Console.ReadLine());
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
2016-03-29 02:45:39 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case "3":
|
|
|
|
|
|
Console.Clear();
|
|
|
|
|
|
Console.Write("Please enter the manufacturer: ");
|
|
|
|
|
|
manufacturer = Console.ReadLine();
|
|
|
|
|
|
Console.Write("\nPlease enter the system: ");
|
|
|
|
|
|
system = Console.ReadLine();
|
2016-03-29 03:09:45 -07:00
|
|
|
|
InitAddSystem(manufacturer, system);
|
2016-03-29 02:45:39 -07:00
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "4":
|
2016-03-29 03:09:45 -07:00
|
|
|
|
Console.Clear();
|
2016-03-29 10:32:12 -07:00
|
|
|
|
ListSystems(true);
|
2016-03-30 12:21:38 -07:00
|
|
|
|
Console.Write("Please enter the system: ");
|
2016-03-29 03:09:45 -07:00
|
|
|
|
InitRemoveSystem(Console.ReadLine());
|
|
|
|
|
|
Console.Write("\nPress any key to continue...");
|
|
|
|
|
|
Console.ReadKey();
|
2016-03-29 02:45:39 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-03-29 03:09:45 -07:00
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap adding a new source to the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name">Source name</param>
|
|
|
|
|
|
/// <param name="url">Source URL(s)</param>
|
2016-03-29 03:09:45 -07:00
|
|
|
|
private static void InitAddSource(string name, string url)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (DBTools.AddSource(name, url, _connectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.Log("Source " + name + " added!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-03-30 13:36:52 -07:00
|
|
|
|
logger.Error("Source " + name + " could not be added!");
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap removing an existing source from the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">Source ID to be removed from the database</param>
|
2016-03-29 03:09:45 -07:00
|
|
|
|
private static void InitRemoveSource(string sourceid)
|
|
|
|
|
|
{
|
|
|
|
|
|
int srcid = -1;
|
|
|
|
|
|
if (Int32.TryParse(sourceid, out srcid))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (DBTools.RemoveSource(srcid, _connectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.Log("Source '" + srcid + "' removed!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-03-30 13:36:52 -07:00
|
|
|
|
logger.Error("Source with id '" + srcid + "' could not be removed.");
|
2016-04-04 23:11:29 -07:00
|
|
|
|
}
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-03-30 13:36:52 -07:00
|
|
|
|
logger.Error("Invalid input");
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap adding a new system to the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="manufacturer">Manufacturer name</param>
|
|
|
|
|
|
/// <param name="system">System name</param>
|
2016-03-29 03:09:45 -07:00
|
|
|
|
private static void InitAddSystem(string manufacturer, string system)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (DBTools.AddSystem(manufacturer, system, _connectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.Log("System " + manufacturer + " - " + system + " added!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-03-30 13:36:52 -07:00
|
|
|
|
logger.Error("System " + manufacturer + " - " + system + " could not be added!");
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-29 14:49:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap removing an existing system from the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">System ID to be removed from the database</param>
|
2016-03-29 03:09:45 -07:00
|
|
|
|
private static void InitRemoveSystem(string systemid)
|
|
|
|
|
|
{
|
|
|
|
|
|
int sysid = -1;
|
|
|
|
|
|
if (Int32.TryParse(systemid, out sysid))
|
|
|
|
|
|
{
|
2016-03-30 12:23:50 -07:00
|
|
|
|
if (DBTools.RemoveSystem(sysid, _connectionString))
|
2016-03-29 03:09:45 -07:00
|
|
|
|
{
|
2016-03-30 12:31:41 -07:00
|
|
|
|
logger.Log("System '" + sysid + "' removed!");
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-03-30 13:36:52 -07:00
|
|
|
|
logger.Error("System with id '" + sysid + "' could not be removed.");
|
2016-04-04 23:11:29 -07:00
|
|
|
|
}
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-03-30 13:36:52 -07:00
|
|
|
|
logger.Error("Invalid input");
|
2016-03-29 03:09:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-03-18 01:17:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|