refactor: better casting of int types from database

This commit is contained in:
Michael Green
2023-03-03 16:27:42 +11:00
parent 39e0bd9740
commit 959f6f2419
2 changed files with 132 additions and 121 deletions

View File

@@ -175,11 +175,11 @@ if (Directory.Exists(tosecXML))
sql = "INSERT INTO signatures_platforms (platform) VALUES (@platform); SELECT LAST_INSERT_ID()";
sigDB = db.ExecuteCMD(sql, dbDict);
gameSystem = int.Parse(sigDB.Rows[0][0].ToString());
gameSystem = (int)sigDB.Rows[0][0];
}
else
{
gameSystem = int.Parse(sigDB.Rows[0][0].ToString());
gameSystem = (int)sigDB.Rows[0][0];
}
}
dbDict.Add("systemid", gameSystem);
@@ -196,11 +196,11 @@ if (Directory.Exists(tosecXML))
// entry not present, insert it
sql = "INSERT INTO signatures_publishers (publisher) VALUES (@publisher); SELECT LAST_INSERT_ID()";
sigDB = db.ExecuteCMD(sql, dbDict);
gamePublisher = int.Parse(sigDB.Rows[0][0].ToString());
gamePublisher = (int)sigDB.Rows[0][0];
}
else
{
gamePublisher = int.Parse(sigDB.Rows[0][0].ToString());
gamePublisher = (int)sigDB.Rows[0][0];
}
}
dbDict.Add("publisherid", gamePublisher);
@@ -218,11 +218,11 @@ if (Directory.Exists(tosecXML))
"(@name, @description, @year, @publisherid, @demo, @systemid, @systemvariant, @video, @country, @language, @copyright); SELECT LAST_INSERT_ID()";
sigDB = db.ExecuteCMD(sql, dbDict);
gameId = int.Parse(sigDB.Rows[0][0].ToString());
gameId = (int)sigDB.Rows[0][0];
}
else
{
gameId = int.Parse(sigDB.Rows[0][0].ToString());
gameId = (int)sigDB.Rows[0][0];
}
// store rom
@@ -268,11 +268,11 @@ if (Directory.Exists(tosecXML))
sigDB = db.ExecuteCMD(sql, dbDict);
romId = int.Parse(sigDB.Rows[0][0].ToString());
romId = (int)sigDB.Rows[0][0];
}
else
{
romId = int.Parse(sigDB.Rows[0][0].ToString());
romId = (int)sigDB.Rows[0][0];
}
}
}

View File

@@ -351,15 +351,25 @@ namespace gaseous_signature_parser.parsers
case "rom":
RomSignatureObject.Game.Rom romObject = new RomSignatureObject.Game.Rom();
if (xmlGameDetail != null)
{
romObject.Name = xmlGameDetail.Attributes["name"]?.Value;
if (xmlGameDetail.Attributes["size"]?.Value != null)
{
romObject.Size = UInt64.Parse(xmlGameDetail.Attributes["size"]?.Value);
}
else
{
romObject.Size = 0;
}
romObject.Crc = xmlGameDetail.Attributes["crc"]?.Value;
romObject.Md5 = xmlGameDetail.Attributes["md5"]?.Value;
romObject.Sha1 = xmlGameDetail.Attributes["sha1"]?.Value;
// parse name
string[] romNameTokens = romDescription.Split("(");
foreach (string rawToken in romNameTokens) {
foreach (string rawToken in romNameTokens)
{
string[] tokenSplit = rawToken.Split("[");
// replace the extra closing bracket
@@ -480,6 +490,7 @@ namespace gaseous_signature_parser.parsers
}
}
}
}
gameObject.Roms.Add(romObject);
break;