Ensure ROMs are decompressed before loading them into a media group (#321)
All compressed archives (zip, rar, and 7z) are decompressed when a media group is created. Only files with an extension defined in the platform mapping are added to the M3U file. Closes #307
This commit is contained in:
@@ -5,6 +5,9 @@ using Microsoft.VisualBasic;
|
|||||||
using IGDB.Models;
|
using IGDB.Models;
|
||||||
using gaseous_server.Classes.Metadata;
|
using gaseous_server.Classes.Metadata;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using SharpCompress.Archives;
|
||||||
|
using SharpCompress.Common;
|
||||||
|
using gaseous_server.Models;
|
||||||
|
|
||||||
namespace gaseous_server.Classes
|
namespace gaseous_server.Classes
|
||||||
{
|
{
|
||||||
@@ -259,6 +262,7 @@ namespace gaseous_server.Classes
|
|||||||
{
|
{
|
||||||
Game GameObject = Games.GetGame(mediaGroupItem.GameId, false, false, false);
|
Game GameObject = Games.GetGame(mediaGroupItem.GameId, false, false, false);
|
||||||
Platform PlatformObject = Platforms.GetPlatform(mediaGroupItem.PlatformId, false);
|
Platform PlatformObject = Platforms.GetPlatform(mediaGroupItem.PlatformId, false);
|
||||||
|
PlatformMapping.PlatformMapItem platformMapItem = PlatformMapping.GetPlatformMap(mediaGroupItem.PlatformId);
|
||||||
|
|
||||||
Logging.Log(Logging.LogType.Information, "Media Group", "Beginning build of media group: " + GameObject.Name + " for platform " + PlatformObject.Name);
|
Logging.Log(Logging.LogType.Information, "Media Group", "Beginning build of media group: " + GameObject.Name + " for platform " + PlatformObject.Name);
|
||||||
|
|
||||||
@@ -293,10 +297,124 @@ namespace gaseous_server.Classes
|
|||||||
foreach (long RomId in mediaGroupItem.RomIds)
|
foreach (long RomId in mediaGroupItem.RomIds)
|
||||||
{
|
{
|
||||||
Roms.GameRomItem rom = Roms.GetRom(RomId);
|
Roms.GameRomItem rom = Roms.GetRom(RomId);
|
||||||
|
bool fileNameFound = false;
|
||||||
if (File.Exists(rom.Path))
|
if (File.Exists(rom.Path))
|
||||||
{
|
{
|
||||||
Logging.Log(Logging.LogType.Information, "Media Group", "Copying ROM: " + rom.Name);
|
string romExt = Path.GetExtension(rom.Path);
|
||||||
File.Copy(rom.Path, Path.Combine(ZipFileTempPath, Path.GetFileName(rom.Path)));
|
if (new string[]{ ".zip", ".rar", ".7z" }.Contains(romExt))
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Information, "Media Group", "Decompressing ROM: " + rom.Name);
|
||||||
|
|
||||||
|
// is compressed
|
||||||
|
switch (romExt)
|
||||||
|
{
|
||||||
|
case ".zip":
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var archive = SharpCompress.Archives.Zip.ZipArchive.Open(rom.Path))
|
||||||
|
{
|
||||||
|
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Information, "Media Group", "Extracting file: " + entry.Key);
|
||||||
|
if (fileNameFound == false)
|
||||||
|
{
|
||||||
|
//check if extension is in valid extensions
|
||||||
|
if (platformMapItem.Extensions.SupportedFileExtensions.Contains(Path.GetExtension(entry.Key), StringComparer.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
// update rom file name
|
||||||
|
rom.Name = entry.Key;
|
||||||
|
fileNameFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry.WriteToDirectory(ZipFileTempPath, new ExtractionOptions()
|
||||||
|
{
|
||||||
|
ExtractFullPath = true,
|
||||||
|
Overwrite = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception zipEx)
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Warning, "Media Group", "Unzip error", zipEx);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ".rar":
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var archive = SharpCompress.Archives.Rar.RarArchive.Open(rom.Path))
|
||||||
|
{
|
||||||
|
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Information, "Media Group", "Extracting file: " + entry.Key);
|
||||||
|
if (fileNameFound == false)
|
||||||
|
{
|
||||||
|
//check if extension is in valid extensions
|
||||||
|
if (platformMapItem.Extensions.SupportedFileExtensions.Contains(Path.GetExtension(entry.Key), StringComparer.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
// update rom file name
|
||||||
|
rom.Name = entry.Key;
|
||||||
|
fileNameFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry.WriteToDirectory(ZipFileTempPath, new ExtractionOptions()
|
||||||
|
{
|
||||||
|
ExtractFullPath = true,
|
||||||
|
Overwrite = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception zipEx)
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Warning, "Media Group", "Unrar error", zipEx);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ".7z":
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var archive = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(rom.Path))
|
||||||
|
{
|
||||||
|
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Information, "Media Group", "Extracting file: " + entry.Key);
|
||||||
|
if (fileNameFound == false)
|
||||||
|
{
|
||||||
|
//check if extension is in valid extensions
|
||||||
|
if (platformMapItem.Extensions.SupportedFileExtensions.Contains(Path.GetExtension(entry.Key), StringComparer.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
// update rom file name
|
||||||
|
rom.Name = entry.Key;
|
||||||
|
fileNameFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry.WriteToDirectory(ZipFileTempPath, new ExtractionOptions()
|
||||||
|
{
|
||||||
|
ExtractFullPath = true,
|
||||||
|
Overwrite = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception zipEx)
|
||||||
|
{
|
||||||
|
Logging.Log(Logging.LogType.Warning, "Media Group", "7z error", zipEx);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// is uncompressed
|
||||||
|
Logging.Log(Logging.LogType.Information, "Media Group", "Copying ROM: " + rom.Name);
|
||||||
|
File.Copy(rom.Path, Path.Combine(ZipFileTempPath, Path.GetFileName(rom.Path)));
|
||||||
|
}
|
||||||
|
|
||||||
romItems.Add(rom);
|
romItems.Add(rom);
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
var emuBios = '';
|
var emuBios = '';
|
||||||
var emuBackground = '';
|
var emuBackground = '';
|
||||||
|
|
||||||
|
console.log("Loading rom url: " + decodeURIComponent(getQueryString('rompath', 'string')));
|
||||||
|
|
||||||
ajaxCall('/api/v1.1/Games/' + gameId, 'GET', function (result) {
|
ajaxCall('/api/v1.1/Games/' + gameId, 'GET', function (result) {
|
||||||
gameData = result;
|
gameData = result;
|
||||||
|
|
||||||
|
@@ -545,7 +545,7 @@
|
|||||||
var saveStatesButton = '';
|
var saveStatesButton = '';
|
||||||
if (mediaGroup.emulator) {
|
if (mediaGroup.emulator) {
|
||||||
if (mediaGroup.emulator.type.length > 0) {
|
if (mediaGroup.emulator.type.length > 0) {
|
||||||
var romPath = encodeURIComponent('/api/v1.1/Games/' + gameId + '/romgroup/' + mediaGroup.id + '/' + gameData.name + '(' + mediaGroup.id + ')' + '.zip');
|
var romPath = encodeURIComponent('/api/v1.1/Games/' + gameId + '/romgroup/' + mediaGroup.id + '/' + gameData.name + '.zip');
|
||||||
|
|
||||||
if (mediaGroup.hasSaveStates == true) {
|
if (mediaGroup.hasSaveStates == true) {
|
||||||
var modalVariables = {
|
var modalVariables = {
|
||||||
|
Reference in New Issue
Block a user