mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] Get rid of rest of non-library usings
This commit is contained in:
@@ -314,12 +314,9 @@ namespace SabreTools
|
||||
|
||||
// Populate the List from the database
|
||||
string query = "SELECT UNIQUE value FROM data WHERE key=\"dat\"";
|
||||
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
||||
{
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
SqliteConnection dbc = new SqliteConnection(_connectionString);
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
SqliteDataReader sldr = slc.ExecuteReader();
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
sldr.Read();
|
||||
@@ -329,8 +326,9 @@ namespace SabreTools
|
||||
databaseDats.Add(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slc.Dispose();
|
||||
sldr.Dispose();
|
||||
|
||||
// Now create a Dictionary of dats to parse from what's not in the database (SHA-1, Path)
|
||||
Dictionary<string, string> toscan = new Dictionary<string, string>();
|
||||
@@ -372,10 +370,9 @@ namespace SabreTools
|
||||
+ "(key=\"crc\" AND (value=\"" + rom.CRC + "\" OR value=\"null\"))"
|
||||
+ "AND (key=\"md5\" AND value=\"" + rom.MD5 + "\" OR value=\"null\"))"
|
||||
+ "AND (key=\"sha1\" AND value=\"" + rom.SHA1 + "\" OR value=\"null\")))";
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
slc = new SqliteCommand(query, dbc);
|
||||
sldr = slc.ExecuteReader();
|
||||
|
||||
// If the hash exists in the database, add the dat hash for that id
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
@@ -383,55 +380,44 @@ namespace SabreTools
|
||||
string id = sldr.GetString(0);
|
||||
|
||||
string squery = "INSERT INTO data (id, key, value) VALUES (\"" + id + "\", \"dat\", \"" + key + "\")";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
SqliteCommand sslc = new SqliteCommand(squery, dbc);
|
||||
sslc.ExecuteNonQuery();
|
||||
}
|
||||
sslc.Dispose();
|
||||
}
|
||||
|
||||
// If it doesn't exist, add the hash and the dat hash for a new id
|
||||
else
|
||||
{
|
||||
string squery = "INSERT INTO data (key, value) VALUES (\"size\", \"" + rom.Size + "\")";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
SqliteCommand sslc = new SqliteCommand(squery, dbc);
|
||||
sslc.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
long id = -1;
|
||||
|
||||
squery = "SELECT last_insertConstants.Rowid()";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
sslc = new SqliteCommand(squery, dbc);
|
||||
id = (long)sslc.ExecuteScalar();
|
||||
}
|
||||
|
||||
squery = "INSERT INTO data (id, key, value) VALUES (\"" + id + "\", \"crc\", \"" + rom.CRC + "\"),"
|
||||
+ " (\"" + id + "\", \"md5\", \"" + rom.MD5 + "\"),"
|
||||
+ " (\"" + id + "\", \"sha1\", \"" + rom.SHA1 + "\"),"
|
||||
+ " (\"" + id + "\", \"dat\", \"" + key + "\"),"
|
||||
+ " (\"" + id + "\", \"exists\", \"false\")";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
sslc = new SqliteCommand(squery, dbc);
|
||||
sslc.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now loop through and remove all references to old Dats
|
||||
// TODO: Remove orphaned files as well
|
||||
foreach (string dathash in databaseDats)
|
||||
{
|
||||
query = "DELETE FROM data WHERE key=\"dat\" AND value=\"" + dathash + "\"";
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
slc = new SqliteCommand(query, dbc);
|
||||
slc.ExecuteNonQuery();
|
||||
}
|
||||
slc.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -982,12 +982,13 @@ namespace SabreTools.Helper
|
||||
return;
|
||||
}
|
||||
|
||||
// Now get the hash of the stream
|
||||
// Create the hashers
|
||||
uint tempCrc;
|
||||
using (OptimizedCRC crc = new OptimizedCRC())
|
||||
using (MD5 md5 = System.Security.Cryptography.MD5.Create())
|
||||
using (SHA1 sha1 = System.Security.Cryptography.SHA1.Create())
|
||||
{
|
||||
OptimizedCRC crc = new OptimizedCRC();
|
||||
MD5 md5 = System.Security.Cryptography.MD5.Create();
|
||||
SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
|
||||
|
||||
// Now get the hash of the stream
|
||||
BinaryReader fs = new BinaryReader(stream);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
@@ -1006,7 +1007,11 @@ namespace SabreTools.Helper
|
||||
tempCrc = crc.UnsignedValue;
|
||||
_md5 = md5.Hash;
|
||||
_sha1 = sha1.Hash;
|
||||
}
|
||||
|
||||
// Dispose of the hashers
|
||||
crc.Dispose();
|
||||
md5.Dispose();
|
||||
sha1.Dispose();
|
||||
|
||||
if (_compressionMethod == CompressionMethod.Deflated)
|
||||
{
|
||||
|
||||
@@ -149,18 +149,14 @@ namespace SabreTools
|
||||
{
|
||||
bool exists = false;
|
||||
|
||||
string query = @"SELECT * FROM data WHERE sha1='" + SHA1 + "' AND header='" + header + "'";
|
||||
using (SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString))
|
||||
{
|
||||
// Open the database connection
|
||||
SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString);
|
||||
dbc.Open();
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -168,15 +164,14 @@ namespace SabreTools
|
||||
SHA1 + "', " +
|
||||
"'" + header + "', " +
|
||||
"'" + type.ToString() + "')";
|
||||
using (SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString))
|
||||
{
|
||||
dbc.Open();
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
slc = new SqliteCommand(query, dbc);
|
||||
_logger.Log("Result of inserting header: " + slc.ExecuteNonQuery());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dispose of database objects
|
||||
slc.Dispose();
|
||||
sldr.Dispose();
|
||||
dbc.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -186,20 +181,22 @@ namespace SabreTools
|
||||
/// <returns>True if a header was found and appended, false otherwise</returns>
|
||||
private bool RestoreHeader(string file)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
// First, get the SHA-1 hash of the file
|
||||
Rom rom = FileTools.GetSingleFileInfo(file);
|
||||
|
||||
// Then try to pull the corresponding headers from the database
|
||||
string header = "";
|
||||
|
||||
string query = @"SELECT header, type FROM data WHERE sha1='" + rom.SHA1 + "'";
|
||||
using (SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString))
|
||||
{
|
||||
// Open the database connection
|
||||
SqliteConnection dbc = new SqliteConnection(Constants.HeadererConnectionString);
|
||||
dbc.Open();
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
|
||||
string query = @"SELECT header, type FROM data WHERE sha1='" + rom.SHA1 + "'";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
SqliteDataReader sldr = slc.ExecuteReader();
|
||||
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
int sub = 0;
|
||||
@@ -218,13 +215,15 @@ namespace SabreTools
|
||||
else
|
||||
{
|
||||
_logger.Warning("No matching header could be found!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
// Dispose of database objects
|
||||
slc.Dispose();
|
||||
sldr.Dispose();
|
||||
dbc.Dispose();
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace SabreTools.Helper
|
||||
SqliteConnection.CreateFile(db);
|
||||
}
|
||||
|
||||
// Connect to the file
|
||||
// Open the database connection
|
||||
SqliteConnection dbc = new SqliteConnection(connectionString);
|
||||
dbc.Open();
|
||||
|
||||
@@ -44,6 +44,7 @@ CREATE TABLE IF NOT EXISTS data (
|
||||
)";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
slc.ExecuteNonQuery();
|
||||
slc.Dispose();
|
||||
}
|
||||
else if (type == "headerer")
|
||||
{
|
||||
@@ -56,6 +57,7 @@ CREATE TABLE IF NOT EXISTS data (
|
||||
)";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
slc.ExecuteNonQuery();
|
||||
slc.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -64,124 +66,7 @@ CREATE TABLE IF NOT EXISTS data (
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close and return the database connection
|
||||
dbc.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new source to the database if it doesn't already exist
|
||||
/// </summary>
|
||||
/// <param name="name">Source name</param>
|
||||
/// <param name="url">Source URL(s)</param>
|
||||
/// <param name="connectionString">Connection string for SQLite</param>
|
||||
/// <returns>True if the source existed or could be added, false otherwise</returns>
|
||||
public static bool AddSource(string name, string url, string connectionString)
|
||||
{
|
||||
string query = "SELECT id, name, url FROM source WHERE name='" + name + "'";
|
||||
using (SqliteConnection dbc = new SqliteConnection(connectionString))
|
||||
{
|
||||
dbc.Open();
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
// If nothing is found, add the source
|
||||
if (!sldr.HasRows)
|
||||
{
|
||||
string squery = "INSERT INTO source (name, url) VALUES ('" + name + "', '" + url + "')";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
return sslc.ExecuteNonQuery() >= 1;
|
||||
}
|
||||
}
|
||||
// Otherwise, update the source URL if it's different
|
||||
else
|
||||
{
|
||||
sldr.Read();
|
||||
if (url != sldr.GetString(2))
|
||||
{
|
||||
string squery = "UPDATE source SET url='" + url + "' WHERE id=" + sldr.GetInt32(0);
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
return sslc.ExecuteNonQuery() >= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an existing source from the database
|
||||
/// </summary>
|
||||
/// <param name="id">Source ID to be removed from the database</param>
|
||||
/// <param name="connectionString">Connection string for SQLite</param>
|
||||
/// <returns>True if the source was removed, false otherwise</returns>
|
||||
public static bool RemoveSource(int id, string connectionString)
|
||||
{
|
||||
string query = "DELETE FROM source WHERE id=" + id;
|
||||
using (SqliteConnection dbc = new SqliteConnection(connectionString))
|
||||
{
|
||||
dbc.Open();
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
return slc.ExecuteNonQuery() >= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new system to the database if it doesn't already exist
|
||||
/// </summary>
|
||||
/// <param name="manufacturer">Manufacturer name</param>
|
||||
/// <param name="system">System name</param>
|
||||
/// <param name="connectionString">Connection string for SQLite</param>
|
||||
/// <returns>True if the system existed or could be added, false otherwise</returns>
|
||||
public static bool AddSystem(string manufacturer, string system, string connectionString)
|
||||
{
|
||||
string query = "SELECT id, manufacturer, name FROM system WHERE manufacturer='" + manufacturer + "' AND system='" + system + "'";
|
||||
using (SqliteConnection dbc = new SqliteConnection(connectionString))
|
||||
{
|
||||
dbc.Open();
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
// If nothing is found, add the system
|
||||
if (!sldr.HasRows)
|
||||
{
|
||||
string squery = "INSERT INTO name (manufacturer, system) VALUES ('" + manufacturer + "', '" + system + "')";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
return sslc.ExecuteNonQuery() >= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an existing system from the database
|
||||
/// </summary>
|
||||
/// <param name="id">System ID to be removed from the database</param>
|
||||
/// <param name="connectionString">Connection string for SQLite</param>
|
||||
/// <returns>True if the system was removed, false otherwise</returns>
|
||||
public static bool RemoveSystem(int id, string connectionString)
|
||||
{
|
||||
string query = "DELETE FROM system WHERE id=" + id;
|
||||
using (SqliteConnection dbc = new SqliteConnection(connectionString))
|
||||
{
|
||||
dbc.Open();
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
return slc.ExecuteNonQuery() >= 1;
|
||||
}
|
||||
dbc.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -726,10 +726,11 @@ namespace SabreTools.Helper
|
||||
|
||||
try
|
||||
{
|
||||
using (OptimizedCRC crc = new OptimizedCRC())
|
||||
using (MD5 md5 = MD5.Create())
|
||||
using (SHA1 sha1 = SHA1.Create())
|
||||
{
|
||||
// Initialize the hashers
|
||||
OptimizedCRC crc = new OptimizedCRC();
|
||||
MD5 md5 = MD5.Create();
|
||||
SHA1 sha1 = SHA1.Create();
|
||||
|
||||
// Seek to the starting position, if one is set
|
||||
if (offset > 0)
|
||||
{
|
||||
@@ -764,7 +765,11 @@ namespace SabreTools.Helper
|
||||
sha1.TransformFinalBlock(buffer, 0, 0);
|
||||
rom.SHA1 = BitConverter.ToString(sha1.Hash).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
|
||||
// Dispose of the hashers
|
||||
crc.Dispose();
|
||||
md5.Dispose();
|
||||
sha1.Dispose();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user