|
1 | | -using Microsoft.Win32; |
| 1 | +using System.Security; |
| 2 | +using Microsoft.Win32; |
2 | 3 |
|
3 | 4 | namespace Utils; |
4 | 5 |
|
@@ -130,18 +131,72 @@ public static bool IsSteamInstalled() { |
130 | 131 | } |
131 | 132 |
|
132 | 133 | private static bool IsSteamInstalledWindows() { |
133 | | - using var key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam"); |
| 134 | + if (!OperatingSystem.IsWindows()) { |
| 135 | + return false; |
| 136 | + } |
| 137 | + |
| 138 | + // Query registry |
| 139 | + try { |
| 140 | + // Current User |
| 141 | + using var hkcu = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam"); |
| 142 | + var hkcuPath = hkcu?.GetValue("SteamPath") as string; |
| 143 | + |
| 144 | + hkcu?.Close(); |
| 145 | + |
| 146 | + if (!string.IsNullOrEmpty(hkcuPath)) { |
| 147 | + var exePath = Path.Combine(hkcuPath, "steam.exe"); |
| 148 | + |
| 149 | + return File.Exists(exePath); |
| 150 | + } |
| 151 | + |
| 152 | + // Local Machine |
| 153 | + using var hklm = Registry.LocalMachine.OpenSubKey(@"Software\Valve\Steam"); |
| 154 | + var hklmPath = hklm?.GetValue("InstallPath") as string; |
| 155 | + |
| 156 | + hklm?.Close(); |
134 | 157 |
|
135 | | - return string.IsNullOrEmpty(key?.GetValue("SteamPath") as string); |
| 158 | + if (!string.IsNullOrEmpty(hklmPath)) { |
| 159 | + var exePath = Path.Combine(hklmPath, "steam.exe"); |
| 160 | + |
| 161 | + return File.Exists(exePath); |
| 162 | + } |
| 163 | + } |
| 164 | + catch (SecurityException) { /* ignore */ } |
| 165 | + catch (UnauthorizedAccessException) { /* ignore */ } |
| 166 | + |
| 167 | + var potentialLocations = new List<string> { |
| 168 | + @"C:\Program Files (x86)\Steam", |
| 169 | + @"C:\Program Files\Steam", |
| 170 | + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Steam"), |
| 171 | + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Steam"), |
| 172 | + }; |
| 173 | + |
| 174 | + return potentialLocations.Any(Directory.Exists); |
136 | 175 | } |
137 | 176 |
|
138 | 177 | private static bool IsSteamInstalledLinux() { |
| 178 | + if (!OperatingSystem.IsLinux()) { |
| 179 | + return false; |
| 180 | + } |
| 181 | + |
139 | 182 | var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); |
| 183 | + var snapEnv = Environment.GetEnvironmentVariable("SNAP_USER_DATA"); |
| 184 | + var snapDir = !string.IsNullOrEmpty(snapEnv) |
| 185 | + ? snapEnv |
| 186 | + : Path.Combine(home, "snap"); |
140 | 187 |
|
141 | 188 | var potentialLocations = new List<string> { |
142 | | - Path.Combine(home, ".steam/steam"), |
143 | 189 | Path.Combine(home, ".local/share/Steam"), |
144 | | - "/user/lib/steam" |
| 190 | + Path.Combine(home, ".steam/steam"), |
| 191 | + Path.Combine(home, ".steam/root"), |
| 192 | + Path.Combine(home, ".steam/debian-installation"), |
| 193 | + Path.Combine(home, ".var/app/com.valvesoftware.Steam/.local/share/Steam"), |
| 194 | + Path.Combine(home, ".var/app/com.valvesoftware.Steam/.steam/steam"), |
| 195 | + Path.Combine(home, ".var/app/com.valvesoftware.Steam/.steam/root"), |
| 196 | + Path.Combine(snapDir, "steam/common/.local/share/Steam"), |
| 197 | + Path.Combine(snapDir, "steam/common/.steam/steam"), |
| 198 | + Path.Combine(snapDir, "steam/common/.steam/root"), |
| 199 | + "/usr/lib/steam" |
145 | 200 | }; |
146 | 201 |
|
147 | 202 | return potentialLocations.Any(Directory.Exists); |
|
0 commit comments