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 Logger _logger;
|
||||||
|
|
||||||
// Private required variables
|
// Private required variables
|
||||||
|
private static string _dbSchema = "Headerer";
|
||||||
private static string _dbName = "Headerer.sqlite";
|
private static string _dbName = "Headerer.sqlite";
|
||||||
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ namespace SabreTools
|
|||||||
// Perform initial setup and verification
|
// Perform initial setup and verification
|
||||||
Logger logger = new Logger(true, "headerer.log");
|
Logger logger = new Logger(true, "headerer.log");
|
||||||
logger.Start();
|
logger.Start();
|
||||||
DBTools.EnsureDatabase(_dbName, _connectionString);
|
DBTools.EnsureDatabase(_dbSchema, _dbName, _connectionString);
|
||||||
|
|
||||||
// Credits take precidence over all
|
// Credits take precidence over all
|
||||||
if ((new List<string>(args)).Contains("--credits"))
|
if ((new List<string>(args)).Contains("--credits"))
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace SabreTools
|
|||||||
|
|
||||||
// Other private variables
|
// Other private variables
|
||||||
private string _config = "config.xml";
|
private string _config = "config.xml";
|
||||||
|
private string _dbSchema = "rombasharp";
|
||||||
private string _connectionString;
|
private string _connectionString;
|
||||||
private Logger _logger;
|
private Logger _logger;
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ namespace SabreTools
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
InitializeConfiguration();
|
InitializeConfiguration();
|
||||||
InitializeDatabase();
|
DBTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
@@ -280,51 +281,6 @@ namespace SabreTools
|
|||||||
_port = port;
|
_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>
|
/// <summary>
|
||||||
/// Populate or refresh the database information
|
/// Populate or refresh the database information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -12,19 +12,20 @@ namespace SabreTools.Helper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ensure that the databse exists and has the proper schema
|
/// Ensure that the databse exists and has the proper schema
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="type">Schema type to use</param>
|
||||||
/// <param name="db">Name of the databse</param>
|
/// <param name="db">Name of the databse</param>
|
||||||
/// <param name="connectionString">Connection string for SQLite</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
|
// Make sure the file exists
|
||||||
if (!File.Exists(db))
|
if (!File.Exists(db))
|
||||||
{
|
{
|
||||||
SqliteConnection.CreateFile(db);
|
SqliteConnection.CreateFile(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get "type" from the filename
|
|
||||||
string type = Path.GetFileNameWithoutExtension(db);
|
|
||||||
|
|
||||||
// Connect to the file
|
// Connect to the file
|
||||||
SqliteConnection dbc = new SqliteConnection(connectionString);
|
SqliteConnection dbc = new SqliteConnection(connectionString);
|
||||||
dbc.Open();
|
dbc.Open();
|
||||||
@@ -32,7 +33,18 @@ namespace SabreTools.Helper
|
|||||||
// Make sure the database has the correct schema
|
// Make sure the database has the correct schema
|
||||||
try
|
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 = @"
|
string query = @"
|
||||||
CREATE TABLE IF NOT EXISTS data (
|
CREATE TABLE IF NOT EXISTS data (
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
Directory.CreateDirectory(_outroot);
|
Directory.CreateDirectory(_outroot);
|
||||||
}
|
}
|
||||||
DBTools.EnsureDatabase(_dbName, _connectionString);
|
DBTools.EnsureDatabase(_dbSchema, _dbName, _connectionString);
|
||||||
|
|
||||||
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ namespace SabreTools
|
|||||||
// Private required variables
|
// Private required variables
|
||||||
private static string _datroot = "DATS";
|
private static string _datroot = "DATS";
|
||||||
private static string _outroot = "Output";
|
private static string _outroot = "Output";
|
||||||
private static string _dbName = "dats.sqlite";
|
private static string _dbSchema = "dats";
|
||||||
|
private static string _dbName = "dats.sqlite";
|
||||||
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
||||||
|
|
||||||
private static Logger _logger;
|
private static Logger _logger;
|
||||||
|
|||||||
Reference in New Issue
Block a user