Skip to content

Commit

Permalink
Fixed import of MAME style DATs (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-j-green authored Jul 22, 2024
1 parent 1672520 commit d7fca42
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gaseous-server/Classes/SignatureIngestors/XML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void Import(string SearchPath, gaseous_signature_parser.parser.SignatureP
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<string, object>();
dbDict.Add("gameid", gameId);
dbDict.Add("name", Common.ReturnValueIfNull(romObject.Name, ""));
Expand Down
42 changes: 42 additions & 0 deletions gaseous-server/Classes/SignatureManagement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data;
using gaseous_server.Models;
using gaseous_signature_parser.models.RomSignatureObject;

namespace gaseous_server.Classes
Expand Down Expand Up @@ -79,5 +80,46 @@ public class SignatureManagement
}
return GamesList;
}

public List<Signatures_Sources> 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<Signatures_Sources> SourcesList = new List<Signatures_Sources>();

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<string, object> dbDict = new Dictionary<string, object>
{
{ "sourceId", sourceId }
};
db.ExecuteCMD(sql, dbDict);
}
}
}
26 changes: 25 additions & 1 deletion gaseous-server/Controllers/V1.0/SignaturesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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

Expand Down Expand Up @@ -54,11 +55,34 @@ public Models.Signatures_Status Status()
{
SignatureManagement signatureManagement = new SignatureManagement();
return signatureManagement.GetByTosecName(TosecName);
} else
}
else
{
return null;
}
}

[MapToApiVersion("1.0")]
[MapToApiVersion("1.1")]
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public List<Signatures_Sources> 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();
}
}
}

20 changes: 20 additions & 0 deletions gaseous-server/Models/Signatures_Sources.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}

0 comments on commit d7fca42

Please sign in to comment.