-
Notifications
You must be signed in to change notification settings - Fork 0
/
RiotClient.cs
112 lines (100 loc) · 3.91 KB
/
RiotClient.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Reflection;
namespace RiotGamesLibrary
{
public class RiotGame
{
private struct GameName
{
public string registryName;
public string exeName;
}
private static Dictionary<string, GameName> idToInstall = new Dictionary<string, GameName>()
{
{ "rg-leagueoflegends", new GameName(){registryName = "league_of_legends", exeName = "LeagueClient.exe"} },
{ "rg-valorant", new GameName(){registryName = "valorant", exeName = "VALORANT.exe"} },
{ "rg-legendsofruneterra", new GameName(){registryName = "bacon", exeName = "LoR.exe"} }
};
public static Dictionary<string, string> Icons = new Dictionary<string, string>()
{
{ "rg-leagueoflegends", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Resources\league_of_legends.live.ico") },
{ "rg-valorant", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Resources\valorant.live.ico") },
{ "rg-legendsofruneterra", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Resources\bacon.live.ico") }
};
public static string InstallPath(string gameId)
{
using (var key = Registry.CurrentUser.OpenSubKey($@"Software\Microsoft\Windows\CurrentVersion\Uninstall\Riot Game {idToInstall[gameId].registryName}.live"))
{
if (key != null && File.Exists(Path.Combine(key?.GetValue("InstallLocation").ToString(), idToInstall[gameId].exeName)))
{
return Path.GetFullPath(key.GetValue("InstallLocation").ToString());
}
return string.Empty;
}
}
public static bool IsInstalled(string gameId)
{
if (string.IsNullOrEmpty(InstallPath(gameId)) || !Directory.Exists(InstallPath(gameId)))
{
return false;
}
else
{
return true;
}
}
}
public class RiotClient
{
public static string ClientExecPath
{
get
{
var path = InstallationPath;
return string.IsNullOrEmpty(path) ? string.Empty : Path.Combine(path, "RiotClientServices.exe");
}
}
public static string InstallationPath
{
get
{
using (var key = Registry.ClassesRoot.OpenSubKey(@"riotclient\shell\open\command"))
{
if (key?.GetValue("").ToString().Contains("RiotClientServices.exe") == true)
{
return Path.GetDirectoryName(key.GetValue("").ToString().Split('\"')[1]);
}
}
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\riotclient\shell\open\command"))
{
if (key?.GetValue("").ToString().Contains("RiotClientServices.exe") == true)
{
return Path.GetDirectoryName(key.GetValue("").ToString().Split('\"')[1]);
}
}
return string.Empty;
}
}
public static bool IsInstalled
{
get
{
if (string.IsNullOrEmpty(InstallationPath) || !Directory.Exists(InstallationPath))
{
return false;
}
else
{
return true;
}
}
}
public static string Icon => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Resources\rioticon.png");
}
}