Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-j-green committed Jan 10, 2025
1 parent a0a8495 commit 86c207e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
13 changes: 13 additions & 0 deletions gaseous-server/Classes/DatabaseMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ public static void PostUpgradeScript(int TargetSchemaVersion, Database.databaseT
}
}

// get all tables that have the prefix "Relation_" and drop them
sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = @dbname AND table_name LIKE 'Relation_%';";
dbDict = new Dictionary<string, object>
{
{ "dbname", Config.DatabaseConfiguration.DatabaseName }
};
data = db.ExecuteCMD(sql, dbDict);
foreach (DataRow row in data.Rows)
{
sql = "DROP TABLE " + (string)row["table_name"] + ";";
db.ExecuteNonQuery(sql);
}

// migrating metadata is a safe background task
BackgroundUpgradeTargetSchemaVersions.Add(1024);
break;
Expand Down
7 changes: 5 additions & 2 deletions gaseous-server/Classes/ImportGames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ private static void _ImportGameFile(string FilePath, Common.hashObject Hash, ref
Platform? determinedPlatform = Metadata.Platforms.GetPlatform((long)discoveredSignature.Flags.PlatformId);
Models.Game? determinedGame = Metadata.Games.GetGame(discoveredSignature.Flags.GameMetadataSource, discoveredSignature.Flags.GameId);
long RomId = StoreGame(GameLibrary.GetDefaultLibrary, Hash, discoveredSignature, determinedPlatform, FilePath, 0, true);
Roms.GameRomItem romItem = Roms.GetRom(RomId);

// build return value
GameFileInfo.Add("romid", RomId);
GameFileInfo.Add("platform", determinedPlatform);
GameFileInfo.Add("game", determinedGame);
GameFileInfo.Add("signature", discoveredSignature);
GameFileInfo.Add("rom", romItem);
GameFileInfo.Add("status", "imported");
}
}
Expand Down Expand Up @@ -248,7 +250,7 @@ public static long StoreGame(GameLibrary.LibraryItem library, Common.hashObject
}
}
}

// reload the map
map = MetadataManagement.GetMetadataMap((long)map.Id);

Expand Down Expand Up @@ -479,8 +481,9 @@ public static string ComputeROMPath(long RomId)
Classes.Roms.GameRomItem rom = Classes.Roms.GetRom(RomId);

// get metadata
MetadataMap.MetadataMapItem metadataMap = Classes.MetadataManagement.GetMetadataMap(rom.MetadataMapId).PreferredMetadataMapItem;
Platform? platform = gaseous_server.Classes.Metadata.Platforms.GetPlatform(rom.PlatformId);
gaseous_server.Models.Game? game = gaseous_server.Classes.Metadata.Games.GetGame(Config.MetadataConfiguration.DefaultMetadataSource, rom.GameId);
gaseous_server.Models.Game? game = Classes.Metadata.Games.GetGame(metadataMap.SourceType, metadataMap.SourceId);

// build path
string platformSlug = "Unknown Platform";
Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Classes/Metadata/Platforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Platforms()
{
Id = 0,
Name = "Unknown Platform",
Slug = "Unknown"
Slug = "unknown"
};
Storage.NewCacheValue(Source, returnValue);

Expand Down
23 changes: 13 additions & 10 deletions gaseous-server/Models/PlatformMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ private static Platform CreateDummyPlatform(PlatformMapItem mapItem)
Storage.NewCacheValue(HasheousClient.Models.MetadataSources.None, platform);
}

Communications.PopulateHasheousPlatformData(mapItem.IGDBId);
if (Config.MetadataConfiguration.SignatureSource == HasheousClient.Models.MetadataModel.SignatureSources.Hasheous)
{
Communications.PopulateHasheousPlatformData(mapItem.IGDBId);
}

if (Storage.GetCacheStatus(HasheousClient.Models.MetadataSources.IGDB, "Platform", mapItem.IGDBId) == Storage.CacheStatus.NotPresent)
{
Expand Down Expand Up @@ -318,15 +321,15 @@ static PlatformMapItem BuildPlatformMapItem(DataRow row)

// get platform data
Platform? platform = null;
// if (Storage.GetCacheStatus(HasheousClient.Models.MetadataSources.None, "Platform", IGDBId) == Storage.CacheStatus.NotPresent)
// {
// //platform = Platforms.GetPlatform(IGDBId, false);
// }
// else
// {
// platform = (Platform)Storage.GetCacheValue<Platform>(HasheousClient.Models.MetadataSources.None, new Platform(), "id", IGDBId);
// }
platform = Platforms.GetPlatform(IGDBId, HasheousClient.Models.MetadataSources.None);
if (Storage.GetCacheStatus(HasheousClient.Models.MetadataSources.None, "Platform", IGDBId) == Storage.CacheStatus.NotPresent)
{
//platform = Platforms.GetPlatform(IGDBId, false);
}
else
{
// platform = (Platform)Storage.GetCacheValue<Platform>(HasheousClient.Models.MetadataSources.None, new Platform(), "id", IGDBId);
platform = Platforms.GetPlatform(IGDBId, HasheousClient.Models.MetadataSources.None);
}

if (platform != null)
{
Expand Down
6 changes: 6 additions & 0 deletions gaseous-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Identity;
using gaseous_server.Classes.Metadata;
using Asp.Versioning;
using HasheousClient.Models.Metadata.IGDB;

Logging.WriteToDiskOnly = true;
Logging.Log(Logging.LogType.Information, "Startup", "Starting Gaseous Server " + Assembly.GetExecutingAssembly().GetName().Version);
Expand Down Expand Up @@ -329,6 +330,11 @@
// setup library directories
Config.LibraryConfiguration.InitLibrary();

// create unknown platform
Platforms.GetPlatform(0, HasheousClient.Models.MetadataSources.None);
Platforms.GetPlatform(0, HasheousClient.Models.MetadataSources.IGDB);
Platforms.GetPlatform(0, HasheousClient.Models.MetadataSources.TheGamesDb);

// extract platform map if not present
PlatformMapping.ExtractPlatformMap();

Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Support/Database/MySQL/gaseous-1024.sql
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,4 @@ FROM (
`Game`.`SourceId` = `view_MetadataMap`.`MetadataSourceType`
AND `Game`.`Id` = `view_MetadataMap`.`MetadataSourceId`
)
);
);
11 changes: 9 additions & 2 deletions gaseous-server/wwwroot/scripts/uploadrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class UploadRom {
if (xhr.status === 200) {
// process the results
let response = JSON.parse(xhr.responseText);
console.log(response);
switch (response.type) {
case 'rom':
switch (response.status) {
Expand All @@ -121,16 +122,21 @@ class UploadRom {
uploadedItem.platformName = 'Unknown Platform';
uploadedItem.gameId = 0;
uploadedItem.gameName = 'Unknown Game';
uploadedItem.gameData = response.game;
uploadedItem.romId = response.romid;

if (response.game) {
uploadedItem.gameId = response.game.metadataMapId;
// game data was returned
uploadedItem.gameId = response.rom.metadataMapId;
uploadedItem.gameName = response.game.name;
if (response.game.cover != null) {
if (response.game.cover != null) {
uploadedItem.coverId = response.game.cover;
}
}
} else {
// game has been deemed to be unknown
uploadedItem.gameId = response.rom.metadataMapId;
}

if (response.platform) {
Expand Down Expand Up @@ -273,6 +279,7 @@ class UploadItem {
platformName = null;
gameId = null;
gameName = null;
gameData = null;
coverId = null;
romId = null;

Expand Down Expand Up @@ -319,7 +326,7 @@ class UploadItem {
case 'rom':
this.infoButton.style.display = 'block';

if (this.gameId === null || this.gameId === 0) {
if (this.gameId === null || this.gameId === 0 || this.gameData === null) {
this.coverArt.src = '/images/unknowngame.png';
} else {
this.coverArt.src = '/api/v1.1/Games/' + this.gameId + '/cover/' + this.coverId + '/image/cover_big/cover.jpg';
Expand Down

0 comments on commit 86c207e

Please sign in to comment.