mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DATabase] Separate out helpers to partial class
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Mono.Data.Sqlite;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
|
||||||
|
|
||||||
using SabreTools.Helper;
|
using SabreTools.Helper;
|
||||||
|
|
||||||
@@ -684,122 +682,5 @@ namespace SabreTools
|
|||||||
_logger.Close();
|
_logger.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Helper methods
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Perform initial setup for the program
|
|
||||||
/// </summary>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// List sources in the database
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>This does not have an analogue in DATabaseTwo</remarks>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// List systems in the database
|
|
||||||
/// </summary>
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,7 @@
|
|||||||
<Compile Include="DATabase.cs" />
|
<Compile Include="DATabase.cs" />
|
||||||
<Compile Include="ImportExport\ImportTwo.cs" />
|
<Compile Include="ImportExport\ImportTwo.cs" />
|
||||||
<Compile Include="MergeDiff.cs" />
|
<Compile Include="MergeDiff.cs" />
|
||||||
|
<Compile Include="Partials\DATabase_Helpers.cs" />
|
||||||
<Compile Include="Partials\DATabase_Inits.cs" />
|
<Compile Include="Partials\DATabase_Inits.cs" />
|
||||||
<Compile Include="Partials\DATabase_Menus.cs" />
|
<Compile Include="Partials\DATabase_Menus.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
128
DATabase/Partials/DATabase_Helpers.cs
Normal file
128
DATabase/Partials/DATabase_Helpers.cs
Normal file
@@ -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
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform initial setup for the program
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List sources in the database
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>This does not have an analogue in DATabaseTwo</remarks>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List systems in the database
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user