Skip to content

Commit 13e8037

Browse files
authored
Fixed Steam exe not found for some setups on Linux (SubnauticaNitrox#2664)
2 parents 3f06268 + 4830234 commit 13e8037

2 files changed

Lines changed: 57 additions & 66 deletions

File tree

Nitrox.Model/Platforms/Discovery/InstallationFinders/SteamFinder.cs

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Runtime.InteropServices;
44
using System.Text.RegularExpressions;
55
using Nitrox.Model.Platforms.Discovery.InstallationFinders.Core;
6-
using Nitrox.Model.Platforms.OS.Windows;
6+
using Nitrox.Model.Platforms.Store;
77
using static Nitrox.Model.Platforms.Discovery.InstallationFinders.Core.GameFinderResult;
88

99
namespace Nitrox.Model.Platforms.Discovery.InstallationFinders;
@@ -50,69 +50,19 @@ public GameFinderResult FindGame(GameInfo gameInfo)
5050
return Ok(path);
5151
}
5252

53-
private static string? GetSteamPath()
53+
private static string GetSteamPath()
5454
{
55-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
56-
{
57-
string steamPath = RegistryEx.Read<string>(@"Software\Valve\Steam\SteamPath");
58-
59-
if (string.IsNullOrWhiteSpace(steamPath))
60-
{
61-
steamPath = Path.Combine(
62-
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
63-
"Steam"
64-
);
65-
}
66-
67-
return Directory.Exists(steamPath) ? steamPath : null;
68-
}
69-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
70-
{
71-
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
72-
if (string.IsNullOrWhiteSpace(homePath))
73-
{
74-
homePath = Environment.GetEnvironmentVariable("HOME");
75-
}
76-
77-
if (!Directory.Exists(homePath))
78-
{
79-
return null;
80-
}
81-
82-
string[] commonSteamPath =
83-
[
84-
// Default install location
85-
// https://github.com/ValveSoftware/steam-for-linux
86-
Path.Combine(homePath, ".local", "share", "Steam"),
87-
// Those symlinks are often use as a backward-compatibility (Debian, Ubuntu, Fedora, ArchLinux)
88-
// https://wiki.archlinux.org/title/steam, https://askubuntu.com/questions/227502/where-are-steam-games-installed
89-
Path.Combine(homePath, ".steam", "steam"),
90-
Path.Combine(homePath, ".steam", "root"),
91-
// Flatpack install
92-
// https://github.com/flathub/com.valvesoftware.Steam/wiki, https://flathub.org/apps/com.valvesoftware.Steam
93-
Path.Combine(homePath, ".var", "app", "com.valvesoftware.Steam", ".local", "share", "Steam"),
94-
Path.Combine(homePath, ".var", "app", "com.valvesoftware.Steam", ".steam", "steam"),
95-
];
96-
97-
foreach (string path in commonSteamPath)
98-
{
99-
if (Directory.Exists(path))
100-
{
101-
return path;
102-
}
103-
}
104-
}
105-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
55+
// OSX: Steam dynamic data isn't near the steam exe. Because it can't (or isn't supposed to) write anything inside application bundle.
56+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
10657
{
10758
string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
10859
if (string.IsNullOrWhiteSpace(homePath))
10960
{
11061
homePath = Environment.GetEnvironmentVariable("HOME");
11162
}
112-
11363
if (!Directory.Exists(homePath))
11464
{
115-
return null;
65+
return "";
11666
}
11767

11868
// Steam should always be here
@@ -123,7 +73,7 @@ public GameFinderResult FindGame(GameInfo gameInfo)
12373
}
12474
}
12575

126-
return null;
76+
return Path.GetDirectoryName(Steam.GetExeFile()) ?? "";
12777
}
12878

12979
/// <summary>

Nitrox.Model/Platforms/Store/Steam.cs

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Runtime.InteropServices;
67
using System.Text.RegularExpressions;
78
using System.Threading;
@@ -107,34 +108,74 @@ await RegistryEx.CompareWaitAsync<int>(@"SOFTWARE\Valve\Steam\ActiveProcess\Acti
107108
return steam;
108109
}
109110

110-
private static string? GetExeFile()
111+
public static string? GetExeFile()
111112
{
112113
string steamExecutable = "";
113114

114115
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
115116
{
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") : "";
117128
}
118129
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
119130
{
120131
steamExecutable = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Steam", "Steam.AppBundle", "Steam", "Contents", "MacOS", "steam_osx");
121132
}
122133
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
123134
{
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))
126141
{
127142
return null;
128143
}
129144

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))
133176
{
134-
steamPath = Path.Combine(userHomePath, ".var", "app", "com.valvesoftware.Steam", "data", "Steam");
177+
steamExecutable = Path.Combine(steamPath, "steam.sh");
135178
}
136-
137-
steamExecutable = Path.Combine(steamPath, "steam.sh");
138179
}
139180

140181
return File.Exists(steamExecutable) ? Path.GetFullPath(steamExecutable) : null;

0 commit comments

Comments
 (0)