Skip to content

Commit

Permalink
Resolves bugs when importing Signatures (#482)
Browse files Browse the repository at this point in the history
Resolves bugs when importing signature DATs.

For existing installs, the database upgrade will trigger a full
re-import of all DATs on startup to correct gaps or errors in the
database. This process may take some time.
  • Loading branch information
michael-j-green authored Jan 27, 2025
1 parent 3e844f8 commit beb14a5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
10 changes: 10 additions & 0 deletions gaseous-server/Classes/DatabaseMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ public static void PostUpgradeScript(int TargetSchemaVersion, Database.databaseT
} while (reader.EndOfStream == false);
}
break;

case 1024:
// attempt to re-import signature dats

// delete existing signature sources to allow re-import
Logging.Log(Logging.LogType.Information, "Database Upgrade", "Deleting existing signature sources");
sql = "DELETE FROM Signatures_Sources;";
db.ExecuteNonQuery(sql);

break;
}
break;
}
Expand Down
17 changes: 14 additions & 3 deletions gaseous-server/Classes/SignatureIngestors/XML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ public void Import(string SearchPath, string ProcessedDirectory, gaseous_signatu
}
else
{
gameId = (int)sigDB.Rows[0][0];
gameId = (long)(int)sigDB.Rows[0]["Id"];

string gameSourceSql = "UPDATE Signatures_Games SET `Name`=@name, `Description`=@description, `Year`=@year WHERE `Id`=@gameid;";
dbDict.Add("gameid", gameId);
db.ExecuteCMD(gameSourceSql, dbDict);
}

// insert countries
Expand Down Expand Up @@ -355,7 +359,7 @@ public void Import(string SearchPath, string ProcessedDirectory, gaseous_signatu
dbDict = new Dictionary<string, object>();
dbDict.Add("gameid", gameId);
dbDict.Add("name", Common.ReturnValueIfNull(romObject.Name, ""));
dbDict.Add("size", Common.ReturnValueIfNull(romObject.Size, ""));
dbDict.Add("size", Common.ReturnValueIfNull(romObject.Size, "0"));
dbDict.Add("crc", Common.ReturnValueIfNull(romObject.Crc, "").ToString().ToLower());
dbDict.Add("md5", Common.ReturnValueIfNull(romObject.Md5, "").ToString().ToLower());
dbDict.Add("sha1", Common.ReturnValueIfNull(romObject.Sha1, "").ToString().ToLower());
Expand Down Expand Up @@ -390,15 +394,22 @@ public void Import(string SearchPath, string ProcessedDirectory, gaseous_signatu
sigDB = db.ExecuteCMD(sql, dbDict);

romId = Convert.ToInt32(sigDB.Rows[0][0]);

dbDict.Add("romid", romId);
}
else
{
romId = (int)sigDB.Rows[0][0];

dbDict.Add("romid", romId);

// update the rom
sql = "UPDATE Signatures_Roms SET `GameId`=@gameid, `Name`=@name, `Size`=@size, `CRC`=@crc, `DevelopmentStatus`=@developmentstatus, `Attributes`=@attributes, `RomType`=@romtype, `RomTypeMedia`=@romtypemedia, `MediaLabel`=@medialabel, `MetadataSource`=@metadatasource, `IngestorVersion`=@ingestorversion WHERE `Id`=@romid;";
db.ExecuteCMD(sql, dbDict);
}

// map the rom to the source
sql = "SELECT * FROM Signatures_RomToSource WHERE SourceId=@sourceid AND RomId=@romid;";
dbDict.Add("romid", romId);
dbDict.Add("sourceId", sourceId);

sigDB = db.ExecuteCMD(sql, dbDict);
Expand Down
7 changes: 5 additions & 2 deletions gaseous-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,12 @@
var platformMap = PlatformMapping.PlatformMap;

// add background tasks
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
ProcessQueue.QueueItemType.SignatureIngestor)
ProcessQueue.QueueItem signatureIngestor = new ProcessQueue.QueueItem(
ProcessQueue.QueueItemType.SignatureIngestor
);
signatureIngestor.ForceExecute();
ProcessQueue.QueueItems.Add(signatureIngestor);

ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
ProcessQueue.QueueItemType.TitleIngestor)
);
Expand Down
5 changes: 5 additions & 0 deletions gaseous-server/Support/Database/MySQL/gaseous-1024.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE `Signatures_Games`
CHANGE `Year` `Year` varchar(50) DEFAULT NULL;

ALTER TABLE `Signatures_Roms`
CHANGE `MediaLabel` `MediaLabel` varchar(255) DEFAULT NULL;
2 changes: 2 additions & 0 deletions gaseous-server/gaseous-server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<None Remove="Support\Database\MySQL\gaseous-1021.sql" />
<None Remove="Support\Database\MySQL\gaseous-1022.sql" />
<None Remove="Support\Database\MySQL\gaseous-1023.sql" />
<None Remove="Support\Database\MySQL\gaseous-1024.sql" />
<None Remove="Classes\Metadata\" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -114,5 +115,6 @@
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1021.sql" />
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1022.sql" />
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1023.sql" />
<EmbeddedResource Include="Support\Database\MySQL\gaseous-1024.sql" />
</ItemGroup>
</Project>

0 comments on commit beb14a5

Please sign in to comment.