diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index b70834e3..67ff1b54 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using Mono.Data.Sqlite; using System.IO; -using System.IO.Compression; using SabreTools.Helper; @@ -684,122 +682,5 @@ namespace SabreTools _logger.Close(); return; } - - #region Helper methods - - /// - /// Perform initial setup for the program - /// - private static void Setup() - { - Remapping.CreateRemappings(); - Build.Start("DATabase"); - - // Perform initial database and folder setup - if (!Directory.Exists(_datroot)) - { - Directory.CreateDirectory(_datroot); - } - if (!Directory.Exists(_outroot)) - { - Directory.CreateDirectory(_outroot); - } - DBTools.EnsureDatabase(_dbName, _connectionString); - - using (SqliteConnection dbc = new SqliteConnection(_connectionString)) - { - dbc.Open(); - - string query = "SELECT * FROM system"; - using (SqliteCommand slc = new SqliteCommand(query, dbc)) - { - using (SqliteDataReader sldr = slc.ExecuteReader()) - { - while (sldr.Read()) - { - int systemid = sldr.GetInt32(0); - string system = _datroot + Path.DirectorySeparatorChar + sldr.GetString(1) + " - " + sldr.GetString(2); - system = system.Trim(); - - if (!Directory.Exists(system)) - { - Directory.CreateDirectory(system); - } - } - } - } - } - } - - /// - /// List sources in the database - /// - /// This does not have an analogue in DATabaseTwo - private static void ListSources() - { - string query = @" -SELECT DISTINCT source.id, source.name, source.url -FROM source -ORDER BY source.name"; - 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.Warning("No sources found! Please add a system 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) + (!String.IsNullOrEmpty(sldr.GetString(2)) ? " (" + sldr.GetString(2) + ")" : "")); - } - } - } - } - return; - } - - /// - /// List systems in the database - /// - private static void ListSystems() - { - string query = @" -SELECT DISTINCT system.id, system.manufacturer, system.name -FROM system -ORDER BY system.manufacturer, system.name"; - 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.Warning("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; - } - - #endregion } } diff --git a/DATabase/DATabase.csproj b/DATabase/DATabase.csproj index d794fb24..fd42f586 100644 --- a/DATabase/DATabase.csproj +++ b/DATabase/DATabase.csproj @@ -113,6 +113,7 @@ + diff --git a/DATabase/Partials/DATabase_Helpers.cs b/DATabase/Partials/DATabase_Helpers.cs new file mode 100644 index 00000000..82d613a0 --- /dev/null +++ b/DATabase/Partials/DATabase_Helpers.cs @@ -0,0 +1,128 @@ +using System; +using System.IO; +using Mono.Data.Sqlite; + +using SabreTools.Helper; + +namespace SabreTools +{ + public partial class DATabase + { + #region Helper methods + + /// + /// Perform initial setup for the program + /// + private static void Setup() + { + Remapping.CreateRemappings(); + Build.Start("DATabase"); + + // Perform initial database and folder setup + if (!Directory.Exists(_datroot)) + { + Directory.CreateDirectory(_datroot); + } + if (!Directory.Exists(_outroot)) + { + Directory.CreateDirectory(_outroot); + } + DBTools.EnsureDatabase(_dbName, _connectionString); + + using (SqliteConnection dbc = new SqliteConnection(_connectionString)) + { + dbc.Open(); + + string query = "SELECT * FROM system"; + using (SqliteCommand slc = new SqliteCommand(query, dbc)) + { + using (SqliteDataReader sldr = slc.ExecuteReader()) + { + while (sldr.Read()) + { + int systemid = sldr.GetInt32(0); + string system = _datroot + Path.DirectorySeparatorChar + sldr.GetString(1) + " - " + sldr.GetString(2); + system = system.Trim(); + + if (!Directory.Exists(system)) + { + Directory.CreateDirectory(system); + } + } + } + } + } + } + + /// + /// List sources in the database + /// + /// This does not have an analogue in DATabaseTwo + private static void ListSources() + { + string query = @" +SELECT DISTINCT source.id, source.name, source.url +FROM source +ORDER BY source.name"; + 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.Warning("No sources found! Please add a system 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) + (!String.IsNullOrEmpty(sldr.GetString(2)) ? " (" + sldr.GetString(2) + ")" : "")); + } + } + } + } + return; + } + + /// + /// List systems in the database + /// + private static void ListSystems() + { + string query = @" +SELECT DISTINCT system.id, system.manufacturer, system.name +FROM system +ORDER BY system.manufacturer, system.name"; + 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.Warning("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; + } + + #endregion + } +}