Skip to content

Commit f41fe38

Browse files
Made stream install search more robust (#8)
* More robust steam install search
1 parent 037d757 commit f41fe38

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

Utils/GamePath.cs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Win32;
1+
using System.Security;
2+
using Microsoft.Win32;
23

34
namespace Utils;
45

@@ -130,18 +131,72 @@ public static bool IsSteamInstalled() {
130131
}
131132

132133
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();
134157

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);
136175
}
137176

138177
private static bool IsSteamInstalledLinux() {
178+
if (!OperatingSystem.IsLinux()) {
179+
return false;
180+
}
181+
139182
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");
140187

141188
var potentialLocations = new List<string> {
142-
Path.Combine(home, ".steam/steam"),
143189
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"
145200
};
146201

147202
return potentialLocations.Any(Directory.Exists);

0 commit comments

Comments
 (0)