refactor: added additional hash check on ingestion
This commit is contained in:
@@ -83,8 +83,19 @@ if (Directory.Exists(tosecXML))
|
||||
Console.WriteLine("\r " + statusOutput.PadRight(lineFileNameLength, ' ') + "\r");
|
||||
lineFileNameLength = statusOutput.Length;
|
||||
|
||||
Console.WriteLine(" ==> Parsing file");
|
||||
// check tosec file md5
|
||||
Console.WriteLine(" ==> Checking input file ");
|
||||
Common.hashObject hashObject = new Common.hashObject(tosecXMLFile);
|
||||
sql = "SELECT * FROM signatures_sources WHERE sourcemd5=@sourcemd5";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("sourcemd5", hashObject.md5hash);
|
||||
sigDB = db.ExecuteCMD(sql, dbDict);
|
||||
|
||||
if (sigDB.Rows.Count == 0)
|
||||
{
|
||||
// start parsing file
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
Console.WriteLine(" ==> Parsing file ");
|
||||
TosecParser tosecParser = new TosecParser();
|
||||
RomSignatureObject tosecObject = tosecParser.Parse(tosecXMLFile);
|
||||
|
||||
@@ -94,6 +105,9 @@ if (Directory.Exists(tosecXML))
|
||||
bool processGames = false;
|
||||
if (tosecObject.SourceMd5 != null)
|
||||
{
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
Console.WriteLine(" ==> Storing file in database ");
|
||||
|
||||
sql = "SELECT * FROM signatures_sources WHERE sourcemd5=@sourcemd5";
|
||||
dbDict = new Dictionary<string, object>();
|
||||
dbDict.Add("name", Common.ReturnValueIfNull(tosecObject.Name, ""));
|
||||
@@ -163,7 +177,8 @@ if (Directory.Exists(tosecXML))
|
||||
sigDB = db.ExecuteCMD(sql, dbDict);
|
||||
|
||||
gameSystem = int.Parse(sigDB.Rows[0][0].ToString());
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
gameSystem = int.Parse(sigDB.Rows[0][0].ToString());
|
||||
}
|
||||
@@ -232,7 +247,8 @@ if (Directory.Exists(tosecXML))
|
||||
if (romObject.flags.Count > 0)
|
||||
{
|
||||
dbDict.Add("flags", Newtonsoft.Json.JsonConvert.SerializeObject(romObject.flags));
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
dbDict.Add("flags", "[ ]");
|
||||
}
|
||||
@@ -265,4 +281,5 @@ if (Directory.Exists(tosecXML))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace gaseous_tools
|
||||
{
|
||||
public class Common
|
||||
@@ -19,6 +21,43 @@ namespace gaseous_tools
|
||||
return ObjectToCheck;
|
||||
}
|
||||
}
|
||||
|
||||
public class hashObject
|
||||
{
|
||||
public hashObject(string FileName)
|
||||
{
|
||||
var xmlStream = File.OpenRead(FileName);
|
||||
|
||||
var md5 = MD5.Create();
|
||||
byte[] md5HashByte = md5.ComputeHash(xmlStream);
|
||||
string md5Hash = BitConverter.ToString(md5HashByte).Replace("-", "").ToLowerInvariant();
|
||||
_md5hash = md5hash;
|
||||
|
||||
var sha1 = SHA1.Create();
|
||||
byte[] sha1HashByte = sha1.ComputeHash(xmlStream);
|
||||
string sha1Hash = BitConverter.ToString(sha1HashByte).Replace("-", "").ToLowerInvariant();
|
||||
_sha1hash = sha1hash;
|
||||
}
|
||||
|
||||
string _md5hash = "";
|
||||
string _sha1hash = "";
|
||||
|
||||
public string md5hash
|
||||
{
|
||||
get
|
||||
{
|
||||
return _md5hash;
|
||||
}
|
||||
}
|
||||
|
||||
public string sha1hash
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sha1hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user