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
|
// Make sure the file exists
|
||||||
if (!File.Exists(_db))
|
if (!File.Exists(_db))
|
||||||
{
|
{
|
||||||
DBTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
DatabaseTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the dats dir is set
|
// Make sure the dats dir is set
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace SabreTools
|
|||||||
// Perform initial setup and verification
|
// Perform initial setup and verification
|
||||||
_logger = new Logger(true, "romba.log");
|
_logger = new Logger(true, "romba.log");
|
||||||
InitializeConfiguration();
|
InitializeConfiguration();
|
||||||
DBTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
DatabaseTools.EnsureDatabase(_dbSchema, _db, _connectionString);
|
||||||
|
|
||||||
// If output is being redirected, don't allow clear screens
|
// If output is being redirected, don't allow clear screens
|
||||||
if (!Console.IsOutputRedirected)
|
if (!Console.IsOutputRedirected)
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
<Compile Include="Skippers\Skippers.cs" />
|
<Compile Include="Skippers\Skippers.cs" />
|
||||||
<Compile Include="Tools\ArchiveTools.cs" />
|
<Compile Include="Tools\ArchiveTools.cs" />
|
||||||
<Compile Include="Tools\FileTools.cs" />
|
<Compile Include="Tools\FileTools.cs" />
|
||||||
<Compile Include="Tools\DBTools.cs" />
|
<Compile Include="Tools\DatabaseTools.cs" />
|
||||||
<Compile Include="Data\Enums.cs" />
|
<Compile Include="Data\Enums.cs" />
|
||||||
<Compile Include="Objects\Logger.cs" />
|
<Compile Include="Objects\Logger.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace SabreTools.Helper
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Archive Extraction
|
#region Extraction
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempt to extract a file as an archive
|
/// Attempt to extract a file as an archive
|
||||||
@@ -234,7 +234,7 @@ namespace SabreTools.Helper
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Archive Information
|
#region Information
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate a list of RomData objects from the header values in an archive
|
/// Generate a list of RomData objects from the header values in an archive
|
||||||
@@ -526,7 +526,7 @@ namespace SabreTools.Helper
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Archive Writing
|
#region Writing
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy a file to an output archive
|
/// Copy a file to an output archive
|
||||||
|
|||||||
@@ -7,8 +7,44 @@ namespace SabreTools.Helper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// All general database operations
|
/// All general database operations
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Ensure that the databse exists and has the proper schema
|
/// Ensure that the databse exists and has the proper schema
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -251,48 +251,12 @@ namespace SabreTools.Helper
|
|||||||
|
|
||||||
// Now add the information to the database if it's not already there
|
// Now add the information to the database if it's not already there
|
||||||
Rom rom = GetSingleFileInfo(newfile);
|
Rom rom = GetSingleFileInfo(newfile);
|
||||||
AddHeaderToDatabase(hstr, rom.SHA1, type, logger);
|
DatabaseTools.AddHeaderToDatabase(hstr, rom.SHA1, type, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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>
|
/// <summary>
|
||||||
/// Detect and replace header(s) to the given file
|
/// Detect and replace header(s) to the given file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace SabreTools
|
|||||||
Console.Clear();
|
Console.Clear();
|
||||||
}
|
}
|
||||||
Build.Start("SabreTools");
|
Build.Start("SabreTools");
|
||||||
DBTools.EnsureDatabase(Constants.HeadererDbSchema, Constants.HeadererFileName, Constants.HeadererConnectionString);
|
DatabaseTools.EnsureDatabase(Constants.HeadererDbSchema, Constants.HeadererFileName, Constants.HeadererConnectionString);
|
||||||
|
|
||||||
// Credits take precidence over all
|
// Credits take precidence over all
|
||||||
if ((new List<string>(args)).Contains("--credits"))
|
if ((new List<string>(args)).Contains("--credits"))
|
||||||
|
|||||||
Reference in New Issue
Block a user