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 a957dec..3cf0235 100644 --- a/src/IntelOrca.OpenLauncher.Core/InstallService.cs +++ b/src/IntelOrca.OpenLauncher.Core/InstallService.cs @@ -17,9 +17,8 @@ public class InstallService private readonly Game _game; + private string VersionFilePath => Path.Combine(_game.BinPath, ".version"); - private string BinPath => Path.Combine(_game.DefaultLocation, "bin"); - private string VersionFilePath => Path.Combine(_game.DefaultLocation, "bin", ".version"); public InstallService(Game game) { @@ -32,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); } } @@ -114,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);