diff --git a/RemoteDownloaderPlugin/Game/GameDownload.cs b/RemoteDownloaderPlugin/Game/GameDownload.cs index 4b40412..a97deda 100644 --- a/RemoteDownloaderPlugin/Game/GameDownload.cs +++ b/RemoteDownloaderPlugin/Game/GameDownload.cs @@ -15,6 +15,7 @@ public class GameDownload : ProgressStatus public string Version { get; private set; } public GameType Type { get; private set; } public string BaseFileName { get; private set; } + public string BasePath { get; private set; } public ContentTypes InstalledEntries { get; private set; } private DateTimeOffset _downloadStart = DateTimeOffset.Now; @@ -64,10 +65,10 @@ private async Task DownloadEmu(IApp app, EmuEntry entry) } Line2 = $"{entry.Files.Count(x => x.Type == "base")} base, {entry.Files.Count(x => x.Type == "update")} update, {entry.Files.Count(x => x.Type == "dlc")} dlc"; - var basePath = Path.Join(app.GameDir, "Remote", entry.Emu); + BasePath = Path.Join(app.GameDir, "Remote", entry.Emu); string baseGamePath = null; var extraFilesPath = Path.Join(app.GameDir, "Remote", entry.Emu, entry.GameId); - Directory.CreateDirectory(basePath); + Directory.CreateDirectory(BasePath); Directory.CreateDirectory(extraFilesPath); using HttpClient client = new(); @@ -84,7 +85,7 @@ private async Task DownloadEmu(IApp app, EmuEntry entry) }; var fileEntry = entry.Files[i]; - var destPath = Path.Join(fileEntry.Type == "base" ? basePath : extraFilesPath, fileEntry.Name); + var destPath = Path.Join(fileEntry.Type == "base" ? BasePath : extraFilesPath, fileEntry.Name); InstalledEntries.Add(fileEntry.Type); if (fileEntry.Type == "base") @@ -125,9 +126,9 @@ private async Task DownloadEmu(IApp app, EmuEntry entry) private async Task DownloadPc(IApp app, PcEntry entry) { Type = GameType.Pc; - var basePath = Path.Join(app.GameDir, "Remote", "Pc", entry.GameId); - Directory.CreateDirectory(basePath); - var zipFilePath = Path.Join(basePath, "__game__.zip"); + BasePath = Path.Join(app.GameDir, "Remote", "Pc", entry.GameId); + Directory.CreateDirectory(BasePath); + var zipFilePath = Path.Join(BasePath, "__game__.zip"); using HttpClient client = new(); var fs = new FileStream(zipFilePath, FileMode.Create); @@ -143,7 +144,7 @@ private async Task DownloadPc(IApp app, PcEntry entry) { await Task.Run(() => fs.Dispose()); - Directory.Delete(basePath); + Directory.Delete(BasePath); throw; } @@ -155,15 +156,15 @@ private async Task DownloadPc(IApp app, PcEntry entry) await Task.Run(() => fs.Dispose()); Line1 = "Unzipping..."; InvokeOnUpdate(); - await Task.Run(() => ZipFile.ExtractToDirectory(zipFilePath, basePath)); + await Task.Run(() => ZipFile.ExtractToDirectory(zipFilePath, BasePath)); File.Delete(zipFilePath); if (_cts.IsCancellationRequested) { - Directory.Delete(basePath); + Directory.Delete(BasePath); } - TotalSize = await Task.Run(() => LauncherGamePlugin.Utils.DirSize(new(basePath))); + TotalSize = await Task.Run(() => LauncherGamePlugin.Utils.DirSize(new(BasePath))); Version = entry.Version; } diff --git a/RemoteDownloaderPlugin/Game/InstalledGame.cs b/RemoteDownloaderPlugin/Game/InstalledGame.cs index f17c155..08d4159 100644 --- a/RemoteDownloaderPlugin/Game/InstalledGame.cs +++ b/RemoteDownloaderPlugin/Game/InstalledGame.cs @@ -66,7 +66,7 @@ public InstalledGame(IInstalledGame game, Plugin plugin) if (_type == GameType.Pc) { - var fullPath = Path.Join(plugin.App.GameDir, "Remote", "Pc", Game.Id, "game.json"); + var fullPath = Path.Join(game.BasePath, "game.json"); _pcLaunchDetails = PcLaunchDetails.GetFromPath(fullPath); } else @@ -88,7 +88,7 @@ public void Play() throw new Exception($"No '{_emuGame!.Emu}' emulation profile exists"); } - var baseGamePath = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, _emuGame.BaseFilename); + var baseGamePath = Path.Join(Game.BasePath, _emuGame!.BaseFilename); LaunchParams args = new(emuProfile.ExecPath, emuProfile.CliArgs.Replace("{EXEC}", $"\"{baseGamePath}\""), emuProfile.WorkingDirectory, this, @@ -97,8 +97,8 @@ public void Play() } else { - var execPath = Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id, _pcLaunchDetails!.LaunchExec); - var workingDir = Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id, _pcLaunchDetails!.WorkingDir); + var execPath = Path.Join(Game.BasePath, _pcLaunchDetails!.LaunchExec); + var workingDir = Path.Join(Game.BasePath, _pcLaunchDetails!.WorkingDir); LaunchParams args = new(execPath, _pcLaunchDetails.LaunchArgs, Path.GetDirectoryName(workingDir)!, this, EstimatedGamePlatform); _plugin.App.Launch(args); @@ -114,8 +114,8 @@ public void Delete() { if (IsEmu) { - var baseGamePath = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, _emuGame.BaseFilename); - var extraDir = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, Game.Id); + var baseGamePath = Path.Join(Game.BasePath, _emuGame.BaseFilename); + var extraDir = Path.Join(Game.BasePath, Game.Id); var success = false; try @@ -136,12 +136,11 @@ public void Delete() } else { - var path = Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id); var success = false; try { - Directory.Delete(path, true); + Directory.Delete(Game.BasePath, true); success = true; } catch {} @@ -160,11 +159,7 @@ public void Delete() } public void OpenInFileManager() - { - LauncherGamePlugin.Utils.OpenFolder(IsEmu - ? Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu) - : Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id)); - } + => LauncherGamePlugin.Utils.OpenFolder(Game.BasePath); private Uri? ImageTypeToUri(ImageType type) => type switch diff --git a/RemoteDownloaderPlugin/Game/OnlineGame.cs b/RemoteDownloaderPlugin/Game/OnlineGame.cs index ec438aa..2e259ac 100644 --- a/RemoteDownloaderPlugin/Game/OnlineGame.cs +++ b/RemoteDownloaderPlugin/Game/OnlineGame.cs @@ -98,7 +98,8 @@ public async Task Download() Version = _download.Version, BaseFilename = _download.BaseFileName, Images = Entry.Img, - Types = _download.InstalledEntries + Types = _download.InstalledEntries, + BasePath = _download.BasePath }); } else @@ -109,7 +110,8 @@ public async Task Download() Name = Entry.GameName, GameSize = _download.TotalSize, Version = _download.Version, - Images = Entry.Img + Images = Entry.Img, + BasePath = _download.BasePath }); } diff --git a/RemoteDownloaderPlugin/Store.cs b/RemoteDownloaderPlugin/Store.cs index 05d7eca..e695a69 100644 --- a/RemoteDownloaderPlugin/Store.cs +++ b/RemoteDownloaderPlugin/Store.cs @@ -15,6 +15,7 @@ public interface IInstalledGame public string Version { get; } public long GameSize { get; } public Images Images { get; } + public string BasePath { get; set; } } public class ContentTypes @@ -63,6 +64,7 @@ public class InstalledEmuGame : IInstalledGame public string BaseFilename { get; set; } public Images Images { get; set; } public ContentTypes Types { get; set; } = new(); + public string BasePath { get; set; } } public class InstalledPcGame : IInstalledGame @@ -72,6 +74,7 @@ public class InstalledPcGame : IInstalledGame public long GameSize { get; set; } public string Version { get; set; } public Images Images { get; set; } + public string BasePath { get; set; } } public class EmuProfile