Disable platform logo loading - these aren't used, added try/catch block around Hasheous to deal with failures.

This commit is contained in:
Michael Green
2024-06-28 11:03:59 +10:00
parent 30be179367
commit d1f157ac08
4 changed files with 95 additions and 75 deletions

View File

@@ -264,37 +264,47 @@ namespace gaseous_server.Classes
if (Config.MetadataConfiguration.SignatureSource == HasheousClient.Models.MetadataModel.SignatureSources.Hasheous) if (Config.MetadataConfiguration.SignatureSource == HasheousClient.Models.MetadataModel.SignatureSources.Hasheous)
{ {
HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous(); HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous();
SignatureLookupItem? HasheousResult = hasheous.RetrieveFromHasheousAsync(new HashLookupModel{ SignatureLookupItem? HasheousResult = null;
MD5 = hash.md5hash,
SHA1 = hash.sha1hash
});
if (HasheousResult != null) try
{ {
if (HasheousResult.Signature != null) HasheousResult = hasheous.RetrieveFromHasheousAsync(new HashLookupModel
{ {
gaseous_server.Models.Signatures_Games signature = new Models.Signatures_Games(); MD5 = hash.md5hash,
signature.Game = HasheousResult.Signature.Game; SHA1 = hash.sha1hash
signature.Rom = HasheousResult.Signature.Rom; });
if (HasheousResult.MetadataResults != null) 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; if (metadataResult.Source == MetadataModel.MetadataSources.IGDB)
signature.Flags.IGDBGameId = (long)metadataResult.GameId; {
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; return null;

View File

@@ -5,15 +5,15 @@ using IGDB.Models;
namespace gaseous_server.Classes.Metadata 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;"; 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 PlatformVersions()
{ {
} }
public static PlatformVersion? GetPlatformVersion(long Id, Platform ParentPlatform) public static PlatformVersion? GetPlatformVersion(long Id, Platform ParentPlatform, bool GetImages = false)
{ {
if (Id == 0) if (Id == 0)
{ {
@@ -21,18 +21,18 @@ namespace gaseous_server.Classes.Metadata
} }
else else
{ {
Task<PlatformVersion> RetVal = _GetPlatformVersion(SearchUsing.id, Id, ParentPlatform); Task<PlatformVersion> RetVal = _GetPlatformVersion(SearchUsing.id, Id, ParentPlatform, GetImages);
return RetVal.Result; return RetVal.Result;
} }
} }
public static PlatformVersion GetPlatformVersion(string Slug, Platform ParentPlatform) public static PlatformVersion GetPlatformVersion(string Slug, Platform ParentPlatform, bool GetImages)
{ {
Task<PlatformVersion> RetVal = _GetPlatformVersion(SearchUsing.slug, Slug, ParentPlatform); Task<PlatformVersion> RetVal = _GetPlatformVersion(SearchUsing.slug, Slug, ParentPlatform, GetImages);
return RetVal.Result; return RetVal.Result;
} }
private static async Task<PlatformVersion> _GetPlatformVersion(SearchUsing searchUsing, object searchValue, Platform ParentPlatform) private static async Task<PlatformVersion> _GetPlatformVersion(SearchUsing searchUsing, object searchValue, Platform ParentPlatform, bool GetImages)
{ {
// check database first // check database first
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus(); Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
@@ -67,7 +67,7 @@ namespace gaseous_server.Classes.Metadata
if (returnValue != null) if (returnValue != null)
{ {
Storage.NewCacheValue(returnValue); Storage.NewCacheValue(returnValue);
UpdateSubClasses(ParentPlatform, returnValue); UpdateSubClasses(ParentPlatform, returnValue, GetImages);
} }
return returnValue; return returnValue;
case Storage.CacheStatus.Expired: case Storage.CacheStatus.Expired:
@@ -75,7 +75,7 @@ namespace gaseous_server.Classes.Metadata
{ {
returnValue = await GetObjectFromServer(WhereClause); returnValue = await GetObjectFromServer(WhereClause);
Storage.NewCacheValue(returnValue, true); Storage.NewCacheValue(returnValue, true);
UpdateSubClasses(ParentPlatform, returnValue); UpdateSubClasses(ParentPlatform, returnValue, GetImages);
} }
catch (Exception ex) 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)); try
} {
catch (Exception ex) PlatformLogo platformLogo = PlatformLogos.GetPlatformLogo(platformVersion.PlatformLogo.Id, Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(ParentPlatform), "Versions", platformVersion.Slug));
{ }
Logging.Log(Logging.LogType.Warning, "Platform Update", "Unable to fetch platform logo", ex); catch (Exception ex)
{
Logging.Log(Logging.LogType.Warning, "Platform Update", "Unable to fetch platform logo", ex);
}
} }
} }
} }

View File

@@ -7,16 +7,16 @@ using IGDB.Models;
namespace gaseous_server.Classes.Metadata namespace gaseous_server.Classes.Metadata
{ {
public class Platforms 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;"; 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 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) if (Id == 0)
{ {
Platform returnValue = new Platform(); Platform returnValue = new Platform();
@@ -41,10 +41,10 @@ namespace gaseous_server.Classes.Metadata
{ {
try try
{ {
Task<Platform> RetVal = _GetPlatform(SearchUsing.id, Id, forceRefresh); Task<Platform> RetVal = _GetPlatform(SearchUsing.id, Id, forceRefresh, GetImages);
return RetVal.Result; return RetVal.Result;
} }
catch(Exception ex) catch (Exception ex)
{ {
Logging.Log(Logging.LogType.Warning, "Metadata", "An error occurred fetching Platform Id " + Id, ex); Logging.Log(Logging.LogType.Warning, "Metadata", "An error occurred fetching Platform Id " + Id, ex);
return null; return null;
@@ -52,14 +52,14 @@ namespace gaseous_server.Classes.Metadata
} }
} }
public static Platform GetPlatform(string Slug, bool forceRefresh = false) public static Platform GetPlatform(string Slug, bool forceRefresh = false, bool GetImages = false)
{ {
Task<Platform> RetVal = _GetPlatform(SearchUsing.slug, Slug, forceRefresh); Task<Platform> RetVal = _GetPlatform(SearchUsing.slug, Slug, forceRefresh, GetImages);
return RetVal.Result; return RetVal.Result;
} }
private static async Task<Platform> _GetPlatform(SearchUsing searchUsing, object searchValue, bool forceRefresh) private static async Task<Platform> _GetPlatform(SearchUsing searchUsing, object searchValue, bool forceRefresh, bool GetImages)
{ {
// check database first // check database first
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus(); Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
if (searchUsing == SearchUsing.id) if (searchUsing == SearchUsing.id)
@@ -96,7 +96,7 @@ namespace gaseous_server.Classes.Metadata
case Storage.CacheStatus.NotPresent: case Storage.CacheStatus.NotPresent:
returnValue = await GetObjectFromServer(WhereClause); returnValue = await GetObjectFromServer(WhereClause);
Storage.NewCacheValue(returnValue); Storage.NewCacheValue(returnValue);
UpdateSubClasses(returnValue); UpdateSubClasses(returnValue, GetImages);
AddPlatformMapping(returnValue); AddPlatformMapping(returnValue);
return returnValue; return returnValue;
case Storage.CacheStatus.Expired: case Storage.CacheStatus.Expired:
@@ -104,7 +104,7 @@ namespace gaseous_server.Classes.Metadata
{ {
returnValue = await GetObjectFromServer(WhereClause); returnValue = await GetObjectFromServer(WhereClause);
Storage.NewCacheValue(returnValue, true); Storage.NewCacheValue(returnValue, true);
UpdateSubClasses(returnValue); UpdateSubClasses(returnValue, GetImages);
AddPlatformMapping(returnValue); AddPlatformMapping(returnValue);
return 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) 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)); try
} {
catch (Exception ex) PlatformLogo platformLogo = PlatformLogos.GetPlatformLogo(platform.PlatformLogo.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Platform(platform));
{ }
Logging.Log(Logging.LogType.Warning, "Platform Update", "Unable to fetch platform logo", ex); 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."); Logging.Log(Logging.LogType.Information, "Platform Map", "Importing " + platform.Name + " from predefined data.");
// doesn't exist - add it // doesn't exist - add it
item = new Models.PlatformMapping.PlatformMapItem{ item = new Models.PlatformMapping.PlatformMapItem
{
IGDBId = (long)platform.Id, IGDBId = (long)platform.Id,
IGDBName = platform.Name, IGDBName = platform.Name,
IGDBSlug = platform.Slug, IGDBSlug = platform.Slug,
AlternateNames = new List<string>{ platform.AlternativeName } AlternateNames = new List<string> { platform.AlternativeName }
}; };
Models.PlatformMapping.WritePlatformMap(item, false, true); Models.PlatformMapping.WritePlatformMap(item, false, true);
} }

View File

@@ -13,8 +13,8 @@ using Newtonsoft.Json;
namespace gaseous_server.Models namespace gaseous_server.Models
{ {
public class PlatformMapping public class PlatformMapping
{ {
private static Dictionary<string, PlatformMapItem> PlatformMapCache = new Dictionary<string, PlatformMapItem>(); private static Dictionary<string, PlatformMapItem> PlatformMapCache = new Dictionary<string, PlatformMapItem>();
/// <summary> /// <summary>
@@ -27,7 +27,8 @@ namespace gaseous_server.Models
{ {
string rawJson = reader.ReadToEnd(); string rawJson = reader.ReadToEnd();
List<PlatformMapItem> platforms = new List<PlatformMapItem>(); List<PlatformMapItem> platforms = new List<PlatformMapItem>();
Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings{ Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
{
MaxDepth = 64 MaxDepth = 64
}; };
platforms = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PlatformMapItem>>(rawJson, jsonSerializerSettings); platforms = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PlatformMapItem>>(rawJson, jsonSerializerSettings);
@@ -74,7 +75,7 @@ namespace gaseous_server.Models
foreach (PlatformMapItem mapItem in platforms) foreach (PlatformMapItem mapItem in platforms)
{ {
// get the IGDB platform data // get the IGDB platform data
Platform platform = Platforms.GetPlatform(mapItem.IGDBId); Platform platform = Platforms.GetPlatform(mapItem.IGDBId, false);
try try
{ {
@@ -92,7 +93,7 @@ namespace gaseous_server.Models
} }
} }
} }
public static List<PlatformMapItem> PlatformMap public static List<PlatformMapItem> PlatformMap
{ {
get 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); Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = ""; string sql = "";
@@ -286,7 +287,7 @@ namespace gaseous_server.Models
string sql = ""; string sql = "";
// get platform data // get platform data
IGDB.Models.Platform? platform = Platforms.GetPlatform(IGDBId); IGDB.Models.Platform? platform = Platforms.GetPlatform(IGDBId, false);
if (platform != null) if (platform != null)
{ {
@@ -369,18 +370,20 @@ namespace gaseous_server.Models
mapItem.IGDBName = platform.Name; mapItem.IGDBName = platform.Name;
mapItem.IGDBSlug = platform.Slug; mapItem.IGDBSlug = platform.Slug;
mapItem.AlternateNames = alternateNames; mapItem.AlternateNames = alternateNames;
mapItem.Extensions = new PlatformMapItem.FileExtensions{ mapItem.Extensions = new PlatformMapItem.FileExtensions
{
SupportedFileExtensions = knownExtensions, SupportedFileExtensions = knownExtensions,
UniqueFileExtensions = uniqueExtensions UniqueFileExtensions = uniqueExtensions
}; };
mapItem.RetroPieDirectoryName = (string)Common.ReturnValueIfNull(row["RetroPieDirectoryName"], ""); mapItem.RetroPieDirectoryName = (string)Common.ReturnValueIfNull(row["RetroPieDirectoryName"], "");
mapItem.WebEmulator = new PlatformMapItem.WebEmulatorItem{ mapItem.WebEmulator = new PlatformMapItem.WebEmulatorItem
{
Type = (string)Common.ReturnValueIfNull(row["WebEmulator_Type"], ""), Type = (string)Common.ReturnValueIfNull(row["WebEmulator_Type"], ""),
Core = (string)Common.ReturnValueIfNull(row["WebEmulator_Core"], ""), Core = (string)Common.ReturnValueIfNull(row["WebEmulator_Core"], ""),
AvailableWebEmulators = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PlatformMapItem.WebEmulatorItem.AvailableWebEmulatorItem>>((string)Common.ReturnValueIfNull(row["AvailableWebEmulators"], "[]")) AvailableWebEmulators = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PlatformMapItem.WebEmulatorItem.AvailableWebEmulatorItem>>((string)Common.ReturnValueIfNull(row["AvailableWebEmulators"], "[]"))
}; };
mapItem.Bios = bioss; mapItem.Bios = bioss;
if (PlatformMapCache.ContainsKey(IGDBId.ToString())) if (PlatformMapCache.ContainsKey(IGDBId.ToString()))
{ {
PlatformMapCache[IGDBId.ToString()] = mapItem; PlatformMapCache[IGDBId.ToString()] = mapItem;
@@ -461,7 +464,7 @@ namespace gaseous_server.Models
public string IGDBName { get; set; } public string IGDBName { get; set; }
public string IGDBSlug { get; set; } public string IGDBSlug { get; set; }
public List<string> AlternateNames { get; set; } = new List<string>(); public List<string> AlternateNames { get; set; } = new List<string>();
public FileExtensions Extensions { get; set; } public FileExtensions Extensions { get; set; }
public class FileExtensions public class FileExtensions
{ {
@@ -503,6 +506,6 @@ namespace gaseous_server.Models
public string filename { get; set; } public string filename { get; set; }
} }
} }
} }
} }