Skip to content

Commit b98858a

Browse files
authored
Fixed game path not updating when changing options (SubnauticaNitrox#2658)
1 parent 093c380 commit b98858a

2 files changed

Lines changed: 15 additions & 27 deletions

File tree

Nitrox.Launcher/ViewModels/OptionsViewModel.cs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,42 +74,30 @@ internal override async Task ViewContentLoadAsync(CancellationToken cancellation
7474
AllowMultipleGameInstances = keyValueStore.GetIsMultipleGameInstancesAllowed();
7575
UseBigPictureMode = keyValueStore.GetUseBigPictureMode();
7676
IsInReleaseMode = NitroxEnvironment.IsReleaseMode;
77-
await SetTargetedSubnauticaPathAsync(SelectedGame.PathToGame).ContinueWithHandleError(ex => LauncherNotifier.Error(ex.Message));
77+
await Task.Run(() => SetTargetedSubnauticaPath(SelectedGame.PathToGame), cancellationToken).ContinueWithHandleError(ex => LauncherNotifier.Error(ex.Message));
7878
}
7979

80-
public async Task SetTargetedSubnauticaPathAsync(string path)
80+
private void SetTargetedSubnauticaPath(string path)
8181
{
8282
if (!Directory.Exists(path))
8383
{
8484
return;
8585
}
8686

87-
if (LaunchGameViewModel.LastFindSubnauticaTask != null)
87+
PirateDetection.TriggerOnDirectory(path);
88+
if (!FileSystem.Instance.IsWritable(Directory.GetCurrentDirectory()) || !FileSystem.Instance.IsWritable(path))
8889
{
89-
await LaunchGameViewModel.LastFindSubnauticaTask;
90-
}
91-
92-
LaunchGameViewModel.LastFindSubnauticaTask = Task.Run(() =>
93-
{
94-
PirateDetection.TriggerOnDirectory(path);
95-
96-
if (!FileSystem.Instance.IsWritable(Directory.GetCurrentDirectory()) || !FileSystem.Instance.IsWritable(path))
90+
// TODO: Move this check to another place where Nitrox installation can be verified. (i.e: another page on the launcher in order to check permissions, network setup, ...)
91+
if (!FileSystem.Instance.SetFullAccessToCurrentUser(Directory.GetCurrentDirectory()) || !FileSystem.Instance.SetFullAccessToCurrentUser(path))
9792
{
98-
// TODO: Move this check to another place where Nitrox installation can be verified. (i.e: another page on the launcher in order to check permissions, network setup, ...)
99-
if (!FileSystem.Instance.SetFullAccessToCurrentUser(Directory.GetCurrentDirectory()) || !FileSystem.Instance.SetFullAccessToCurrentUser(path))
100-
{
101-
LauncherNotifier.Error("Restart Nitrox Launcher as admin to allow Nitrox to change permissions as needed. This is only needed once. Nitrox will close after this message.");
102-
return null;
103-
}
93+
LauncherNotifier.Error("Restart Nitrox Launcher as admin to allow Nitrox to change permissions as needed. This is only needed once. Nitrox will close after this message.");
94+
return;
10495
}
96+
}
10597

106-
// Save game path as preferred for future sessions.
107-
NitroxUser.PreferredGamePath = path;
108-
109-
return path;
110-
});
111-
112-
await LaunchGameViewModel.LastFindSubnauticaTask;
98+
// Save game path as preferred for future sessions.
99+
NitroxUser.PreferredGamePath = path;
100+
NitroxUser.SetGamePathAndPlatform(path, null);
113101
}
114102

115103
[RelayCommand]
@@ -129,7 +117,7 @@ private async Task SetGamePath()
129117

130118
if (!selectedDirectory.Equals(SelectedGame.PathToGame, StringComparison.OrdinalIgnoreCase))
131119
{
132-
await SetTargetedSubnauticaPathAsync(selectedDirectory);
120+
await Task.Run(() => SetTargetedSubnauticaPath(selectedDirectory));
133121
SelectedGame = new() { PathToGame = NitroxUser.GamePath, Platform = NitroxUser.GamePlatform?.Platform ?? Platform.NONE };
134122
LauncherNotifier.Success("Applied changes");
135123
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public GameFinderResult FindGame(GameInfo gameInfo)
5050
return Ok(path);
5151
}
5252

53-
private static string GetSteamPath()
53+
private static string? GetSteamPath()
5454
{
5555
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
5656
{
@@ -129,7 +129,7 @@ private static string GetSteamPath()
129129
/// <summary>
130130
/// Finds game install directory by iterating through all the steam game libraries configured, matching the given appid.
131131
/// </summary>
132-
private static string SearchAllInstallations(string libraryFolders, int appid, string gameName)
132+
private static string? SearchAllInstallations(string libraryFolders, int appid, string gameName)
133133
{
134134
if (!File.Exists(libraryFolders))
135135
{

0 commit comments

Comments
 (0)