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
26 changes: 6 additions & 20 deletions src/IntelOrca.OpenLauncher.Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/IntelOrca.OpenLauncher.Core/InstallService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment thread
Gymnasiast marked this conversation as resolved.

public InstallService(Game game)
{
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down