From d7fca420578ca90bdc716e2d55bd8b26dcabbe45 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:51:57 +1000 Subject: [PATCH] Fixed import of MAME style DATs (#400) --- .../Classes/SignatureIngestors/XML.cs | 2 +- gaseous-server/Classes/SignatureManagement.cs | 42 +++++++++++++++++++ .../Controllers/V1.0/SignaturesController.cs | 26 +++++++++++- gaseous-server/Models/Signatures_Sources.cs | 20 +++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 gaseous-server/Models/Signatures_Sources.cs diff --git a/gaseous-server/Classes/SignatureIngestors/XML.cs b/gaseous-server/Classes/SignatureIngestors/XML.cs index b3f05c2..75eb02f 100644 --- a/gaseous-server/Classes/SignatureIngestors/XML.cs +++ b/gaseous-server/Classes/SignatureIngestors/XML.cs @@ -194,7 +194,7 @@ namespace gaseous_server.SignatureIngestors.XML if (romObject.Md5 != null || romObject.Sha1 != null) { int romId = 0; - sql = "SELECT * FROM Signatures_Roms WHERE GameId=@gameid AND MD5=@md5"; + sql = "SELECT * FROM Signatures_Roms WHERE `GameId`=@gameid AND (`MD5`=@md5 AND `SHA1`=@sha1)"; dbDict = new Dictionary(); dbDict.Add("gameid", gameId); dbDict.Add("name", Common.ReturnValueIfNull(romObject.Name, "")); diff --git a/gaseous-server/Classes/SignatureManagement.cs b/gaseous-server/Classes/SignatureManagement.cs index f8dae08..f56792f 100644 --- a/gaseous-server/Classes/SignatureManagement.cs +++ b/gaseous-server/Classes/SignatureManagement.cs @@ -1,4 +1,5 @@ using System.Data; +using gaseous_server.Models; using gaseous_signature_parser.models.RomSignatureObject; namespace gaseous_server.Classes @@ -79,5 +80,46 @@ namespace gaseous_server.Classes } return GamesList; } + + public List GetSources() + { + Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "SELECT * FROM Signatures_Sources ORDER BY `SourceType`, `Name`;"; + DataTable sigDb = db.ExecuteCMD(sql); + + List SourcesList = new List(); + + foreach (DataRow sigDbRow in sigDb.Rows) + { + Signatures_Sources sourceItem = new Signatures_Sources + { + Id = (int)sigDbRow["Id"], + Name = (string)sigDbRow["Name"], + Description = (string)sigDbRow["Description"], + URL = (string)sigDbRow["URL"], + Category = (string)sigDbRow["Category"], + Version = (string)sigDbRow["Version"], + Author = (string)sigDbRow["Author"], + Email = (string)sigDbRow["Email"], + Homepage = (string)sigDbRow["Homepage"], + SourceType = (gaseous_signature_parser.parser.SignatureParser)Enum.Parse(typeof(gaseous_signature_parser.parser.SignatureParser), sigDbRow["SourceType"].ToString()), + MD5 = (string)sigDbRow["SourceMD5"], + SHA1 = (string)sigDbRow["SourceSHA1"] + }; + SourcesList.Add(sourceItem); + } + return SourcesList; + } + + public void DeleteSource(int sourceId) + { + Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "DELETE FROM Signatures_Sources WHERE Id = @sourceId;"; + Dictionary dbDict = new Dictionary + { + { "sourceId", sourceId } + }; + db.ExecuteCMD(sql, dbDict); + } } } \ No newline at end of file diff --git a/gaseous-server/Controllers/V1.0/SignaturesController.cs b/gaseous-server/Controllers/V1.0/SignaturesController.cs index 2d85377..3a87437 100644 --- a/gaseous-server/Controllers/V1.0/SignaturesController.cs +++ b/gaseous-server/Controllers/V1.0/SignaturesController.cs @@ -9,6 +9,7 @@ using gaseous_signature_parser.models.RomSignatureObject; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Asp.Versioning; +using gaseous_server.Models; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -54,11 +55,34 @@ namespace gaseous_server.Controllers { SignatureManagement signatureManagement = new SignatureManagement(); return signatureManagement.GetByTosecName(TosecName); - } else + } + else { return null; } } + + [MapToApiVersion("1.0")] + [MapToApiVersion("1.1")] + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public List GetSignatureSources() + { + SignatureManagement signatureManagement = new SignatureManagement(); + return signatureManagement.GetSources(); + } + + [MapToApiVersion("1.0")] + [MapToApiVersion("1.1")] + [HttpDelete] + [ProducesResponseType(StatusCodes.Status200OK)] + public IActionResult DeleteSignatureSource(int Id) + { + SignatureManagement signatureManagement = new SignatureManagement(); + signatureManagement.DeleteSource(Id); + + return Ok(); + } } } diff --git a/gaseous-server/Models/Signatures_Sources.cs b/gaseous-server/Models/Signatures_Sources.cs new file mode 100644 index 0000000..d1d9192 --- /dev/null +++ b/gaseous-server/Models/Signatures_Sources.cs @@ -0,0 +1,20 @@ +using NuGet.Protocol.Core.Types; + +namespace gaseous_server.Models +{ + public class Signatures_Sources + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public string URL { get; set; } + public string Category { get; set; } + public string Version { get; set; } + public string Author { get; set; } + public string Email { get; set; } + public string Homepage { get; set; } + public gaseous_signature_parser.parser.SignatureParser SourceType { get; set; } + public string MD5 { get; set; } + public string SHA1 { get; set; } + } +} \ No newline at end of file