diff --git a/gaseous-server/Classes/Roms.cs b/gaseous-server/Classes/Roms.cs index a36decd..aed8ca7 100644 --- a/gaseous-server/Classes/Roms.cs +++ b/gaseous-server/Classes/Roms.cs @@ -50,6 +50,40 @@ namespace gaseous_server.Classes } } + public static RomItem UpdateRom(long RomId, long PlatformId, long GameId) + { + // ensure metadata for platformid is present + IGDB.Models.Platform platform = Classes.Metadata.Platforms.GetPlatform(PlatformId); + + // ensure metadata for gameid is present + IGDB.Models.Game game = Classes.Metadata.Games.GetGame(GameId, false, false); + + Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "UPDATE games_roms SET platformid=@platformid, gameid=@gameid WHERE id = @id"; + Dictionary dbDict = new Dictionary(); + dbDict.Add("id", RomId); + dbDict.Add("platformid", PlatformId); + dbDict.Add("gameid", GameId); + db.ExecuteCMD(sql, dbDict); + + RomItem rom = GetRom(RomId); + + return rom; + } + + public static void DeleteRom(long RomId) + { + RomItem rom = GetRom(RomId); + if (File.Exists(rom.Path)) + { + File.Delete(rom.Path); + } + + Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "DELETE FROM games_roms WHERE id = @id"; + db.ExecuteCMD(sql); + } + private static RomItem BuildRom(DataRow romDR) { RomItem romItem = new RomItem diff --git a/gaseous-server/Controllers/GamesController.cs b/gaseous-server/Controllers/GamesController.cs index 3e44bf2..37371e9 100644 --- a/gaseous-server/Controllers/GamesController.cs +++ b/gaseous-server/Controllers/GamesController.cs @@ -479,6 +479,60 @@ namespace gaseous_server.Controllers } } + [HttpPatch] + [Route("{GameId}/roms/{RomId}")] + [ProducesResponseType(typeof(Classes.Roms.RomItem), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult GameRomRename(long GameId, long RomId, long NewPlatformId, long NewGameId) + { + try + { + Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false); + + Classes.Roms.RomItem rom = Classes.Roms.GetRom(RomId); + if (rom.GameId == GameId) + { + rom = Classes.Roms.UpdateRom(RomId, NewPlatformId, NewGameId); + return Ok(rom); + } + else + { + return NotFound(); + } + } + catch + { + return NotFound(); + } + } + + [HttpDelete] + [Route("{GameId}/roms/{RomId}")] + [ProducesResponseType(typeof(Classes.Roms.RomItem), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult GameRomDelete(long GameId, long RomId) + { + try + { + Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false); + + Classes.Roms.RomItem rom = Classes.Roms.GetRom(RomId); + if (rom.GameId == GameId) + { + Classes.Roms.DeleteRom(RomId); + return Ok(rom); + } + else + { + return NotFound(); + } + } + catch + { + return NotFound(); + } + } + [HttpGet] [Route("{GameId}/roms/{RomId}/file")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)]