diff --git a/gaseous-server/Classes/FileSignature.cs b/gaseous-server/Classes/FileSignature.cs index 9478d89..2c78fc7 100644 --- a/gaseous-server/Classes/FileSignature.cs +++ b/gaseous-server/Classes/FileSignature.cs @@ -264,37 +264,47 @@ namespace gaseous_server.Classes if (Config.MetadataConfiguration.SignatureSource == HasheousClient.Models.MetadataModel.SignatureSources.Hasheous) { HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous(); - SignatureLookupItem? HasheousResult = hasheous.RetrieveFromHasheousAsync(new HashLookupModel{ - MD5 = hash.md5hash, - SHA1 = hash.sha1hash - }); + SignatureLookupItem? HasheousResult = null; - if (HasheousResult != null) + try { - if (HasheousResult.Signature != null) + HasheousResult = hasheous.RetrieveFromHasheousAsync(new HashLookupModel { - gaseous_server.Models.Signatures_Games signature = new Models.Signatures_Games(); - signature.Game = HasheousResult.Signature.Game; - signature.Rom = HasheousResult.Signature.Rom; - - if (HasheousResult.MetadataResults != null) + MD5 = hash.md5hash, + SHA1 = hash.sha1hash + }); + + if (HasheousResult != null) + { + if (HasheousResult.Signature != null) { - if (HasheousResult.MetadataResults.Count > 0) + gaseous_server.Models.Signatures_Games signature = new Models.Signatures_Games(); + signature.Game = HasheousResult.Signature.Game; + signature.Rom = HasheousResult.Signature.Rom; + + if (HasheousResult.MetadataResults != null) { - foreach (SignatureLookupItem.MetadataResult metadataResult in HasheousResult.MetadataResults) + if (HasheousResult.MetadataResults.Count > 0) { - if (metadataResult.Source == MetadataModel.MetadataSources.IGDB) + foreach (SignatureLookupItem.MetadataResult metadataResult in HasheousResult.MetadataResults) { - signature.Flags.IGDBPlatformId = (long)metadataResult.PlatformId; - signature.Flags.IGDBGameId = (long)metadataResult.GameId; + if (metadataResult.Source == MetadataModel.MetadataSources.IGDB) + { + signature.Flags.IGDBPlatformId = (long)metadataResult.PlatformId; + signature.Flags.IGDBGameId = (long)metadataResult.GameId; + } } } } - } - return signature; + return signature; + } } } + catch (Exception ex) + { + Logging.Log(Logging.LogType.Warning, "Get Signature", "Error retrieving signature from Hasheous", ex); + } } return null; diff --git a/gaseous-server/Classes/Metadata/PlatformVersions.cs b/gaseous-server/Classes/Metadata/PlatformVersions.cs index 8e378b3..799f7f5 100644 --- a/gaseous-server/Classes/Metadata/PlatformVersions.cs +++ b/gaseous-server/Classes/Metadata/PlatformVersions.cs @@ -5,15 +5,15 @@ using IGDB.Models; namespace gaseous_server.Classes.Metadata { - public class PlatformVersions - { + public class PlatformVersions + { const string fieldList = "fields checksum,companies,connectivity,cpu,graphics,main_manufacturer,media,memory,name,online,os,output,platform_logo,platform_version_release_dates,resolutions,slug,sound,storage,summary,url;"; public PlatformVersions() - { - } + { + } - public static PlatformVersion? GetPlatformVersion(long Id, Platform ParentPlatform) + public static PlatformVersion? GetPlatformVersion(long Id, Platform ParentPlatform, bool GetImages = false) { if (Id == 0) { @@ -21,18 +21,18 @@ namespace gaseous_server.Classes.Metadata } else { - Task RetVal = _GetPlatformVersion(SearchUsing.id, Id, ParentPlatform); + Task RetVal = _GetPlatformVersion(SearchUsing.id, Id, ParentPlatform, GetImages); return RetVal.Result; } } - public static PlatformVersion GetPlatformVersion(string Slug, Platform ParentPlatform) + public static PlatformVersion GetPlatformVersion(string Slug, Platform ParentPlatform, bool GetImages) { - Task RetVal = _GetPlatformVersion(SearchUsing.slug, Slug, ParentPlatform); + Task RetVal = _GetPlatformVersion(SearchUsing.slug, Slug, ParentPlatform, GetImages); return RetVal.Result; } - private static async Task _GetPlatformVersion(SearchUsing searchUsing, object searchValue, Platform ParentPlatform) + private static async Task _GetPlatformVersion(SearchUsing searchUsing, object searchValue, Platform ParentPlatform, bool GetImages) { // check database first Storage.CacheStatus? cacheStatus = new Storage.CacheStatus(); @@ -67,7 +67,7 @@ namespace gaseous_server.Classes.Metadata if (returnValue != null) { Storage.NewCacheValue(returnValue); - UpdateSubClasses(ParentPlatform, returnValue); + UpdateSubClasses(ParentPlatform, returnValue, GetImages); } return returnValue; case Storage.CacheStatus.Expired: @@ -75,7 +75,7 @@ namespace gaseous_server.Classes.Metadata { returnValue = await GetObjectFromServer(WhereClause); Storage.NewCacheValue(returnValue, true); - UpdateSubClasses(ParentPlatform, returnValue); + UpdateSubClasses(ParentPlatform, returnValue, GetImages); } catch (Exception ex) { @@ -90,17 +90,20 @@ namespace gaseous_server.Classes.Metadata } } - private static void UpdateSubClasses(Platform ParentPlatform, PlatformVersion platformVersion) + private static void UpdateSubClasses(Platform ParentPlatform, PlatformVersion platformVersion, bool GetImages) { - if (platformVersion.PlatformLogo != null) + if (GetImages == true) { - try + if (platformVersion.PlatformLogo != null) { - PlatformLogo platformLogo = PlatformLogos.GetPlatformLogo(platformVersion.PlatformLogo.Id, Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(ParentPlatform), "Versions", platformVersion.Slug)); - } - catch (Exception ex) - { - Logging.Log(Logging.LogType.Warning, "Platform Update", "Unable to fetch platform logo", ex); + try + { + PlatformLogo platformLogo = PlatformLogos.GetPlatformLogo(platformVersion.PlatformLogo.Id, Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(ParentPlatform), "Versions", platformVersion.Slug)); + } + catch (Exception ex) + { + Logging.Log(Logging.LogType.Warning, "Platform Update", "Unable to fetch platform logo", ex); + } } } } diff --git a/gaseous-server/Classes/Metadata/Platforms.cs b/gaseous-server/Classes/Metadata/Platforms.cs index 531d771..5bab6b6 100644 --- a/gaseous-server/Classes/Metadata/Platforms.cs +++ b/gaseous-server/Classes/Metadata/Platforms.cs @@ -7,16 +7,16 @@ using IGDB.Models; namespace gaseous_server.Classes.Metadata { public class Platforms - { + { const string fieldList = "fields abbreviation,alternative_name,category,checksum,created_at,generation,name,platform_family,platform_logo,slug,summary,updated_at,url,versions,websites;"; public Platforms() - { + { - } + } - public static Platform? GetPlatform(long Id, bool forceRefresh = false) - { + public static Platform? GetPlatform(long Id, bool forceRefresh = false, bool GetImages = false) + { if (Id == 0) { Platform returnValue = new Platform(); @@ -41,10 +41,10 @@ namespace gaseous_server.Classes.Metadata { try { - Task RetVal = _GetPlatform(SearchUsing.id, Id, forceRefresh); + Task RetVal = _GetPlatform(SearchUsing.id, Id, forceRefresh, GetImages); return RetVal.Result; } - catch(Exception ex) + catch (Exception ex) { Logging.Log(Logging.LogType.Warning, "Metadata", "An error occurred fetching Platform Id " + Id, ex); return null; @@ -52,14 +52,14 @@ namespace gaseous_server.Classes.Metadata } } - public static Platform GetPlatform(string Slug, bool forceRefresh = false) - { - Task RetVal = _GetPlatform(SearchUsing.slug, Slug, forceRefresh); - return RetVal.Result; - } + public static Platform GetPlatform(string Slug, bool forceRefresh = false, bool GetImages = false) + { + Task RetVal = _GetPlatform(SearchUsing.slug, Slug, forceRefresh, GetImages); + return RetVal.Result; + } - private static async Task _GetPlatform(SearchUsing searchUsing, object searchValue, bool forceRefresh) - { + private static async Task _GetPlatform(SearchUsing searchUsing, object searchValue, bool forceRefresh, bool GetImages) + { // check database first Storage.CacheStatus? cacheStatus = new Storage.CacheStatus(); if (searchUsing == SearchUsing.id) @@ -96,7 +96,7 @@ namespace gaseous_server.Classes.Metadata case Storage.CacheStatus.NotPresent: returnValue = await GetObjectFromServer(WhereClause); Storage.NewCacheValue(returnValue); - UpdateSubClasses(returnValue); + UpdateSubClasses(returnValue, GetImages); AddPlatformMapping(returnValue); return returnValue; case Storage.CacheStatus.Expired: @@ -104,7 +104,7 @@ namespace gaseous_server.Classes.Metadata { returnValue = await GetObjectFromServer(WhereClause); Storage.NewCacheValue(returnValue, true); - UpdateSubClasses(returnValue); + UpdateSubClasses(returnValue, GetImages); AddPlatformMapping(returnValue); return returnValue; } @@ -120,7 +120,7 @@ namespace gaseous_server.Classes.Metadata } } - private static void UpdateSubClasses(Platform platform) + private static void UpdateSubClasses(Platform platform, bool GetImages) { if (platform.Versions != null) { @@ -130,15 +130,18 @@ namespace gaseous_server.Classes.Metadata } } - if (platform.PlatformLogo != null) + if (GetImages == true) { - try + if (platform.PlatformLogo != null) { - PlatformLogo platformLogo = PlatformLogos.GetPlatformLogo(platform.PlatformLogo.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(platform)); - } - catch (Exception ex) - { - Logging.Log(Logging.LogType.Warning, "Platform Update", "Unable to fetch platform logo", ex); + try + { + PlatformLogo platformLogo = PlatformLogos.GetPlatformLogo(platform.PlatformLogo.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(platform)); + } + catch (Exception ex) + { + Logging.Log(Logging.LogType.Warning, "Platform Update", "Unable to fetch platform logo", ex); + } } } } @@ -158,11 +161,12 @@ namespace gaseous_server.Classes.Metadata { Logging.Log(Logging.LogType.Information, "Platform Map", "Importing " + platform.Name + " from predefined data."); // doesn't exist - add it - item = new Models.PlatformMapping.PlatformMapItem{ + item = new Models.PlatformMapping.PlatformMapItem + { IGDBId = (long)platform.Id, IGDBName = platform.Name, IGDBSlug = platform.Slug, - AlternateNames = new List{ platform.AlternativeName } + AlternateNames = new List { platform.AlternativeName } }; Models.PlatformMapping.WritePlatformMap(item, false, true); } diff --git a/gaseous-server/Models/PlatformMapping.cs b/gaseous-server/Models/PlatformMapping.cs index 88eea1f..14eab24 100644 --- a/gaseous-server/Models/PlatformMapping.cs +++ b/gaseous-server/Models/PlatformMapping.cs @@ -13,8 +13,8 @@ using Newtonsoft.Json; namespace gaseous_server.Models { - public class PlatformMapping - { + public class PlatformMapping + { private static Dictionary PlatformMapCache = new Dictionary(); /// @@ -27,7 +27,8 @@ namespace gaseous_server.Models { string rawJson = reader.ReadToEnd(); List platforms = new List(); - Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings{ + Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings + { MaxDepth = 64 }; platforms = Newtonsoft.Json.JsonConvert.DeserializeObject>(rawJson, jsonSerializerSettings); @@ -74,7 +75,7 @@ namespace gaseous_server.Models foreach (PlatformMapItem mapItem in platforms) { // get the IGDB platform data - Platform platform = Platforms.GetPlatform(mapItem.IGDBId); + Platform platform = Platforms.GetPlatform(mapItem.IGDBId, false); try { @@ -92,7 +93,7 @@ namespace gaseous_server.Models } } } - + public static List PlatformMap { get @@ -254,7 +255,7 @@ namespace gaseous_server.Models } } - public static void WriteAvailableEmulators (PlatformMapItem item) + public static void WriteAvailableEmulators(PlatformMapItem item) { Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); string sql = ""; @@ -286,7 +287,7 @@ namespace gaseous_server.Models string sql = ""; // get platform data - IGDB.Models.Platform? platform = Platforms.GetPlatform(IGDBId); + IGDB.Models.Platform? platform = Platforms.GetPlatform(IGDBId, false); if (platform != null) { @@ -369,18 +370,20 @@ namespace gaseous_server.Models mapItem.IGDBName = platform.Name; mapItem.IGDBSlug = platform.Slug; mapItem.AlternateNames = alternateNames; - mapItem.Extensions = new PlatformMapItem.FileExtensions{ + mapItem.Extensions = new PlatformMapItem.FileExtensions + { SupportedFileExtensions = knownExtensions, UniqueFileExtensions = uniqueExtensions }; mapItem.RetroPieDirectoryName = (string)Common.ReturnValueIfNull(row["RetroPieDirectoryName"], ""); - mapItem.WebEmulator = new PlatformMapItem.WebEmulatorItem{ + mapItem.WebEmulator = new PlatformMapItem.WebEmulatorItem + { Type = (string)Common.ReturnValueIfNull(row["WebEmulator_Type"], ""), Core = (string)Common.ReturnValueIfNull(row["WebEmulator_Core"], ""), AvailableWebEmulators = Newtonsoft.Json.JsonConvert.DeserializeObject>((string)Common.ReturnValueIfNull(row["AvailableWebEmulators"], "[]")) }; mapItem.Bios = bioss; - + if (PlatformMapCache.ContainsKey(IGDBId.ToString())) { PlatformMapCache[IGDBId.ToString()] = mapItem; @@ -461,7 +464,7 @@ namespace gaseous_server.Models public string IGDBName { get; set; } public string IGDBSlug { get; set; } public List AlternateNames { get; set; } = new List(); - + public FileExtensions Extensions { get; set; } public class FileExtensions { @@ -503,6 +506,6 @@ namespace gaseous_server.Models public string filename { get; set; } } } - } + } }