|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics; |
4 | 4 | using System.IO; |
| 5 | +using System.Linq; |
5 | 6 | using System.Runtime.InteropServices; |
6 | 7 | using System.Text.RegularExpressions; |
7 | 8 | using System.Threading; |
@@ -107,34 +108,74 @@ await RegistryEx.CompareWaitAsync<int>(@"SOFTWARE\Valve\Steam\ActiveProcess\Acti |
107 | 108 | return steam; |
108 | 109 | } |
109 | 110 |
|
110 | | - private static string? GetExeFile() |
| 111 | + public static string? GetExeFile() |
111 | 112 | { |
112 | 113 | string steamExecutable = ""; |
113 | 114 |
|
114 | 115 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
115 | 116 | { |
116 | | - steamExecutable = Path.Combine(RegistryEx.Read(@"SOFTWARE\Valve\Steam\SteamPath", steamExecutable), "steam.exe"); |
| 117 | + string steamPath = RegistryEx.Read<string>(@"Software\Valve\Steam\SteamPath"); |
| 118 | + |
| 119 | + if (string.IsNullOrWhiteSpace(steamPath)) |
| 120 | + { |
| 121 | + steamPath = Path.Combine( |
| 122 | + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), |
| 123 | + "Steam" |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + steamExecutable = Directory.Exists(steamPath) ? Path.Combine(steamPath, "steam.exe") : ""; |
117 | 128 | } |
118 | 129 | else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) |
119 | 130 | { |
120 | 131 | steamExecutable = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Steam", "Steam.AppBundle", "Steam", "Contents", "MacOS", "steam_osx"); |
121 | 132 | } |
122 | 133 | else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) |
123 | 134 | { |
124 | | - string userHomePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); |
125 | | - if (!Directory.Exists(userHomePath)) |
| 135 | + string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); |
| 136 | + if (string.IsNullOrWhiteSpace(homePath)) |
| 137 | + { |
| 138 | + homePath = Environment.GetEnvironmentVariable("HOME"); |
| 139 | + } |
| 140 | + if (!Directory.Exists(homePath)) |
126 | 141 | { |
127 | 142 | return null; |
128 | 143 | } |
129 | 144 |
|
130 | | - string steamPath = Path.Combine(userHomePath, ".steam", "steam"); |
131 | | - // support flatpak |
132 | | - if (!Directory.Exists(steamPath)) |
| 145 | + string[] commonPaths = [ |
| 146 | + // Default install location |
| 147 | + // https://github.com/ValveSoftware/steam-for-linux |
| 148 | + Path.Combine(homePath, ".local", "share", "Steam"), |
| 149 | + // Those symlinks are often use as a backward-compatibility (Debian, Ubuntu, Fedora, ArchLinux) |
| 150 | + // https://wiki.archlinux.org/title/steam, https://askubuntu.com/questions/227502/where-are-steam-games-installed |
| 151 | + Path.Combine(homePath, ".steam", "steam"), |
| 152 | + Path.Combine(homePath, ".steam", "root"), |
| 153 | + // Flatpack install |
| 154 | + // https://github.com/flathub/com.valvesoftware.Steam/wiki, https://flathub.org/apps/com.valvesoftware.Steam |
| 155 | + Path.Combine(homePath, ".var", "app", "com.valvesoftware.Steam", ".local", "share", "Steam"), |
| 156 | + Path.Combine(homePath, ".var", "app", "com.valvesoftware.Steam", ".steam", "steam"), |
| 157 | + ]; |
| 158 | + |
| 159 | + string steamPath = ""; |
| 160 | + foreach (string path in commonPaths) |
| 161 | + { |
| 162 | + try |
| 163 | + { |
| 164 | + if (Directory.GetFileSystemEntries(path).Any()) |
| 165 | + { |
| 166 | + steamPath = path; |
| 167 | + break; |
| 168 | + } |
| 169 | + } |
| 170 | + catch |
| 171 | + { |
| 172 | + // ignored |
| 173 | + } |
| 174 | + } |
| 175 | + if (!string.IsNullOrWhiteSpace(steamPath)) |
133 | 176 | { |
134 | | - steamPath = Path.Combine(userHomePath, ".var", "app", "com.valvesoftware.Steam", "data", "Steam"); |
| 177 | + steamExecutable = Path.Combine(steamPath, "steam.sh"); |
135 | 178 | } |
136 | | - |
137 | | - steamExecutable = Path.Combine(steamPath, "steam.sh"); |
138 | 179 | } |
139 | 180 |
|
140 | 181 | return File.Exists(steamExecutable) ? Path.GetFullPath(steamExecutable) : null; |
|
0 commit comments