mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] Code cleanup and move
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Mono.Data.Sqlite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Helper.Data;
|
||||
|
||||
@@ -27,6 +28,9 @@ namespace SabreTools.Helper.Tools
|
||||
{
|
||||
bool exists = false;
|
||||
|
||||
// Ensure the database exists
|
||||
EnsureDatabase(Constants.HeadererDbSchema, Constants.HeadererFileName, Constants.HeadererConnectionString);
|
||||
|
||||
// Open the database connection
|
||||
SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString);
|
||||
dbc.Open();
|
||||
@@ -153,5 +157,48 @@ CREATE TABLE IF NOT EXISTS data (
|
||||
dbc.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve headers from the database
|
||||
/// </summary>
|
||||
/// <param name="SHA1">SHA-1 of the deheadered file</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
/// <returns>List of strings representing the headers to add</returns>
|
||||
public static List<string> RetrieveHeadersFromDatabase(string SHA1, Logger logger)
|
||||
{
|
||||
// Ensure the database exists
|
||||
EnsureDatabase(Constants.HeadererDbSchema, Constants.HeadererFileName, Constants.HeadererConnectionString);
|
||||
|
||||
// Open the database connection
|
||||
SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString);
|
||||
dbc.Open();
|
||||
|
||||
// Create the output list of headers
|
||||
List<string> headers = new List<string>();
|
||||
|
||||
string query = @"SELECT header, type FROM data WHERE sha1='" + SHA1 + "'";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
SqliteDataReader sldr = slc.ExecuteReader();
|
||||
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
while (sldr.Read())
|
||||
{
|
||||
logger.Verbose("Found match with rom type " + sldr.GetString(1));
|
||||
headers.Add(sldr.GetString(0));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warning("No matching header could be found!");
|
||||
}
|
||||
|
||||
// Dispose of database objects
|
||||
slc.Dispose();
|
||||
sldr.Dispose();
|
||||
dbc.Dispose();
|
||||
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user