This commit is contained in:
Michael Green
2024-12-14 22:02:32 +11:00
parent 2303ab5ffc
commit 142f3ed561
6 changed files with 66 additions and 27 deletions

View File

@@ -30,6 +30,7 @@ namespace gaseous_server.Classes.Metadata
{
Game? RetVal = Metadata.GetMetadata<Game>(SourceType, (long)Id, false);
RetVal.MetadataSource = SourceType;
RetVal.MetadataMapId = (long)Id;
RetVal = MassageResult(RetVal);
return RetVal;
}
@@ -267,7 +268,7 @@ FROM
LEFT JOIN
view_Games_Roms AS GFV ON GFV.Id = User_GameFavouriteRoms.RomId
WHERE
view_Games_Roms.GameId = @gameid
view_Games_Roms.MetadataMapId = @gameid
ORDER BY Platform.`Name`;";
Dictionary<string, object> dbDict = new Dictionary<string, object>
{

View File

@@ -93,13 +93,21 @@ namespace gaseous_server.Classes.Metadata
// check cached metadata status
// if metadata is not cached or expired, get it from the source. Otherwise, return the cached metadata
Storage.CacheStatus? cacheStatus;
if (idType == IdType.Long)
if (SourceType == HasheousClient.Models.MetadataSources.None)
{
cacheStatus = Storage.GetCacheStatus(SourceType, type, (long)Id);
// if source is None, set cache status to current
cacheStatus = Storage.CacheStatus.Current;
}
else
{
cacheStatus = Storage.GetCacheStatus(SourceType, type, (string)Id);
if (idType == IdType.Long)
{
cacheStatus = Storage.GetCacheStatus(SourceType, type, (long)Id);
}
else
{
cacheStatus = Storage.GetCacheStatus(SourceType, type, (string)Id);
}
}
// if ForceRefresh is true, set cache status to expired if it is current

View File

@@ -38,7 +38,7 @@ namespace gaseous_server.Classes
string NameSearchWhere = "";
if (NameSearch.Length > 0)
{
NameSearchWhere = " AND view_Games_Roms.`Name` LIKE @namesearch";
NameSearchWhere = " AND Games_Roms.`Name` LIKE @namesearch";
dbDict.Add("namesearch", '%' + NameSearch + '%');
}
@@ -50,46 +50,69 @@ namespace gaseous_server.Classes
UserJoin = @"
LEFT JOIN
User_RecentPlayedRoms ON User_RecentPlayedRoms.UserId = @userid
AND User_RecentPlayedRoms.GameId = view_Games_Roms.GameId
AND User_RecentPlayedRoms.PlatformId = view_Games_Roms.PlatformId
AND User_RecentPlayedRoms.RomId = view_Games_Roms.Id
AND User_RecentPlayedRoms.GameId = Games_Roms.MetadataMapId
AND User_RecentPlayedRoms.PlatformId = Games_Roms.PlatformId
AND User_RecentPlayedRoms.RomId = Games_Roms.Id
AND User_RecentPlayedRoms.IsMediaGroup = 0
LEFT JOIN
User_GameFavouriteRoms ON User_GameFavouriteRoms.UserId = @userid
AND User_GameFavouriteRoms.GameId = view_Games_Roms.GameId
AND User_GameFavouriteRoms.PlatformId = view_Games_Roms.PlatformId
AND User_GameFavouriteRoms.RomId = view_Games_Roms.Id
AND User_GameFavouriteRoms.GameId = Games_Roms.MetadataMapId
AND User_GameFavouriteRoms.PlatformId = Games_Roms.PlatformId
AND User_GameFavouriteRoms.RomId = Games_Roms.Id
AND User_GameFavouriteRoms.IsMediaGroup = 0
";
}
// platform query
sqlPlatform = "SELECT DISTINCT view_Games_Roms.PlatformId, Platform.`Name` FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id WHERE GameId = @id ORDER BY Platform.`Name`;";
sqlPlatform = "SELECT DISTINCT Games_Roms.PlatformId, Platform.`Name` FROM Games_Roms LEFT JOIN Platform ON Games_Roms.PlatformId = Platform.Id WHERE GameId = @id ORDER BY Platform.`Name`;";
if (PlatformId == -1)
{
// data query
sql = "SELECT DISTINCT view_Games_Roms.*, Platform.`Name` AS platformname, Game.`Name` AS gamename, GameState.RomId AS SavedStateRomId" + UserFields + " FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id LEFT JOIN Game ON view_Games_Roms.GameId = Game.Id LEFT JOIN GameState ON (view_Games_Roms.Id = GameState.RomId AND GameState.UserId = @userid AND GameState.IsMediaGroup = 0) " + UserJoin + " WHERE view_Games_Roms.GameId = @id" + NameSearchWhere + " ORDER BY Platform.`Name`, view_Games_Roms.`Name` LIMIT 1000;";
sql = "SELECT DISTINCT view_Games_Roms.*, Platform.`Name` AS platformname, Game.`Name` AS gamename, GameState.RomId AS SavedStateRomId" + UserFields + " FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id LEFT JOIN Game ON view_Games_Roms.GameId = Game.Id LEFT JOIN GameState ON (view_Games_Roms.Id = GameState.RomId AND GameState.UserId = @userid AND GameState.IsMediaGroup = 0) " + UserJoin + " WHERE view_Games_Roms.MetadataMapId = @id" + NameSearchWhere + " ORDER BY Platform.`Name`, view_Games_Roms.`Name`;";
// count query
sqlCount = "SELECT COUNT(view_Games_Roms.Id) AS RomCount FROM view_Games_Roms WHERE view_Games_Roms.GameId = @id" + NameSearchWhere + ";";
sqlCount = "SELECT COUNT(view_Games_Roms.Id) AS RomCount FROM view_Games_Roms WHERE view_Games_Roms.MetadataMapId = @id" + NameSearchWhere + ";";
}
else
{
// data query
sql = "SELECT DISTINCT view_Games_Roms.*, Platform.`Name` AS platformname, Game.`Name` AS gamename, GameState.RomId AS SavedStateRomId" + UserFields + " FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id LEFT JOIN Game ON view_Games_Roms.GameId = Game.Id LEFT JOIN GameState ON (view_Games_Roms.Id = GameState.RomId AND GameState.UserId = @userid AND GameState.IsMediaGroup = 0) " + UserJoin + " WHERE view_Games_Roms.GameId = @id AND view_Games_Roms.PlatformId = @platformid" + NameSearchWhere + " ORDER BY Platform.`Name`, view_Games_Roms.`Name` LIMIT 1000;";
sql = @"
SELECT DISTINCT
Games_Roms.*,
Platform.`Name` AS platformname,
view_GamesWithRoms.`Name` AS gamename,
GameState.RomId AS SavedStateRomId,
CONCAT(`GameLibraries`.`Path`,
'/',
`Games_Roms`.`RelativePath`) AS `Path`,
`GameLibraries`.`Name` AS `LibraryName`
" + UserFields + @"
FROM
Games_Roms
JOIN
GameLibraries ON Games_Roms.LibraryId = GameLibraries.Id
LEFT JOIN
Platform ON Games_Roms.PlatformId = Platform.Id LEFT JOIN view_GamesWithRoms ON view_GamesWithRoms.MetadataMapId = Games_Roms.MetadataMapId
LEFT JOIN
GameState ON (Games_Roms.Id = GameState.RomId AND GameState.UserId = @userid AND GameState.IsMediaGroup = 0) " + UserJoin + @"
WHERE
Games_Roms.MetadataMapId = @id AND Games_Roms.PlatformId = @platformid" + NameSearchWhere + @"
ORDER BY
Platform.`Name`, Games_Roms.`Name`;
";
// count query
sqlCount = "SELECT COUNT(view_Games_Roms.Id) AS RomCount FROM view_Games_Roms WHERE view_Games_Roms.GameId = @id AND view_Games_Roms.PlatformId = @platformid" + NameSearchWhere + ";";
sqlCount = "SELECT COUNT(Games_Roms.Id) AS RomCount FROM Games_Roms WHERE Games_Roms.MetadataMapId = @id AND Games_Roms.PlatformId = @platformid" + NameSearchWhere + ";";
dbDict.Add("platformid", PlatformId);
}
DataTable romDT = db.ExecuteCMD(sql, dbDict, new Database.DatabaseMemoryCacheOptions(true, (int)TimeSpan.FromMinutes(1).Ticks));
Dictionary<string, object> rowCount = db.ExecuteCMDDict(sqlCount, dbDict, new Database.DatabaseMemoryCacheOptions(true, (int)TimeSpan.FromMinutes(1).Ticks))[0];
if (romDT.Rows.Count > 0)
{
// set count of roms
Dictionary<string, object> rowCount = db.ExecuteCMDDict(sqlCount, dbDict, new Database.DatabaseMemoryCacheOptions(true, (int)TimeSpan.FromMinutes(1).Ticks))[0];
GameRoms.Count = int.Parse((string)rowCount["RomCount"]);
int pageOffset = pageSize * (pageNumber - 1);
@@ -113,7 +136,7 @@ namespace gaseous_server.Classes
public static GameRomItem GetRom(long RomId)
{
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT DISTINCT view_Games_Roms.*, Platform.`Name` AS platformname, view_GamesWithRoms.`Name` AS gamename FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id LEFT JOIN view_GamesWithRoms ON view_Games_Roms.GameId = view_GamesWithRoms.Id WHERE view_Games_Roms.Id = @id";
string sql = "SELECT DISTINCT view_Games_Roms.*, Platform.`Name` AS platformname, view_GamesWithRoms.`Name` AS gamename FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id LEFT JOIN view_GamesWithRoms ON view_Games_Roms.MetadataMapId = view_GamesWithRoms.MetadataMapId WHERE view_Games_Roms.Id = @id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", RomId);
DataTable romDT = db.ExecuteCMD(sql, dbDict);
@@ -133,7 +156,7 @@ namespace gaseous_server.Classes
public static GameRomItem GetRom(string MD5)
{
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT DISTINCT view_Games_Roms.*, Platform.`Name` AS platformname, view_GamesWithRoms.`Name` AS gamename FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id LEFT JOIN view_GamesWithRoms ON view_Games_Roms.GameId = view_GamesWithRoms.Id WHERE view_Games_Roms.MD5 = @id";
string sql = "SELECT DISTINCT view_Games_Roms.*, Platform.`Name` AS platformname, view_GamesWithRoms.`Name` AS gamename FROM view_Games_Roms LEFT JOIN Platform ON view_Games_Roms.PlatformId = Platform.Id LEFT JOIN view_GamesWithRoms ON view_Games_Roms.MetadataMapId = view_GamesWithRoms.MetadataMapId WHERE view_Games_Roms.MD5 = @id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", MD5);
DataTable romDT = db.ExecuteCMD(sql, dbDict);
@@ -159,7 +182,7 @@ namespace gaseous_server.Classes
Models.Game game = Classes.Metadata.Games.GetGame(HasheousClient.Models.MetadataSources.IGDB, GameId);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "UPDATE Games_Roms SET PlatformId=@platformid, GameId=@gameid WHERE Id = @id";
string sql = "UPDATE Games_Roms SET PlatformId=@platformid, MetadataMapId=@gameid WHERE Id = @id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", RomId);
dbDict.Add("platformid", PlatformId);
@@ -269,6 +292,8 @@ namespace gaseous_server.Classes
Id = (long)romDR["id"],
PlatformId = (long)romDR["platformid"],
Platform = (string)romDR["platformname"],
MetadataMapId = (long)romDR["metadatamapid"],
MetadataSource = (HasheousClient.Models.MetadataSources)(int)romDR["metadatasource"],
GameId = (long)romDR["gameid"],
Game = (string)Common.ReturnValueIfNull(romDR["gamename"], ""),
Name = (string)romDR["name"],
@@ -320,6 +345,8 @@ namespace gaseous_server.Classes
{
public long PlatformId { get; set; }
public string Platform { get; set; }
public long MetadataMapId { get; set; }
public HasheousClient.Models.MetadataSources MetadataSource { get; set; }
public long GameId { get; set; }
public string Game { get; set; }
public string? Path { get; set; }

View File

@@ -1151,7 +1151,7 @@ namespace gaseous_server.Controllers
gaseous_server.Models.Game game = Classes.Metadata.Games.GetGame(metadataMap.SourceType, metadataMap.SourceId);
Classes.Roms.GameRomItem rom = Classes.Roms.GetRom(RomId);
if (rom.GameId == MetadataMapId)
if (rom.MetadataMapId == MetadataMapId)
{
return Ok(rom);
}
@@ -1212,7 +1212,7 @@ namespace gaseous_server.Controllers
gaseous_server.Models.Game game = Classes.Metadata.Games.GetGame(metadataMap.SourceType, metadataMap.SourceId);
Classes.Roms.GameRomItem rom = Classes.Roms.GetRom(RomId);
if (rom.GameId == MetadataMapId)
if (rom.MetadataMapId == MetadataMapId)
{
Classes.Roms.DeleteRom(RomId);
return Ok(rom);
@@ -1246,7 +1246,7 @@ namespace gaseous_server.Controllers
if (IsMediaGroup == false)
{
Classes.Roms.GameRomItem rom = Classes.Roms.GetRom(RomId);
if (rom.GameId == MetadataMapId)
if (rom.MetadataMapId == MetadataMapId)
{
if (favourite == true)
{
@@ -1347,7 +1347,7 @@ namespace gaseous_server.Controllers
gaseous_server.Models.Game game = Classes.Metadata.Games.GetGame(metadataMap.SourceType, metadataMap.SourceId);
Classes.Roms.GameRomItem rom = Classes.Roms.GetRom(RomId);
if (rom.GameId != MetadataMapId || rom.Name != FileName)
if (rom.MetadataMapId != MetadataMapId || rom.Name != FileName)
{
return NotFound();
}

View File

@@ -13,7 +13,6 @@ function SetupPage() {
document.head.appendChild(mappingScript);
ajaxCall('/api/v1.1/Games/' + gameId, 'GET', function (result) {
console.log(result);
// populate games page
gameData = result;
@@ -934,6 +933,7 @@ class RomManagement {
}).then(async response => {
if (response.ok) {
let result = await response.json();
console.log(result);
let romCount = this.romsModal.modalElement.querySelector('#games_roms_count');
this.RomCount = result.count;
if (result.count != 1) {

View File

@@ -3,8 +3,11 @@
<div id="gamesummarymediagroupscontent" class="section-body"></div>
</div>
<div id="gamesummaryroms" class="section">
<span id="rom_edit" class="romlink">Edit</span>
<div class="section-header">ROMs/Images</div>
<div class="section-header">
<span id="rom_edit" class="romlink">Edit</span>
<span>ROMs/Images</span>
</div>
<div class="section-body">
<div id="rom_edit_panel" style="display: none;">
<div id="rom_edit_panel_center">