From 11ca84c356c91d4af744272e3d1e6c774bc0b177 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Sat, 10 May 2025 23:26:40 +0200 Subject: [PATCH 1/2] Install binaries in local appdata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The launcher currently tries to put the binaries in a subfolder of the user’s game files, which causes problems with OneDrive and isn’t really a good place to store these to begin with. This makes the code uses %LOCALAPPDATA% instead. This seems to be the best place, as the binaries can be machine-specific, which is why I didn’t pick %APPDATA%. (This is only relevant to roaming profiles, but we might as well do it right while we’re at it.) On Linux, this puts the files in ~/.local/share/Open{RCT2,Loco} --- .../InstallService.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/IntelOrca.OpenLauncher.Core/InstallService.cs b/src/IntelOrca.OpenLauncher.Core/InstallService.cs index a957dec..3a61a9d 100644 --- a/src/IntelOrca.OpenLauncher.Core/InstallService.cs +++ b/src/IntelOrca.OpenLauncher.Core/InstallService.cs @@ -17,15 +17,28 @@ public class InstallService private readonly Game _game; - - private string BinPath => Path.Combine(_game.DefaultLocation, "bin"); - private string VersionFilePath => Path.Combine(_game.DefaultLocation, "bin", ".version"); - public InstallService(Game game) { _game = game; } + public string BinPath + { + get + { + var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + return Path.Combine(localAppData, _game.Name, "bin"); + } + } + + public string VersionFilePath + { + get + { + return Path.Combine(BinPath, ".version"); + } + } + public string ExecutablePath { get From 977e0073541bb186b7e8214228e772d7a2f3b1ea Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Sun, 11 May 2025 20:35:31 +0200 Subject: [PATCH 2/2] Move folder determination to Game.cs --- src/IntelOrca.OpenLauncher.Core/Game.cs | 26 +++++-------------- .../InstallService.cs | 26 +++++-------------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/src/IntelOrca.OpenLauncher.Core/Game.cs b/src/IntelOrca.OpenLauncher.Core/Game.cs index 5eb44f3..6296062 100644 --- a/src/IntelOrca.OpenLauncher.Core/Game.cs +++ b/src/IntelOrca.OpenLauncher.Core/Game.cs @@ -6,39 +6,25 @@ namespace IntelOrca.OpenLauncher.Core { public class Game { - public static Game OpenRCT2 => new Game("OpenRCT2", "openrct2", true, new RepositoryName("OpenRCT2", "OpenRCT2"), new RepositoryName("OpenRCT2", "OpenRCT2-binaries")); - public static Game OpenLoco => new Game("OpenLoco", "openloco", false, new RepositoryName("OpenLoco", "OpenLoco")); + public static Game OpenRCT2 => new Game("OpenRCT2", "openrct2", new RepositoryName("OpenRCT2", "OpenRCT2"), new RepositoryName("OpenRCT2", "OpenRCT2-binaries")); + public static Game OpenLoco => new Game("OpenLoco", "openloco", new RepositoryName("OpenLoco", "OpenLoco")); public string Name { get; } public string BinaryName { get; } - public string DefaultLocation { get; } + public string BinPath { get; } public RepositoryName ReleaseRepository { get; set; } public RepositoryName? DevelopRepository { get; set; } - private Game(string name, string binaryName, bool usesDocuments, RepositoryName releaseRepo, RepositoryName? developRepo = null) + private Game(string name, string binaryName, RepositoryName releaseRepo, RepositoryName? developRepo = null) { Name = name; BinaryName = binaryName; - var root = GetLocation(usesDocuments); - DefaultLocation = Path.Combine(root, name); + var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + BinPath = Path.Combine(localAppData, name, "bin"); ReleaseRepository = releaseRepo; DevelopRepository = developRepo; } - - private string GetLocation(bool usesDocuments) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return usesDocuments ? - Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) : - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - } - else - { - return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - } - } } public struct RepositoryName diff --git a/src/IntelOrca.OpenLauncher.Core/InstallService.cs b/src/IntelOrca.OpenLauncher.Core/InstallService.cs index 3a61a9d..3cf0235 100644 --- a/src/IntelOrca.OpenLauncher.Core/InstallService.cs +++ b/src/IntelOrca.OpenLauncher.Core/InstallService.cs @@ -17,26 +17,12 @@ public class InstallService private readonly Game _game; - public InstallService(Game game) - { - _game = game; - } + private string VersionFilePath => Path.Combine(_game.BinPath, ".version"); - public string BinPath - { - get - { - var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - return Path.Combine(localAppData, _game.Name, "bin"); - } - } - public string VersionFilePath + public InstallService(Game game) { - get - { - return Path.Combine(BinPath, ".version"); - } + _game = game; } public string ExecutablePath @@ -45,7 +31,7 @@ public string ExecutablePath { var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); var binaryName = isWindows ? $"{_game.BinaryName}.exe" : _game.BinaryName; - return Path.Combine(BinPath, binaryName); + return Path.Combine(_game.BinPath, binaryName); } } @@ -127,8 +113,8 @@ public async Task DownloadVersion( ct.ThrowIfCancellationRequested(); // Backup old bin directory - var binDirectory = BinPath; - var backupDirectory = BinPath + ".backup"; + var binDirectory = _game.BinPath; + var backupDirectory = _game.BinPath + ".backup"; if (shell.DirectoryExists(binDirectory)) { shell.MoveDirectory(binDirectory, backupDirectory);