-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLauncher.cs
69 lines (61 loc) · 2.59 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
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Text.Json.Nodes;
namespace LionsGate;
public sealed class RiotClient
{
public static Process? Launch(IEnumerable<string>? args = null)
{
var path = GetPath();
if (path is null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [ERROR] Unable to find Riot Client installation path, cannot start.");
Console.ResetColor();
return null;
}
IEnumerable<string> allArgs = [$"--client-config-url=http://127.0.0.1:{LeagueProxy.ConfigPort}", "--launch-product=lion", "--launch-patchline=live", .. args ?? []];
return Process.Start(path, allArgs);
}
private static string? GetPath()
{
string 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 (Exception ex)
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($" [WARN] An error occurred while processing the install path, using fallback path: {ex.Message}");
Console.ResetColor();
}
}
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))
{
Console.WriteLine($" [DEBUG] Found RiotClient fallback path found at {drive}{potentialPath}");
return potentialPath;
}
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [ERROR] Failed to locate Riot Client installation path from both fallback method and RiotClientInstalls.");
Console.ResetColor();
return null;
}
}