From 0a0facd460077a1d251f6e66df07109dc5b88a93 Mon Sep 17 00:00:00 2001 From: sewer56lol Date: Fri, 26 Apr 2024 18:31:58 +0100 Subject: [PATCH] Fixed: Updating Install Location of MS Store/Gamepass Games --- changelog-template.hbs | 19 +++++++++++++ .../Application/AddApplicationCommand.cs | 28 +++++++++++-------- .../ViewModel/Application/EditAppViewModel.cs | 8 +++++- .../Reloaded.Mod.Launcher.csproj | 2 +- .../Reloaded.Mod.Loader.csproj | 2 +- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/changelog-template.hbs b/changelog-template.hbs index 66b48f8e..5ce070a5 100644 --- a/changelog-template.hbs +++ b/changelog-template.hbs @@ -1,3 +1,22 @@ +## Changelog (1.27.4) + +[Read and Discuss in a Browser](https://github.com/Reloaded-Project/Reloaded-II/discussions/369). +[Previous Changelog](https://github.com/Reloaded-Project/Reloaded-II/releases/tag/1.27.3). + +Originally reported as: +- https://github.com/Reloaded-Project/Reloaded-II/issues/368 + +When changing the install location of a GamePass (Microsoft Store) game within Reloaded-II, the operation will no longer fail if the file is protected/unreadable due to OS' built in Copy Protection/Sandboxing. + +This is useful if: + +- You have reinstalled the game. +- You have moved the game to another location. + +etc. + +Instead, the same logic/steps as will be applied as if the game was added for the first time, including ASI Loader re-deployment (if necessary). + ## Changelog (1.27.3) [Read and Discuss in a Browser](https://github.com/Reloaded-Project/Reloaded-II/discussions/365). diff --git a/source/Reloaded.Mod.Launcher.Lib/Commands/Application/AddApplicationCommand.cs b/source/Reloaded.Mod.Launcher.Lib/Commands/Application/AddApplicationCommand.cs index 6c690d03..ac22f52c 100644 --- a/source/Reloaded.Mod.Launcher.Lib/Commands/Application/AddApplicationCommand.cs +++ b/source/Reloaded.Mod.Launcher.Lib/Commands/Application/AddApplicationCommand.cs @@ -90,6 +90,22 @@ static string GetProductName(string exePath) } // Try to auto deploy ASI Loader. + HandleAddedMsStoreBinary(isMsStore, applicationConfigFile, config); + + // Write file to disk. + Directory.CreateDirectory(applicationDirectory); + IConfig.ToPath(config, applicationConfigFile); + + // Listen to event for when the new application is discovered. + _newConfig = config; + _configService.Items.CollectionChanged += ApplicationsChanged; + + // Set return value + param.ResultCreatedApplication = true; + } + + internal static void HandleAddedMsStoreBinary(bool isMsStore, string applicationConfigFile, ApplicationConfig config) + { if (isMsStore) { var deployer = new AsiLoaderDeployer(new PathTuple(applicationConfigFile, config)); @@ -105,18 +121,8 @@ static string GetProductName(string exePath) Actions.DisplayMessagebox.Invoke(Resources.AsiLoaderDialogTitle.Get(), Resources.AsiLoaderGamePassAutoInstallFail.Get()); } } - - // Write file to disk. - config.IsMsStore = isMsStore; - Directory.CreateDirectory(applicationDirectory); - IConfig.ToPath(config, applicationConfigFile); - // Listen to event for when the new application is discovered. - _newConfig = config; - _configService.Items.CollectionChanged += ApplicationsChanged; - - // Set return value - param.ResultCreatedApplication = true; + config.IsMsStore = isMsStore; } private void ApplicationsChanged(object? sender, NotifyCollectionChangedEventArgs e) diff --git a/source/Reloaded.Mod.Launcher.Lib/Models/ViewModel/Application/EditAppViewModel.cs b/source/Reloaded.Mod.Launcher.Lib/Models/ViewModel/Application/EditAppViewModel.cs index 65f57eb1..39a601cf 100644 --- a/source/Reloaded.Mod.Launcher.Lib/Models/ViewModel/Application/EditAppViewModel.cs +++ b/source/Reloaded.Mod.Launcher.Lib/Models/ViewModel/Application/EditAppViewModel.cs @@ -123,11 +123,14 @@ public void SetNewExecutablePath() if (string.IsNullOrEmpty(result)) return; + var isMsStore = TryUnprotectGamePassGame.TryIt(result); result = SymlinkResolver.GetFinalPathName(result); if (!Path.GetFileName(Application.Config.AppLocation).Equals(Path.GetFileName(result), StringComparison.OrdinalIgnoreCase)) Actions.DisplayMessagebox(Resources.AddAppWarningTitle.Get(), Resources.AddAppWarning.Get()); Application.Config.AppLocation = result; + AddApplicationCommand.HandleAddedMsStoreBinary(isMsStore, Application.Path, Application.Config); + Application.Save(); } /// @@ -163,7 +166,10 @@ private void OnAppLocationChanged(object? sender, PropertyChangedEventArgs e) private string SelectEXEFile() { - var dialog = new VistaOpenFileDialog(); + // This is a Save dialog because Open dialog checks read privileges, + // and that will not work with read protected MS Store/Gamepass executables. + var dialog = new VistaSaveFileDialog(); + dialog.OverwritePrompt = false; dialog.Title = Resources.AddAppExecutableTitle.Get(); dialog.Filter = $"{Resources.AddAppExecutableFilter.Get()} (*.exe)|*.exe"; dialog.FileName = ApplicationConfig.GetAbsoluteAppLocation(Application); diff --git a/source/Reloaded.Mod.Launcher/Reloaded.Mod.Launcher.csproj b/source/Reloaded.Mod.Launcher/Reloaded.Mod.Launcher.csproj index 4f287c59..1ca0f08e 100644 --- a/source/Reloaded.Mod.Launcher/Reloaded.Mod.Launcher.csproj +++ b/source/Reloaded.Mod.Launcher/Reloaded.Mod.Launcher.csproj @@ -7,7 +7,7 @@ true Reloaded-II Reloaded.Mod.Launcher - 1.27.3 + 1.27.4 Sewer56 ~ $([System.DateTime]::UtcNow.ToString("s")) | $(Version) false appicon.ico diff --git a/source/Reloaded.Mod.Loader/Reloaded.Mod.Loader.csproj b/source/Reloaded.Mod.Loader/Reloaded.Mod.Loader.csproj index ccba5239..f1e07520 100644 --- a/source/Reloaded.Mod.Loader/Reloaded.Mod.Loader.csproj +++ b/source/Reloaded.Mod.Loader/Reloaded.Mod.Loader.csproj @@ -11,7 +11,7 @@ true false $(NoWarn);NU1605;NU1701 - 1.27.3 + 1.27.4 x86;x64 false portable