Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a platform override option during web based import #94

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions gaseous-server/Classes/ImportGames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ImportGames(string ImportPath)

// import files first
foreach (string importContent in importContents_Files) {
ImportGame.ImportGameFile(importContent);
ImportGame.ImportGameFile(importContent, null, false);
}
}
else
Expand All @@ -38,7 +38,7 @@ public ImportGames(string ImportPath)

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);
string sql = "";
Expand All @@ -50,7 +50,6 @@ public static void ImportGameFile(string GameFileImportPath, bool IsDirectory =
}
else
{
//Logging.Log(Logging.LogType.Information, "Import Game", "Processing item " + GameFileImportPath);
if (IsDirectory == false)
{
FileInfo fi = new FileInfo(GameFileImportPath);
Expand Down Expand Up @@ -80,10 +79,20 @@ public static void ImportGameFile(string GameFileImportPath, bool IsDirectory =
Models.Signatures_Games discoveredSignature = GetFileSignature(hash, fi, GameFileImportPath);

// get discovered platform
IGDB.Models.Platform determinedPlatform = Metadata.Platforms.GetPlatform(discoveredSignature.Flags.IGDBPlatformId);
if (determinedPlatform == null)
IGDB.Models.Platform? determinedPlatform = null;
if (OverridePlatform == null)
{
determinedPlatform = new IGDB.Models.Platform();
determinedPlatform = Metadata.Platforms.GetPlatform(discoveredSignature.Flags.IGDBPlatformId);
if (determinedPlatform == null)
{
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);
Expand Down
13 changes: 9 additions & 4 deletions gaseous-server/Controllers/RomsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class RomsController : ControllerBase
[ProducesResponseType(typeof(List<IFormFile>), StatusCodes.Status200OK)]
[RequestSizeLimit(long.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();

Expand Down Expand Up @@ -61,12 +61,17 @@ public async Task<IActionResult> UploadRom(List<IFormFile> files)
}
}

// Process uploaded files
// Don't rely on or trust the FileName property without validation.
// get override platform if specified
IGDB.Models.Platform? OverridePlatform = null;
if (OverridePlatformId != null)
{
OverridePlatform = Platforms.GetPlatform((long)OverridePlatformId);
}

// Process uploaded files
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))
Expand Down
58 changes: 58 additions & 0 deletions gaseous-server/wwwroot/pages/dialogs/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@
<div>
<div id="upload_target" class="dropzone"></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">
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", {
url: "/api/v1/Roms",
Expand Down Expand Up @@ -69,4 +80,51 @@
subModalContent.innerHTML = "";
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>