mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] More rearranging
This commit is contained in:
@@ -294,7 +294,7 @@ namespace SabreTools
|
||||
// Make sure the file exists
|
||||
if (!File.Exists(_db))
|
||||
{
|
||||
DBTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||
DatabaseTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||
}
|
||||
|
||||
// Make sure the dats dir is set
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace SabreTools
|
||||
// Perform initial setup and verification
|
||||
_logger = new Logger(true, "romba.log");
|
||||
InitializeConfiguration();
|
||||
DBTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||
DatabaseTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||
|
||||
// If output is being redirected, don't allow clear screens
|
||||
if (!Console.IsOutputRedirected)
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
<Compile Include="Skippers\Skippers.cs" />
|
||||
<Compile Include="Tools\ArchiveTools.cs" />
|
||||
<Compile Include="Tools\FileTools.cs" />
|
||||
<Compile Include="Tools\DBTools.cs" />
|
||||
<Compile Include="Tools\DatabaseTools.cs" />
|
||||
<Compile Include="Data\Enums.cs" />
|
||||
<Compile Include="Objects\Logger.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace SabreTools.Helper
|
||||
|
||||
#endregion
|
||||
|
||||
#region Archive Extraction
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
@@ -234,7 +234,7 @@ namespace SabreTools.Helper
|
||||
|
||||
#endregion
|
||||
|
||||
#region Archive Information
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of RomData objects from the header values in an archive
|
||||
@@ -526,7 +526,7 @@ namespace SabreTools.Helper
|
||||
|
||||
#endregion
|
||||
|
||||
#region Archive Writing
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Copy a file to an output archive
|
||||
|
||||
@@ -7,8 +7,44 @@ namespace SabreTools.Helper
|
||||
/// <summary>
|
||||
/// All general database operations
|
||||
/// </summary>
|
||||
public class DBTools
|
||||
public class DatabaseTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Add a header to the database
|
||||
/// </summary>
|
||||
/// <param name="header">String representing the header bytes</param>
|
||||
/// <param name="SHA1">SHA-1 of the deheadered file</param>
|
||||
/// <param name="type">HeaderType representing the detected header</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
public static void AddHeaderToDatabase(string header, string SHA1, HeaderType type, Logger logger)
|
||||
{
|
||||
bool exists = false;
|
||||
|
||||
// Open the database connection
|
||||
SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString);
|
||||
dbc.Open();
|
||||
|
||||
string query = @"SELECT * FROM data WHERE sha1='" + SHA1 + "' AND header='" + header + "'";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
SqliteDataReader sldr = slc.ExecuteReader();
|
||||
exists = sldr.HasRows;
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
query = @"INSERT INTO data (sha1, header, type) VALUES ('" +
|
||||
SHA1 + "', " +
|
||||
"'" + header + "', " +
|
||||
"'" + type.ToString() + "')";
|
||||
slc = new SqliteCommand(query, dbc);
|
||||
logger.Log("Result of inserting header: " + slc.ExecuteNonQuery());
|
||||
}
|
||||
|
||||
// Dispose of database objects
|
||||
slc.Dispose();
|
||||
sldr.Dispose();
|
||||
dbc.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure that the databse exists and has the proper schema
|
||||
/// </summary>
|
||||
@@ -251,48 +251,12 @@ namespace SabreTools.Helper
|
||||
|
||||
// Now add the information to the database if it's not already there
|
||||
Rom rom = GetSingleFileInfo(newfile);
|
||||
AddHeaderToDatabase(hstr, rom.SHA1, type, logger);
|
||||
DatabaseTools.AddHeaderToDatabase(hstr, rom.SHA1, type, logger);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a header to the database
|
||||
/// </summary>
|
||||
/// <param name="header">String representing the header bytes</param>
|
||||
/// <param name="SHA1">SHA-1 of the deheadered file</param>
|
||||
/// <param name="type">HeaderType representing the detected header</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
private static void AddHeaderToDatabase(string header, string SHA1, HeaderType type, Logger logger)
|
||||
{
|
||||
bool exists = false;
|
||||
|
||||
// Open the database connection
|
||||
SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString);
|
||||
dbc.Open();
|
||||
|
||||
string query = @"SELECT * FROM data WHERE sha1='" + SHA1 + "' AND header='" + header + "'";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
SqliteDataReader sldr = slc.ExecuteReader();
|
||||
exists = sldr.HasRows;
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
query = @"INSERT INTO data (sha1, header, type) VALUES ('" +
|
||||
SHA1 + "', " +
|
||||
"'" + header + "', " +
|
||||
"'" + type.ToString() + "')";
|
||||
slc = new SqliteCommand(query, dbc);
|
||||
logger.Log("Result of inserting header: " + slc.ExecuteNonQuery());
|
||||
}
|
||||
|
||||
// Dispose of database objects
|
||||
slc.Dispose();
|
||||
sldr.Dispose();
|
||||
dbc.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect and replace header(s) to the given file
|
||||
/// </summary>
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace SabreTools
|
||||
Console.Clear();
|
||||
}
|
||||
Build.Start("SabreTools");
|
||||
DBTools.EnsureDatabase(Constants.HeadererDbSchema, Constants.HeadererFileName, Constants.HeadererConnectionString);
|
||||
DatabaseTools.EnsureDatabase(Constants.HeadererDbSchema, Constants.HeadererFileName, Constants.HeadererConnectionString);
|
||||
|
||||
// Credits take precidence over all
|
||||
if ((new List<string>(args)).Contains("--credits"))
|
||||
|
||||
Reference in New Issue
Block a user