Provide a platform override option during web based import (#94)
This commit is contained in:
@@ -23,7 +23,7 @@ namespace gaseous_server.Classes
|
|||||||
|
|
||||||
// import files first
|
// import files first
|
||||||
foreach (string importContent in importContents_Files) {
|
foreach (string importContent in importContents_Files) {
|
||||||
ImportGame.ImportGameFile(importContent);
|
ImportGame.ImportGameFile(importContent, null, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -38,7 +38,7 @@ namespace gaseous_server.Classes
|
|||||||
|
|
||||||
public class ImportGame
|
public class ImportGame
|
||||||
{
|
{
|
||||||
public static void ImportGameFile(string GameFileImportPath, bool IsDirectory = false, bool ForceImport = false)
|
public static void ImportGameFile(string GameFileImportPath, IGDB.Models.Platform? OverridePlatform, bool IsDirectory = false)
|
||||||
{
|
{
|
||||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "";
|
string sql = "";
|
||||||
@@ -50,7 +50,6 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Logging.Log(Logging.LogType.Information, "Import Game", "Processing item " + GameFileImportPath);
|
|
||||||
if (IsDirectory == false)
|
if (IsDirectory == false)
|
||||||
{
|
{
|
||||||
FileInfo fi = new FileInfo(GameFileImportPath);
|
FileInfo fi = new FileInfo(GameFileImportPath);
|
||||||
@@ -80,11 +79,21 @@ namespace gaseous_server.Classes
|
|||||||
Models.Signatures_Games discoveredSignature = GetFileSignature(hash, fi, GameFileImportPath);
|
Models.Signatures_Games discoveredSignature = GetFileSignature(hash, fi, GameFileImportPath);
|
||||||
|
|
||||||
// get discovered platform
|
// get discovered platform
|
||||||
IGDB.Models.Platform determinedPlatform = Metadata.Platforms.GetPlatform(discoveredSignature.Flags.IGDBPlatformId);
|
IGDB.Models.Platform? determinedPlatform = null;
|
||||||
|
if (OverridePlatform == null)
|
||||||
|
{
|
||||||
|
determinedPlatform = Metadata.Platforms.GetPlatform(discoveredSignature.Flags.IGDBPlatformId);
|
||||||
if (determinedPlatform == null)
|
if (determinedPlatform == null)
|
||||||
{
|
{
|
||||||
determinedPlatform = new IGDB.Models.Platform();
|
determinedPlatform = new IGDB.Models.Platform();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
determinedPlatform = OverridePlatform;
|
||||||
|
discoveredSignature.Flags.IGDBPlatformId = (long)determinedPlatform.Id;
|
||||||
|
discoveredSignature.Flags.IGDBPlatformName = determinedPlatform.Name;
|
||||||
|
}
|
||||||
|
|
||||||
IGDB.Models.Game determinedGame = SearchForGame(discoveredSignature.Game.Name, discoveredSignature.Flags.IGDBPlatformId);
|
IGDB.Models.Game determinedGame = SearchForGame(discoveredSignature.Game.Name, discoveredSignature.Flags.IGDBPlatformId);
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ namespace gaseous_server.Controllers
|
|||||||
[ProducesResponseType(typeof(List<IFormFile>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(List<IFormFile>), StatusCodes.Status200OK)]
|
||||||
[RequestSizeLimit(long.MaxValue)]
|
[RequestSizeLimit(long.MaxValue)]
|
||||||
[DisableRequestSizeLimit, RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue, ValueLengthLimit = int.MaxValue)]
|
[DisableRequestSizeLimit, RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue, ValueLengthLimit = int.MaxValue)]
|
||||||
public async Task<IActionResult> UploadRom(List<IFormFile> files)
|
public async Task<IActionResult> UploadRom(List<IFormFile> files, long? OverridePlatformId = null)
|
||||||
{
|
{
|
||||||
Guid sessionid = Guid.NewGuid();
|
Guid sessionid = Guid.NewGuid();
|
||||||
|
|
||||||
@@ -61,12 +61,17 @@ namespace gaseous_server.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process uploaded files
|
// get override platform if specified
|
||||||
// Don't rely on or trust the FileName property without validation.
|
IGDB.Models.Platform? OverridePlatform = null;
|
||||||
|
if (OverridePlatformId != null)
|
||||||
|
{
|
||||||
|
OverridePlatform = Platforms.GetPlatform((long)OverridePlatformId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process uploaded files
|
||||||
foreach (Dictionary<string, object> UploadedFile in UploadedFiles)
|
foreach (Dictionary<string, object> UploadedFile in UploadedFiles)
|
||||||
{
|
{
|
||||||
Classes.ImportGame.ImportGameFile((string)UploadedFile["fullpath"]);
|
Classes.ImportGame.ImportGameFile((string)UploadedFile["fullpath"], OverridePlatform, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Directory.Exists(workPath))
|
if (Directory.Exists(workPath))
|
||||||
|
@@ -12,9 +12,20 @@
|
|||||||
<div>
|
<div>
|
||||||
<div id="upload_target" class="dropzone"></div>
|
<div id="upload_target" class="dropzone"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<table style="width: 100%;">
|
||||||
|
<tr>
|
||||||
|
<th style="width: 40%;">
|
||||||
|
Override automatic platform detection:
|
||||||
|
</th>
|
||||||
|
<td style="width: 60%;">
|
||||||
|
<select id="upload_platformoverride" style="width: 100%;"></select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
document.getElementById('modal-heading').innerHTML = "Upload";
|
document.getElementById('modal-heading').innerHTML = "Upload";
|
||||||
|
document.getElementById('upload_platformoverride').innerHTML = "<option value='0' selected='selected'>Automatic Platform</option>";
|
||||||
|
|
||||||
var myDropzone = new Dropzone("div#upload_target", {
|
var myDropzone = new Dropzone("div#upload_target", {
|
||||||
url: "/api/v1/Roms",
|
url: "/api/v1/Roms",
|
||||||
@@ -69,4 +80,51 @@
|
|||||||
subModalContent.innerHTML = "";
|
subModalContent.innerHTML = "";
|
||||||
subModalVariables = null;
|
subModalVariables = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#upload_platformoverride').select2({
|
||||||
|
minimumInputLength: 3,
|
||||||
|
ajax: {
|
||||||
|
url: '/api/v1/Search/Platform',
|
||||||
|
data: function (params) {
|
||||||
|
var query = {
|
||||||
|
SearchString: params.term
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query parameters will be ?SearchString=[term]
|
||||||
|
return query;
|
||||||
|
},
|
||||||
|
processResults: function (data) {
|
||||||
|
var arr = [];
|
||||||
|
|
||||||
|
// insert automatic detection item
|
||||||
|
arr.push({
|
||||||
|
id: 0,
|
||||||
|
text: "Automatic Platform"
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
arr.push({
|
||||||
|
id: data[i].id,
|
||||||
|
text: data[i].name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
results: arr
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#upload_platformoverride').on('select2:select', function (e) {
|
||||||
|
var platformOverride = $('#upload_platformoverride').select2('data');
|
||||||
|
var queryString = '';
|
||||||
|
if (Number(platformOverride[0].id) != 0) {
|
||||||
|
queryString = "?OverridePlatformId=" + platformOverride[0].id;
|
||||||
|
}
|
||||||
|
console.log(queryString);
|
||||||
|
|
||||||
|
myDropzone.options.url = "/api/v1/Roms" + queryString;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
Reference in New Issue
Block a user