mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[RombaSharp] More code for update
This commit is contained in:
@@ -322,6 +322,9 @@ namespace SabreTools
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
sldr.Read();
|
||||
string hash = sldr.GetString(0);
|
||||
if (!databaseDats.Contains(hash))
|
||||
{
|
||||
@@ -365,12 +368,59 @@ namespace SabreTools
|
||||
// Loop through the parsed entries
|
||||
foreach (string romkey in tempdat.Files.Keys)
|
||||
{
|
||||
// So, we have an issue. Finding each of the particular crc/md5/sha1 combinations
|
||||
// that need to be added compared to what's already in the database is likely to
|
||||
// be difficult with the current keyvault structure. Can we move to a non-kv since
|
||||
// we're using a database that we are fully aware of anyway? Then we can definitely
|
||||
// have a hash table and a dat table and a mapping between the two. Slower, but works
|
||||
// more efficiently for my format. Get input?
|
||||
foreach (Rom rom in tempdat.Files[romkey])
|
||||
{
|
||||
query = "SELECT id FROM data WHERE key=\"size\" AND value=\"" + rom.HashData.Size + "\" AND ("
|
||||
+ "(key=\"crc\" AND (value=\"" + rom.HashData.CRC + "\" OR value=\"null\"))"
|
||||
+ "AND (key=\"md5\" AND value=\"" + rom.HashData.MD5 + "\" OR value=\"null\"))"
|
||||
+ "AND (key=\"sha1\" AND value=\"" + rom.HashData.SHA1 + "\" OR value=\"null\")))";
|
||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||
{
|
||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||
{
|
||||
// If the hash exists in the database, add the dat hash for that id
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
sldr.Read();
|
||||
string id = sldr.GetString(0);
|
||||
|
||||
string squery = "INSERT INTO data (id, key, value) VALUES (\"" + id + "\", \"dat\", \"" + key + "\")";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
sslc.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
// 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.HashData.Size + "\")";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
sslc.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
long id = -1;
|
||||
|
||||
squery = "SELECT last_insertConstants.Rowid()";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
id = (long)sslc.ExecuteScalar();
|
||||
}
|
||||
|
||||
squery = "INSERT INTO data (id, key, value) VALUES (\"" + id + "\", \"crc\", \"" + rom.HashData.CRC + "\"),"
|
||||
+ " (\"" + id + "\", \"md5\", \"" + rom.HashData.MD5 + "\"),"
|
||||
+ " (\"" + id + "\", \"sha1\", \"" + rom.HashData.SHA1 + "\"),"
|
||||
+ " (\"" + id + "\", \"dat\", \"" + key + "\")";
|
||||
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
|
||||
{
|
||||
sslc.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS data (
|
||||
'id' INTEGER NOT NULL
|
||||
'key' TEXT NOT NULL
|
||||
'value' TEXT NOT NULL
|
||||
PRIMARY KEY (id, key, value)
|
||||
)";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
slc.ExecuteNonQuery();
|
||||
|
||||
Reference in New Issue
Block a user