-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLauncher.cs
77 lines (65 loc) · 2.26 KB
/
Launcher.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
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace LeaguePatchCollection;
internal sealed class RiotClient
{
public RiotClient()
{
}
public Process? Launch(string configServerUrl, IEnumerable<string>? args = null)
{
var path = GetPath();
if (path is null)
return null;
IEnumerable<string> allArgs = [$"--client-config-url={configServerUrl}", "--launch-product=league_of_legends", "--launch-patchline=live", .. args ?? []];
return Process.Start(path, allArgs);
}
private string? GetPath()
{
string installPath;
if (OperatingSystem.IsMacOS())
{
installPath = "/Users/Shared/Riot Games/RiotClientInstalls.json";
}
else
{
installPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"Riot Games/RiotClientInstalls.json");
}
if (File.Exists(installPath))
{
try
{
var data = JsonSerializer.Deserialize<JsonNode>(File.ReadAllText(installPath));
var rcPaths = new List<string?>
{
data?["rc_default"]?.ToString(),
data?["rc_live"]?.ToString(),
data?["rc_beta"]?.ToString()
};
var validPath = rcPaths.FirstOrDefault(File.Exists);
if (validPath != null)
return validPath;
}
catch
{
}
}
if (OperatingSystem.IsMacOS())
{
return "/Users/Shared/Riot Games/Riot Client.app/Contents/MacOS/RiotClientServices";
}
else
{
foreach (var drive in DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveType == DriveType.Fixed))
{
var potentialPath = Path.Combine(drive.RootDirectory.FullName, "Riot Games", "Riot Client", "RiotClientServices.exe");
if (File.Exists(potentialPath))
return potentialPath;
}
}
return null;
}
}