Skip to content
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
6 changes: 4 additions & 2 deletions Downloads/DownloadQueueController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ private async Task DownloadAndInstall(DownloadQueueItem item, DownloadRequest re
}

// Extract if needed (we treat extract as 0..100 in its own bar)
if (req.HasMultipleFiles || (req.AutoExtract && IsFileCompressed(req.GamePath)))
// Don't extract archives when install flat is enabled
if (req.HasMultipleFiles || (req.AutoExtract && IsFileCompressed(req.GamePath) && !req.InstallFlat))
{
item.SetStatus(DownloadStatus.Extracting, "Extracting...");
Logger.Info($"Extracting {req.GamePath}...");
Expand Down Expand Up @@ -323,7 +324,8 @@ private void TryCleanupPartialInstall(DownloadRequest req)
SafeDeleteFileWithRetry(req.GamePath);

// delete folder (recursively) if it exists
SafeDeleteDirectoryWithRetry(req.InstallDir);
if(!req.InstallFlat)
SafeDeleteDirectoryWithRetry(req.InstallDir);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion Downloads/DownloadRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DownloadRequest
public bool AutoExtract { get; set; } = true;
public bool Use7z { get; set; } = false;
public string PathTo7Z { get; set; } = "";

public bool InstallFlat { get; set; } = false;

/// Optional function used after extraction to build rom list for Playnite
public Func<List<GameRom>> BuildRoms { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Games/RomMGameInfo.Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public EmulatorMapping Mapping

public InstallController GetInstallController(Game game, RomM romm, GameInstallInfo GameData) => new RomMInstallController(game, romm, GameData);

public UninstallController GetUninstallController(Game game, RomM romm) => new RomMUninstallController(game, romm);
public UninstallController GetUninstallController(Game game, RomM romm, EmulatorMapping mapping) => new RomMUninstallController(game, romm, mapping);

protected IEnumerable<string> GetDescriptionLines()
{
Expand Down
5 changes: 3 additions & 2 deletions Games/RomMImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ private Game ImportGame(RomMRom ROM, Guid StatusID)
return null;
}

var gameInstallDir = RomMInstallPaths.InstallDir(rootInstallDir, folderName, fileName);
var pathToGame = RomMInstallPaths.GamePath(rootInstallDir, folderName, fileName);
var gameInstallDir = _mapping.InstallFlat ? rootInstallDir : RomMInstallPaths.InstallDir(rootInstallDir, folderName, fileName);
var pathToGame = _mapping.InstallFlat ? $"{rootInstallDir}\\{fileName}" : RomMInstallPaths.GamePath(rootInstallDir, folderName, fileName);

var status = _plugin.Playnite.Database.CompletionStatuses.Get(StatusID);
var completionStatusProperty = status != null ? new MetadataNameProperty(status.Name) : null;
Expand Down Expand Up @@ -246,6 +246,7 @@ private Game ImportGame(RomMRom ROM, Guid StatusID)
}
};


// Import new game
Game game = _plugin.Playnite.Database.ImportGame(metadata, _plugin);

Expand Down
9 changes: 7 additions & 2 deletions Games/RomMInstallController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Playnite.SDK;
using Newtonsoft.Json;
using Playnite.SDK;
using Playnite.SDK.Models;
using Playnite.SDK.Plugins;
using RomM.Downloads;
using RomM.Models.RomM.Rom;
using RomM.Settings;
using SharpCompress.Archives;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;

namespace RomM.Games
{
Expand Down Expand Up @@ -47,6 +48,9 @@ public override void Install(InstallActionArgs args)
// IsInstalled detection lines up.
var installDir = RomMInstallPaths.InstallDir(dstPath, _gameData.FolderName, _gameData.FileName);

if (_gameData.Mapping.InstallFlat)
installDir = dstPath;
Comment thread
matthew-pye marked this conversation as resolved.
Comment thread
matthew-pye marked this conversation as resolved.

// If RomM indicates multiple files, we download as an archive name (zip) into the install folder.
// Otherwise we download the single ROM file.
var downloadFilePath = _gameData.HasMultipleFiles
Expand All @@ -66,6 +70,7 @@ public override void Install(InstallActionArgs args)

HasMultipleFiles = _gameData.HasMultipleFiles,
AutoExtract = _gameData.Mapping != null && _gameData.Mapping.AutoExtract,
InstallFlat = _gameData.Mapping.InstallFlat,

// Called by queue AFTER download/extract is done
BuildRoms = () =>
Expand Down
25 changes: 20 additions & 5 deletions Games/RomMUninstallController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Playnite.SDK.Models;
using Playnite.SDK.Plugins;
using RomM.Settings;
using System.IO;
using System.Windows;

Expand All @@ -8,24 +9,38 @@ namespace RomM.Games
internal class RomMUninstallController : UninstallController
{
private readonly IRomM _romM;
private EmulatorMapping _mapping;

internal RomMUninstallController(Game game, IRomM romM) : base(game)
internal RomMUninstallController(Game game, IRomM romM, EmulatorMapping mapping) : base(game)
{
Name = "Uninstall";
_romM = romM;
_mapping = mapping;
}

public override void Uninstall(UninstallActionArgs args)
{
if (new DirectoryInfo(Game.InstallDirectory).Exists)
if(_mapping.InstallFlat)
{
Directory.Delete(Game.InstallDirectory, true);
foreach (var RomFile in Game.Roms)
{
if(File.Exists(RomFile.Path))
File.Delete(RomFile.Path);
}
}
else
{
_romM.Playnite.Dialogs.ShowMessage($"\"{Game.Name}\" folder could not be found. Marking as uninstalled.", "Game not found", MessageBoxButton.OK);
if (new DirectoryInfo(Game.InstallDirectory).Exists)
{
Directory.Delete(Game.InstallDirectory, true);
}
else
{
_romM.Playnite.Dialogs.ShowMessage($"\"{Game.Name}\" folder could not be found. Marking as uninstalled.", "Game not found", MessageBoxButton.OK);
}
}
Game.Roms.Clear();

Game.Roms.Clear();
InvokeOnUninstalled(new GameUninstalledEventArgs());
}
}
Expand Down
23 changes: 22 additions & 1 deletion RomM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,28 @@ public override IEnumerable<UninstallController> GetUninstallActions(GetUninstal
{
if (args.Game.PluginId == Id)
{
yield return new RomMUninstallController(args.Game, this);
EmulatorMapping mapping = null;

try
{
var splitID = args.Game.GameId.Split(':');
string sidecarPath = $"{ROMDataPath}{splitID[1]}.json";
if (File.Exists(sidecarPath))
{
var existingJson = File.ReadAllText(sidecarPath);
var localROM = JsonConvert.DeserializeObject<RomMRomLocal>(existingJson);
mapping = Settings.Mappings.FirstOrDefault(x => x.MappingId == localROM.MappingID);
}
}
catch (Exception)
{
Logger.Error($"{args.Game.Name} GameID is malformed or json file is corrupted!");
}

if (mapping == null)
yield return null;

yield return new RomMUninstallController(args.Game, this, mapping);
}
}
public override void OnGameInstalled(OnGameInstalledEventArgs args)
Expand Down
18 changes: 15 additions & 3 deletions Settings/EmulatorMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class EmulatorMapping : ObservableObject
public int _romMPlatformId = -1;
[JsonIgnore]
private string _destinationPath = "";
[JsonIgnore]
private bool _installFlat = false;

public EmulatorMapping(List<RomMPlatform> romMPlatforms)
{
Expand Down Expand Up @@ -232,10 +234,20 @@ public string DestinationPath
{
_destinationPath = value;
OnPropertyChanged();
}
}
}
}

public bool InstallFlat
{
get => _installFlat;
set
{
_installFlat = value;
OnPropertyChanged();
}
}

[JsonIgnore]
[JsonIgnore]
public static IEnumerable<Emulator> AvailableEmulators => SettingsViewModel.Instance.PlayniteAPI.Database.Emulators?.OrderBy(x => x.Name) ?? Enumerable.Empty<Emulator>();
[JsonIgnore]
public IEnumerable<EmulatorProfile> AvailableProfiles
Expand Down
1 change: 1 addition & 0 deletions Settings/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
<StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="0,2,0,8">
<CheckBox Content="Enabled" Margin="0,0,16,0" IsChecked="{Binding Enabled, Mode=TwoWay}" />
<CheckBox Content="Auto-extract" Margin="0,0,16,0" IsChecked="{Binding AutoExtract, Mode=TwoWay}" ToolTip="Extract ROMs stored on the server as Rar, Zip, Tar, 7z, GZip, or BZip2." />
<CheckBox Content="Install Flat" Margin="0,0,16,0" IsChecked="{Binding InstallFlat, Mode=TwoWay}" ToolTip="Will download ROMs into the Path/ instead of Path/Gamename/" />
<CheckBox Content="Prefer .m3u" IsChecked="{Binding UseM3U, Mode=TwoWay}" ToolTip="Use the .m3u file for multi-file ROMs when the emulator supports it." />
</StackPanel>

Expand Down
Loading