diff --git a/gaseous-server/Classes/ImportGames.cs b/gaseous-server/Classes/ImportGames.cs index 257f27a..b13f618 100644 --- a/gaseous-server/Classes/ImportGames.cs +++ b/gaseous-server/Classes/ImportGames.cs @@ -134,7 +134,7 @@ namespace gaseous_server.Classes if (games.Length == 1) { // exact match! - determinedGame = Metadata.Games.GetGame((long)games[0].Id); + determinedGame = Metadata.Games.GetGame((long)games[0].Id, false); Logging.Log(Logging.LogType.Information, "Import Game", " IGDB game: " + determinedGame.Name); break; } @@ -195,7 +195,7 @@ namespace gaseous_server.Classes // get metadata IGDB.Models.Platform platform = gaseous_server.Classes.Metadata.Platforms.GetPlatform(rom.PlatformId); - IGDB.Models.Game game = gaseous_server.Classes.Metadata.Games.GetGame(rom.GameId); + IGDB.Models.Game game = gaseous_server.Classes.Metadata.Games.GetGame(rom.GameId, false); // build path string platformSlug = "Unknown Platform"; @@ -262,7 +262,9 @@ namespace gaseous_server.Classes public static void OrganiseLibrary() { - // move rom files to their new location + Logging.Log(Logging.LogType.Information, "Organise Library", "Starting library organisation"); + + // move rom files to their new location Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); string sql = "SELECT * FROM games_roms"; DataTable romDT = db.ExecuteCMD(sql); @@ -271,13 +273,16 @@ namespace gaseous_server.Classes { foreach (DataRow dr in romDT.Rows) { - long RomId = (long)dr["id"]; + Logging.Log(Logging.LogType.Information, "Organise Library", "Processing ROM " + dr["name"]); + long RomId = (long)dr["id"]; MoveGameFile(RomId); } } // clean up empty directories processDirectory(Config.LibraryConfiguration.LibraryDataDirectory); + + Logging.Log(Logging.LogType.Information, "Organise Library", "Finsihed library organisation"); } private static void processDirectory(string startLocation) diff --git a/gaseous-server/Classes/Metadata/Games.cs b/gaseous-server/Classes/Metadata/Games.cs index a23f3e2..9b60e23 100644 --- a/gaseous-server/Classes/Metadata/Games.cs +++ b/gaseous-server/Classes/Metadata/Games.cs @@ -20,7 +20,7 @@ namespace gaseous_server.Classes.Metadata Config.IGDB.Secret ); - public static Game? GetGame(long Id) + public static Game? GetGame(long Id, bool followSubGames) { if (Id == 0) { @@ -28,18 +28,18 @@ namespace gaseous_server.Classes.Metadata } else { - Task RetVal = _GetGame(SearchUsing.id, Id); + Task RetVal = _GetGame(SearchUsing.id, Id, followSubGames); return RetVal.Result; } } - public static Game GetGame(string Slug) + public static Game GetGame(string Slug, bool followSubGames) { - Task RetVal = _GetGame(SearchUsing.slug, Slug); + Task RetVal = _GetGame(SearchUsing.slug, Slug, followSubGames); return RetVal.Result; } - private static async Task _GetGame(SearchUsing searchUsing, object searchValue) + private static async Task _GetGame(SearchUsing searchUsing, object searchValue, bool followSubGames = false) { // check database first Storage.CacheStatus? cacheStatus = new Storage.CacheStatus(); @@ -72,12 +72,12 @@ namespace gaseous_server.Classes.Metadata case Storage.CacheStatus.NotPresent: returnValue = await GetObjectFromServer(WhereClause); Storage.NewCacheValue(returnValue); - UpdateSubClasses(returnValue); + UpdateSubClasses(returnValue, followSubGames); return returnValue; case Storage.CacheStatus.Expired: returnValue = await GetObjectFromServer(WhereClause); Storage.NewCacheValue(returnValue, true); - UpdateSubClasses(returnValue); + UpdateSubClasses(returnValue, followSubGames); return returnValue; case Storage.CacheStatus.Current: return Storage.GetCacheValue(returnValue, "id", (long)searchValue); @@ -86,7 +86,7 @@ namespace gaseous_server.Classes.Metadata } } - private static void UpdateSubClasses(Game Game) + private static void UpdateSubClasses(Game Game, bool followSubGames) { if (Game.Artworks != null) { @@ -95,6 +95,22 @@ namespace gaseous_server.Classes.Metadata Artwork GameArtwork = Artworks.GetArtwork(ArtworkId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(Game)); } } + if (followSubGames) + { + List gamesToFetch = new List(); + if (Game.Bundles != null) { gamesToFetch.AddRange(Game.Bundles.Ids); } + if (Game.Dlcs != null) { gamesToFetch.AddRange(Game.Dlcs.Ids); } + if (Game.Expansions != null) { gamesToFetch.AddRange(Game.Expansions.Ids); } + if (Game.ParentGame != null) { gamesToFetch.Add((long)Game.ParentGame.Id); } + if (Game.SimilarGames != null) { gamesToFetch.AddRange(Game.SimilarGames.Ids); } + if (Game.StandaloneExpansions != null) { gamesToFetch.AddRange(Game.StandaloneExpansions.Ids); } + if (Game.VersionParent != null) { gamesToFetch.Add((long)Game.VersionParent.Id); } + + foreach (long gameId in gamesToFetch) + { + Game relatedGame = GetGame(gameId, false); + } + } if (Game.Cover != null) { Cover GameCover = Covers.GetCover(Game.Cover.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(Game)); diff --git a/gaseous-server/Classes/Metadata/Storage.cs b/gaseous-server/Classes/Metadata/Storage.cs index 8ac0ac6..f712385 100644 --- a/gaseous-server/Classes/Metadata/Storage.cs +++ b/gaseous-server/Classes/Metadata/Storage.cs @@ -44,7 +44,7 @@ namespace gaseous_server.Classes.Metadata } else { - DateTime CacheExpiryTime = DateTime.UtcNow.AddHours(-24); + DateTime CacheExpiryTime = DateTime.UtcNow.AddHours(-168); if ((DateTime)dt.Rows[0]["lastUpdated"] < CacheExpiryTime) { return CacheStatus.Expired; diff --git a/gaseous-server/Classes/MetadataManagement.cs b/gaseous-server/Classes/MetadataManagement.cs new file mode 100644 index 0000000..90e9f96 --- /dev/null +++ b/gaseous-server/Classes/MetadataManagement.cs @@ -0,0 +1,23 @@ +using System; +using System.Data; +using gaseous_tools; + +namespace gaseous_server.Classes +{ + public class MetadataManagement + { + public static void RefreshMetadata() + { + Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "SELECT id, `name` FROM game;"; + DataTable dt = db.ExecuteCMD(sql); + + foreach (DataRow dr in dt.Rows) + { + Logging.Log(Logging.LogType.Information, "Metadata Refresh", "Refreshing metadata for game " + dr["name"] + " (" + dr["id"] + ")"); + Metadata.Games.GetGame((long)dr["id"], true); + } + } + } +} + diff --git a/gaseous-server/ProcessQueue.cs b/gaseous-server/ProcessQueue.cs index 07b01ad..4a9a781 100644 --- a/gaseous-server/ProcessQueue.cs +++ b/gaseous-server/ProcessQueue.cs @@ -69,6 +69,11 @@ namespace gaseous_server Logging.Log(Logging.LogType.Information, "Timered Event", "Starting Title Ingestor"); Classes.ImportGames importGames = new Classes.ImportGames(Config.LibraryConfiguration.LibraryImportDirectory); break; + + case QueueItemType.MetadataRefresh: + Logging.Log(Logging.LogType.Information, "Timered Event", "Starting Metadata Refresher"); + Classes.MetadataManagement.RefreshMetadata(); + break; } } catch (Exception ex) @@ -95,7 +100,8 @@ namespace gaseous_server { NotConfigured, SignatureIngestor, - TitleIngestor + TitleIngestor, + MetadataRefresh } public enum QueueItemState diff --git a/gaseous-server/Program.cs b/gaseous-server/Program.cs index 92a3abb..3c5fa0d 100644 --- a/gaseous-server/Program.cs +++ b/gaseous-server/Program.cs @@ -54,11 +54,12 @@ app.MapControllers(); Config.LibraryConfiguration.InitLibrary(); // organise library -gaseous_server.Classes.ImportGame.OrganiseLibrary(); +//gaseous_server.Classes.ImportGame.OrganiseLibrary(); // add background tasks ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.SignatureIngestor, 60)); ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.TitleIngestor, 1)); +ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.MetadataRefresh, 360)); // start the app app.Run();