-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGogLauncher.cs
93 lines (70 loc) · 2.7 KB
/
GogLauncher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Gamelib.Core.Util;
using GameLib.Core;
using Microsoft.Win32;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
namespace GameLib.Plugin.Gog;
[Guid("02BBDAB7-68D7-4CE1-9044-934DFEC6CF17")]
[Export(typeof(ILauncher))]
public class GogLauncher : ILauncher
{
[ImportingConstructor]
public GogLauncher(LauncherOptions? launcherOptions)
{
LauncherOptions = launcherOptions ?? new LauncherOptions();
}
#region Interface implementations
public LauncherOptions LauncherOptions { get; }
public Guid Id => GetType().GUID;
public string Name => "GOG Galaxy";
public Image Logo => Properties.Resources.Logo128px;
public bool IsInstalled { get; private set; }
public bool IsRunning => ProcessUtil.IsProcessRunning(Executable);
public string InstallDir { get; private set; } = string.Empty;
public string Executable { get; private set; } = string.Empty;
public Icon? ExecutableIcon => PathUtil.GetFileIcon(Executable);
public IEnumerable<IGame> Games { get; private set; } = Enumerable.Empty<IGame>();
public void Refresh(CancellationToken cancellationToken = default)
{
Executable = string.Empty;
InstallDir = string.Empty;
IsInstalled = false;
Games = Enumerable.Empty<IGame>();
Executable = GetExecutable() ?? string.Empty;
if (!string.IsNullOrEmpty(Executable))
{
InstallDir = Path.GetDirectoryName(Executable) ?? string.Empty;
IsInstalled = File.Exists(Executable);
Games = GogGameFactory.GetGames(this, cancellationToken);
}
}
public bool Start() => IsRunning || ProcessUtil.StartProcess(Executable);
public void Stop()
{
if (IsRunning)
{
Process.Start(Executable, "/command=shutdown");
}
}
#endregion
#region Private methods
private static string? GetExecutable()
{
string? executablePath = null;
executablePath ??= RegistryUtil.GetShellCommand("goggalaxy");
executablePath ??= RegistryUtil.GetValue(RegistryHive.LocalMachine, @"SOFTWARE\GOG.com\GalaxyClient\paths", "client");
executablePath = PathUtil.Sanitize(executablePath);
if (!string.IsNullOrEmpty(executablePath) && !PathUtil.IsExecutable(executablePath))
{
executablePath = Path.Combine(executablePath, RegistryUtil.GetValue(RegistryHive.LocalMachine, @"SOFTWARE\GOG.com\GalaxyClient", "clientExecutable") ?? string.Empty);
}
if (!PathUtil.IsExecutable(executablePath))
{
executablePath = null;
}
return executablePath;
}
#endregion
}