diff --git a/Games/RomMInstallController.cs b/Games/RomMInstallController.cs index 63aeaf6..51bde5c 100644 --- a/Games/RomMInstallController.cs +++ b/Games/RomMInstallController.cs @@ -48,11 +48,13 @@ public override void Install(InstallActionArgs args) HttpResponseMessage response = await RomM.GetAsync(info.DownloadUrl, HttpCompletionOption.ResponseHeadersRead); response.EnsureSuccessStatusCode(); - string installDir = dstPath; - string gamePath = Path.Combine(dstPath, info.FileName); + List roms = new List(); + string installDir = Path.Combine(dstPath, Path.GetFileNameWithoutExtension(info.FileName)); + string gamePath = Path.Combine(installDir, info.FileName); if (info.IsMulti) { - gamePath = Path.Combine(dstPath, info.FileName + ".zip"); + // File name for multi-file archives is the folder name, so we append .zip + gamePath = Path.Combine(installDir, info.FileName + ".zip"); } if (_romM.Playnite.ApplicationInfo.IsPortable) @@ -62,6 +64,7 @@ public override void Install(InstallActionArgs args) } Logger.Debug($"Downloading {Game.Name} to {gamePath}."); + Directory.CreateDirectory(installDir); // Stream the file directly to disk using (var fileStream = new FileStream(gamePath, FileMode.Create, FileAccess.Write, FileShare.None)) @@ -70,29 +73,34 @@ public override void Install(InstallActionArgs args) await httpStream.CopyToAsync(fileStream); } - Logger.Debug($"Download of {Game.Name} complete!"); + Logger.Debug($"Download of {Game.Name} complete."); // ALways extract top-level file of multi-file archives if (info.IsMulti || (info.Mapping.AutoExtract && IsFileCompressed(gamePath))) { - // Create the install directory if it doesn't exist - installDir = Path.Combine(dstPath, Path.GetFileNameWithoutExtension(info.FileName)); - Directory.CreateDirectory(installDir); - // Extract the archive to the install directory ExtractArchive(gamePath, installDir); + // Delete the compressed file + File.Delete(gamePath); + // Extract nested archives if auto-extract is enabled if (info.IsMulti && info.Mapping.AutoExtract) { ExtractNestedArchives(installDir); } - // Delete the compressed file - File.Delete(gamePath); + // Add just the ROM files to the list + string[] actualRomFiles = Directory.GetFiles(installDir, "*", SearchOption.AllDirectories) + .Where(file => !file.EndsWith(".m3u", StringComparison.OrdinalIgnoreCase)) + .ToArray(); - // Update the game path to the extracted game - gamePath = Path.Combine(installDir, Directory.GetFiles(installDir, "*", SearchOption.AllDirectories).Where(file => !file.EndsWith(".m3u", StringComparison.OrdinalIgnoreCase)).ToArray()[0]); + foreach (var romFile in actualRomFiles) { + roms.Add(new GameRom(Game.Name, romFile)); + } + } else { + // Add the single ROM file to the list + roms.Add(new GameRom(Game.Name, gamePath)); } // Update the game's installation status @@ -103,7 +111,7 @@ public override void Install(InstallActionArgs args) InvokeOnInstalled(new GameInstalledEventArgs(new GameInstallationData() { InstallDirectory = installDir, - Roms = new List() { new GameRom(Game.Name, gamePath) }, + Roms = roms, })); } catch (Exception ex)