Files
SabreTools/DATabase/DATabase.cs

847 lines
23 KiB
C#
Raw Normal View History

using System;
using System.Data.SQLite;
using System.IO;
using System.Xml.Linq;
using SabreTools.Helper;
namespace SabreTools
{
/// <summary>
/// Entry class for the DATabase application
/// </summary>
class DATabase
{
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-29 12:14:32 -07:00
private static string _version = "0.1.5.0";
2016-03-24 22:25:56 -07:00
private static string _header =
2016-03-25 00:24:30 -07:00
@"+-----------------------------------------------------------------------------+
2016-03-25 00:50:27 -07:00
| DATabase " + _version + @" |
2016-03-25 00:24:30 -07:00
| |
2016-03-28 17:54:24 -07:00
| Programming: Matt Nadareski (darksabre76) |
| Testing: @tractivo |
2016-03-25 00:24:30 -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-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();
Console.SetBufferSize(Console.BufferWidth, 999);
2016-03-25 01:27:00 -07:00
Console.Title = "DATabase " + _version;
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-24 22:25:56 -07:00
ShowMainMenu();
2016-03-28 17:54:24 -07:00
logger.Close();
return;
}
2016-03-24 13:23:25 -07:00
// Determine which switches are enabled (with values if necessary)
bool help = false, import = false, generate = false, convert = false,
2016-03-28 17:54:24 -07:00
listsys = false, listsrc = false, norename = false, old = false,
log = false, genall = false, add = false, rem = false;
string systems = "", sources = "", input = "", manu = "", url = "";
2016-03-24 13:23:25 -07:00
foreach (string arg in args)
{
2016-03-29 13:36:32 -07:00
// Main functions
2016-03-24 13:23:25 -07:00
help = help || (arg == "-h" || arg == "-?" || arg == "--help");
import = import || (arg == "-i" || arg == "--import");
generate = generate || (arg == "-g" || arg == "--generate");
2016-03-29 13:36:32 -07:00
genall = genall || (arg == "-ga" || arg == "--generate-all");
2016-03-24 13:23:25 -07:00
convert = convert || (arg == "-c" || arg == "--convert");
2016-03-24 16:10:01 -07:00
listsys = listsys || (arg == "-lsy" || arg == "--list-systems");
listsrc = listsrc || (arg == "-lso" || arg == "--list-sources");
add = add || (arg == "-a" || arg == "--add");
rem = rem || (arg == "-r" || arg == "--remove");
2016-03-29 13:36:32 -07:00
2016-03-29 13:38:58 -07:00
// Switches
2016-03-29 13:36:32 -07:00
log = log || (arg == "-l" || arg == "--log");
2016-03-29 13:38:58 -07:00
old = old || (arg == "-old" || arg == "--romvault");
norename = norename || (arg == "-nr" || arg == "--no-rename");
2016-03-29 13:36:32 -07:00
// User input strings
systems = (arg.StartsWith("system=") && systems == "" ? arg.Split('=')[1] : systems);
sources = (arg.StartsWith("source=") && sources == "" ? arg.Split('=')[1] : sources);
manu = (arg.StartsWith("manu=") && manu == "" ? arg.Split('=')[1] : manu);
url = (arg.StartsWith("url=") && url == "" ? arg.Split('=')[1] : url);
2016-03-24 14:53:27 -07:00
// Take care of the two distinct input name possibilites; prioritize the input tag
input = (arg.StartsWith("input=") && input == "" ? arg.Split('=')[1] : input);
2016-03-29 13:36:32 -07:00
input = (!arg.StartsWith("-") &&
!arg.StartsWith("source=") &&
!arg.StartsWith("system=") &&
!arg.StartsWith("manu=") &&
!arg.StartsWith("url=") &&
!arg.StartsWith("input=") &&
input == "" ? arg : input);
2016-03-24 13:23:25 -07:00
}
2016-03-24 16:29:27 -07:00
// If more than one switch is enabled or help is set, show the help screen
2016-03-29 03:10:54 -07:00
if (help || !(import ^ generate ^ listsys ^ listsrc ^ genall ^ add ^ rem))
2016-03-24 13:23:25 -07:00
{
Help();
2016-03-28 17:54:24 -07:00
logger.Close();
2016-03-24 13:23:25 -07:00
return;
}
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-03-24 22:25:56 -07:00
InitImport(input);
2016-03-24 13:23:25 -07:00
}
// Generate a DAT
else if (generate)
{
2016-03-24 22:25:56 -07:00
InitGenerate(systems, sources, norename, old);
2016-03-24 13:23:25 -07:00
}
2016-03-28 19:44:10 -07:00
// Generate all DATs
else if (genall)
{
InitGenerateAll(norename, old);
}
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-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-24 13:23:25 -07:00
// Convert RV DAT to XML DAT
else if (convert)
{
2016-03-24 22:25:56 -07:00
InitConvert(input);
}
// Add a source or system
else if (add)
{
if (manu != "" && systems != "")
{
InitAddSystem(manu, systems);
}
else if (sources != "" && url != "")
{
InitAddSource(manu, systems);
}
else
{
Help();
}
}
// Remove a source or system
else if (rem)
{
if (systems != "")
{
InitRemoveSystem(systems);
}
else if (sources != "")
{
InitRemoveSource(sources);
}
else
{
Help();
}
}
2016-03-28 17:54:24 -07:00
logger.Close();
2016-03-24 22:25:56 -07:00
return;
}
/// <summary>
/// Print the program header
/// </summary>
2016-03-25 00:24:30 -07:00
private static void PrintHeader()
{
ConsoleColor formertext = Console.ForegroundColor;
ConsoleColor formerback = Console.BackgroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Blue;
Console.WriteLine(_header);
Console.ForegroundColor = formertext;
Console.BackgroundColor = formerback;
}
/// <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-03-25 00:24:30 -07:00
PrintHeader();
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
3) Generate a DAT file
2016-03-28 19:44:10 -07:00
4) Generate all DAT files
5) Convert a DAT file from RV to XML
6) List all available sources
7) List all available systems
2016-03-29 02:45:39 -07:00
8) Add and Remove from database
9) " + (logger.ToFile ? "Disable Logging" : "Enable Logging") + @"
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":
Help();
break;
case "2":
ImportMenu();
break;
case "3":
GenerateMenu();
break;
case "4":
2016-03-28 19:44:10 -07:00
GenerateAllMenu();
2016-03-24 22:25:56 -07:00
break;
case "5":
2016-03-28 19:44:10 -07:00
ConvertMenu();
break;
case "6":
2016-03-25 00:28:39 -07:00
Console.Clear();
PrintHeader();
2016-03-24 22:25:56 -07:00
ListSources();
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
2016-03-28 19:44:10 -07:00
case "7":
2016-03-25 00:28:39 -07:00
Console.Clear();
PrintHeader();
2016-03-24 22:25:56 -07:00
ListSystems();
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
2016-03-28 19:44:10 -07:00
case "8":
2016-03-29 02:45:39 -07:00
AddRemoveMenu();
break;
case "9":
2016-03-28 17:54:24 -07:00
logger.ToFile = !logger.ToFile;
break;
2016-03-24 13:23:25 -07:00
}
}
2016-03-24 22:25:56 -07:00
Console.Clear();
Console.WriteLine("Thank you for using DATabase!");
}
/// <summary>
/// Show the help dialog
/// </summary>
2016-03-24 22:25:56 -07:00
private static void Help()
{
Console.Clear();
Console.Write(@"
DATabase - Import and Generate DAT files
-----------------------------------------
2016-03-24 17:38:08 -07:00
Usage: DATabase [option] [filename|dirname|<system=sy,...> <source=so,...>]
2016-03-24 16:10:01 -07:00
Options:
-h, -?, --help Show this help
-i, --import Start tool in import mode
A filename or folder is required to run
-g, --generate Start tool in generate mode
2016-03-24 17:38:08 -07:00
system=sy,... List of system IDs
source=so,... List of source IDs
-nr, --no-rename Don't auto-rename games
-old, --romvault Produce a DAT in RV format
2016-03-28 19:44:10 -07:00
-ga, --generate-all Start tool in generate all mode
2016-03-24 16:10:01 -07:00
-lso, --list-sources List all sources (id <= name)
-lsy, --list-systems List all systems (id <= name)
-c, --convert Convert a RV DAT to XML
A filename or folder is required to run
2016-03-28 17:54:24 -07:00
-l, --log Enable logging of program output
Filenames and directories can't start with '-', 'system=', or 'source='
2016-03-24 14:53:27 -07:00
unless prefixed by 'input='
");
2016-03-24 22:25:56 -07:00
Console.Write("\nPress any key to continue...");
Console.ReadKey();
2016-03-29 02:45:39 -07:00
Console.Write(@"
Database Options:
-a, --add Add a new system or source to the database
manu=mn Manufacturer name (system only)
system=sy System name (system only)
source=sr Source name (source only)
url=ul URL (source only)
2016-03-29 02:45:39 -07:00
-r, --remove Remove a system or source from the database
system=sy System ID
source=so Source ID");
Console.Write("\nPress any key to continue...");
Console.ReadKey();
2016-03-24 22:25:56 -07:00
return;
}
/// <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-03-25 00:24:30 -07:00
PrintHeader();
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;
}
/// <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();
// Check to see if the second argument is a file that exists
if (filename != "" && File.Exists(filename))
{
Console.WriteLine("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();
Console.WriteLine(filename + " imported!");
}
// Check to see if the second argument is a directory that exists
else if (filename != "" && Directory.Exists(filename))
{
foreach (string file in Directory.GetFiles(filename, "*", SearchOption.TopDirectoryOnly))
{
Console.WriteLine("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();
Console.WriteLine(file + " imported!");
}
}
else
{
Console.WriteLine("I'm sorry but " + filename + "doesn't exist!");
}
return;
}
/// <summary>
/// Show the text-based generate menu
/// </summary>
2016-03-24 22:25:56 -07:00
private static void GenerateMenu()
{
string selection = "", systems = "", sources = "";
bool norename = false, old = false;
while (selection.ToLowerInvariant() != "b")
{
Console.Clear();
2016-03-25 00:24:30 -07:00
PrintHeader();
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") + @"
3) Enter a list of systems to generate from
4) Enter a list of sources to generate from
5) Generate the DAT file
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();
InitGenerate(systems, sources, norename, old);
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
}
}
return;
}
/// <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>
private static void InitGenerate(string systems, string sources, bool norename, bool old)
{
Generate gen = new Generate(systems, sources, _connectionString, logger, norename, old);
gen.Export();
return;
}
/// <summary>
/// Show the text-based generate all menu
/// </summary>
2016-03-28 19:44:10 -07:00
private static void GenerateAllMenu()
{
string selection = "";
bool norename = false, old = false;
while (selection.ToLowerInvariant() != "b")
{
Console.Clear();
PrintHeader();
Console.WriteLine(@"GENERATE ALL MENU
===========================
Make a selection:
1) " + (norename ? "Enable game renaming" : "Disable game renaming") + @"
2) " + (old ? "Enable XML output" : "Enable RomVault output") + @"
3) Generate all DAT files
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();
InitGenerateAll(norename, old);
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
}
}
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-28 19:44:10 -07:00
private static void InitGenerateAll(bool norename, bool old)
{
// 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)
{
logger.Log("Error: No systems found! Please add a source and then try again.");
return;
}
while (sldr.Read())
{
InitGenerate(sldr.GetInt32(0).ToString(), "", norename, old);
// 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() + @"
ORDER BY sources.name";
using (SQLiteCommand sslc = new SQLiteCommand(squery, dbc))
{
using (SQLiteDataReader ssldr = sslc.ExecuteReader())
{
// If nothing is found, tell the user and exit
if (!ssldr.HasRows)
{
logger.Log("Error: No sources found! Please add a source and then try again.");
return;
}
while (ssldr.Read())
{
InitGenerate(sldr.GetInt32(0).ToString(), ssldr.GetInt32(0).ToString(), norename, old);
}
}
}
}
}
}
// 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)
{
logger.Log("Error: No systems found! Please add a source and then try again.");
return;
}
while (sldr.Read())
{
InitGenerate("", sldr.GetInt32(0).ToString(), norename, old);
}
}
}
}
// Generate MEGAMERGED
InitGenerate("", "", norename, old);
return;
}
/// <summary>
/// Show the text-based conversion menu
/// </summary>
2016-03-24 22:25:56 -07:00
private static void ConvertMenu()
{
string selection = "";
while (selection.ToLowerInvariant() != "b")
{
Console.Clear();
2016-03-25 00:24:30 -07:00
PrintHeader();
Console.WriteLine(@"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();
InitConvert(selection);
Console.Write("\nPress any key to continue...");
Console.ReadKey();
}
}
return;
}
/// <summary>
/// Wrap converting DAT file from RomValut to XML
/// </summary>
/// <param name="filename"></param>
2016-03-24 22:25:56 -07:00
private static void InitConvert(string filename)
{
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;
}
/// <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>
private static void ListSources(bool all = false)
2016-03-24 22:25:56 -07:00
{
string query = @"
SELECT DISTINCT sources.id, sources.name
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)
{
Console.WriteLine("Error: No sources found! Please add a source and then try again.");
return;
}
Console.WriteLine("Available Sources (id <= name):\n");
while (sldr.Read())
{
Console.WriteLine(sldr.GetInt32(0) + "\t<=\t" + sldr.GetString(1));
}
}
}
}
return;
}
/// <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>
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
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)
{
Console.WriteLine("Error: No systems found! Please add a system and then try again.");
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-29 02:45:39 -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();
PrintHeader();
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();
InitAddSource(name, url);
2016-03-29 02:45:39 -07:00
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
case "2":
Console.Clear();
ListSources(true);
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();
InitAddSystem(manufacturer, system);
2016-03-29 02:45:39 -07:00
Console.Write("\nPress any key to continue...");
Console.ReadKey();
break;
case "4":
Console.Clear();
ListSystems(true);
Console.Write("Please enter the source: ");
InitRemoveSystem(Console.ReadLine());
Console.Write("\nPress any key to continue...");
Console.ReadKey();
2016-03-29 02:45:39 -07:00
break;
}
}
return;
}
/// <summary>
/// Wrap adding a new source to the database
/// </summary>
/// <param name="name">Source name</param>
/// <param name="url">Source URL(s)</param>
private static void InitAddSource(string name, string url)
{
if (DBTools.AddSource(name, url, _connectionString))
{
logger.Log("Source " + name + " added!");
}
else
{
logger.Log("Source " + name + " could not be added!");
}
}
/// <summary>
/// Wrap removing an existing source from the database
/// </summary>
/// <param name="id">Source ID to be removed from the database</param>
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-29 03:10:54 -07:00
logger.Log("Source with id '" + srcid + "' could not be removed.");
}
}
else
{
logger.Log("Invalid input");
}
}
/// <summary>
/// Wrap adding a new system to the database
/// </summary>
/// <param name="manufacturer">Manufacturer name</param>
/// <param name="system">System name</param>
private static void InitAddSystem(string manufacturer, string system)
{
if (DBTools.AddSystem(manufacturer, system, _connectionString))
{
logger.Log("System " + manufacturer + " - " + system + " added!");
}
else
{
logger.Log("System " + manufacturer + " - " + system + " could not be added!");
}
}
/// <summary>
/// Wrap removing an existing system from the database
/// </summary>
/// <param name="id">System ID to be removed from the database</param>
private static void InitRemoveSystem(string systemid)
{
int sysid = -1;
if (Int32.TryParse(systemid, out sysid))
{
if (DBTools.RemoveSource(sysid, _connectionString))
{
Console.WriteLine("System '" + sysid + "' removed!");
}
else
{
2016-03-29 03:10:54 -07:00
Console.WriteLine("System with id '" + sysid + "' could not be removed.");
}
}
else
{
Console.WriteLine("Invalid input");
}
}
}
}