mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DBTools] Add new param, update usage
This commit is contained in:
@@ -17,6 +17,7 @@ namespace SabreTools
|
||||
private Logger _logger;
|
||||
|
||||
// Private required variables
|
||||
private static string _dbSchema = "Headerer";
|
||||
private static string _dbName = "Headerer.sqlite";
|
||||
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
||||
|
||||
@@ -48,7 +49,7 @@ namespace SabreTools
|
||||
// Perform initial setup and verification
|
||||
Logger logger = new Logger(true, "headerer.log");
|
||||
logger.Start();
|
||||
DBTools.EnsureDatabase(_dbName, _connectionString);
|
||||
DBTools.EnsureDatabase(_dbSchema, _dbName, _connectionString);
|
||||
|
||||
// Credits take precidence over all
|
||||
if ((new List<string>(args)).Contains("--credits"))
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace SabreTools
|
||||
|
||||
// Other private variables
|
||||
private string _config = "config.xml";
|
||||
private string _dbSchema = "rombasharp";
|
||||
private string _connectionString;
|
||||
private Logger _logger;
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace SabreTools
|
||||
_logger = logger;
|
||||
|
||||
InitializeConfiguration();
|
||||
InitializeDatabase();
|
||||
DBTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
@@ -280,51 +281,6 @@ namespace SabreTools
|
||||
_port = port;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the Romba database
|
||||
/// </summary>
|
||||
private void InitializeDatabase()
|
||||
{
|
||||
// Make sure the db is set
|
||||
if (String.IsNullOrEmpty(_db))
|
||||
{
|
||||
_db = "db.sqlite";
|
||||
_connectionString = "Data Source=" + _db + ";Version = 3;";
|
||||
}
|
||||
|
||||
// Make sure the file exists
|
||||
if (!File.Exists(_db))
|
||||
{
|
||||
SqliteConnection.CreateFile(_db);
|
||||
}
|
||||
|
||||
// Connect to the file
|
||||
SqliteConnection dbc = new SqliteConnection(_connectionString);
|
||||
dbc.Open();
|
||||
|
||||
// Initialize the database schema
|
||||
try
|
||||
{
|
||||
string query = @"
|
||||
CREATE TABLE IF NOT EXISTS data (
|
||||
'id' INTEGER NOT NULL
|
||||
'key' TEXT NOT NULL
|
||||
'value' TEXT NOT NULL
|
||||
)";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
slc.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close the database connection
|
||||
dbc.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populate or refresh the database information
|
||||
/// </summary>
|
||||
|
||||
@@ -12,19 +12,20 @@ namespace SabreTools.Helper
|
||||
/// <summary>
|
||||
/// Ensure that the databse exists and has the proper schema
|
||||
/// </summary>
|
||||
/// <param name="type">Schema type to use</param>
|
||||
/// <param name="db">Name of the databse</param>
|
||||
/// <param name="connectionString">Connection string for SQLite</param>
|
||||
public static void EnsureDatabase(string db, string connectionString)
|
||||
public static void EnsureDatabase(string type, string db, string connectionString)
|
||||
{
|
||||
// Set the type to lowercase
|
||||
type = type.ToLowerInvariant();
|
||||
|
||||
// Make sure the file exists
|
||||
if (!File.Exists(db))
|
||||
{
|
||||
SqliteConnection.CreateFile(db);
|
||||
}
|
||||
|
||||
//Get "type" from the filename
|
||||
string type = Path.GetFileNameWithoutExtension(db);
|
||||
|
||||
// Connect to the file
|
||||
SqliteConnection dbc = new SqliteConnection(connectionString);
|
||||
dbc.Open();
|
||||
@@ -32,7 +33,18 @@ namespace SabreTools.Helper
|
||||
// Make sure the database has the correct schema
|
||||
try
|
||||
{
|
||||
if (type == "Headerer")
|
||||
if (type == "rombasharp")
|
||||
{
|
||||
string query = @"
|
||||
CREATE TABLE IF NOT EXISTS data (
|
||||
'id' INTEGER NOT NULL
|
||||
'key' TEXT NOT NULL
|
||||
'value' TEXT NOT NULL
|
||||
)";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
slc.ExecuteNonQuery();
|
||||
}
|
||||
else if (type == "headerer")
|
||||
{
|
||||
string query = @"
|
||||
CREATE TABLE IF NOT EXISTS data (
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace SabreTools
|
||||
{
|
||||
Directory.CreateDirectory(_outroot);
|
||||
}
|
||||
DBTools.EnsureDatabase(_dbName, _connectionString);
|
||||
DBTools.EnsureDatabase(_dbSchema, _dbName, _connectionString);
|
||||
|
||||
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace SabreTools
|
||||
// Private required variables
|
||||
private static string _datroot = "DATS";
|
||||
private static string _outroot = "Output";
|
||||
private static string _dbSchema = "dats";
|
||||
private static string _dbName = "dats.sqlite";
|
||||
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user