Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game finders overhaul #2053

Conversation

dartasen
Copy link
Member

@dartasen dartasen commented Jun 16, 2023

Nitrox has always defined an order in the way it searches the Subnautica installation files. This works in most cases, since users generally have only one installation of the game. However, this approach raises questions when a user has the game on both Steam & Epic.

The aim of this PR is to do away with this automatic way of doing things, by providing an API that lets you search for one or more installations of a given game (GameInfo) via flags (GameLibraries).

i.e:

IEnumerable<GameInstallation> installations = GameInstallerFinder.FindGame(GameInfo.SubnauticaZero, GameLibraries.EPIC | GameLibraries.STEAM);

var wantedInstallation = installations.Where(install => install.Origin == GameLibraries.Steam)

That will allow the launcher to display all the path, and let the user choose between them. Rather than imposing it.

Progression

  • Reimplement finders
  • Rework option page of the launcher
  • Cleanup of the launcher (especially Styles + UI bugfixes)

Below zero will follow up in another Pull Request

@dartasen dartasen marked this pull request as draft June 16, 2023 09:47
Nitrox.BuildTool/Models/GameInstallData.cs Outdated Show resolved Hide resolved
Nitrox.BuildTool/Models/GameInstallData.cs Show resolved Hide resolved
Nitrox.BuildTool/Models/GameInstallData.cs Show resolved Hide resolved
Nitrox.BuildTool/Models/GameInstallData.cs Outdated Show resolved Hide resolved
NitroxModel/Discovery/IGameFinder.cs Outdated Show resolved Hide resolved
NitroxModel/Discovery/Models/GameLibraries.cs Outdated Show resolved Hide resolved
NitroxModel/GameInfo.cs Outdated Show resolved Hide resolved
NitroxModel/Helper/NitroxUser.cs Outdated Show resolved Hide resolved
NitroxModel/Discovery/GameInstallationFinder.cs Outdated Show resolved Hide resolved
NitroxModel/Discovery/GameInstallationFinder.cs Outdated Show resolved Hide resolved
NitroxModel/Helper/NitroxUser.cs Outdated Show resolved Hide resolved
@dartasen dartasen force-pushed the feature/rework-installation-finding branch from a709177 to b67610b Compare August 8, 2023 12:02
NitroxLauncher/App.xaml.cs Outdated Show resolved Hide resolved
NitroxLauncher/App.xaml.cs Outdated Show resolved Hide resolved
NitroxLauncher/Models/Extensions.cs Outdated Show resolved Hide resolved
NitroxLauncher/Usings.cs Outdated Show resolved Hide resolved
NitroxModel/Discovery/IGameFinder.cs Outdated Show resolved Hide resolved
@dartasen dartasen force-pushed the feature/rework-installation-finding branch from b67610b to 44a6d95 Compare September 24, 2023 14:02
@dartasen dartasen marked this pull request as ready for review September 24, 2023 14:36
@dartasen dartasen force-pushed the feature/rework-installation-finding branch from 82e50ce to 174c608 Compare September 24, 2023 14:53
@dartasen
Copy link
Member Author

Still need to untangle NitroxUser around game path managing, but it's getting there

@dartasen dartasen force-pushed the feature/rework-installation-finding branch from 174c608 to b6ffee2 Compare September 24, 2023 15:48
Comment on lines +1 to +2
using NitroxModel.Discovery.Models;
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong sorting

NitroxModel/Platforms/OS/Shared/FileSystem.cs Show resolved Hide resolved
Log.Error(e.Exception.GetBaseException().ToString()); // Gets the exception that was unhandled, not the "dispatched unhandled" exception.
MessageBox.Show(GetExceptionError(e.Exception), "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
}
MessageBox.Show(GetExceptionError(e.Exception), "Unexpected error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would keep the comment:
// Gets the exception that was unhandled, not the "dispatched unhandled" exception.

as .GetBaseException() is usually a bad thing to do (except for niche case here)


using (StreamReader sr = new(response.GetResponseStream()))
using (StreamReader sr = new(response.GetResponseStream()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using (StreamReader sr = new(response.GetResponseStream()))
using (StreamReader sr = new(response.GetResponseStream() ?? Stream.Null))

using (StreamReader sr = new(response.GetResponseStream()))
using (StreamReader sr = new(response.GetResponseStream()))
{
string json = sr.ReadToEnd();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string json = sr.ReadToEnd();
string json = await sr.ReadToEndAsync();

{
Log.Info("Fetched nitrox changelogs from the local cache");
}
public async static Task<IList<NitroxChangelog>> GetChangeLogsAsync(CancellationToken cancellationToken = default)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public async static Task<IList<NitroxChangelog>> GetChangeLogsAsync(CancellationToken cancellationToken = default)
public static async Task<IList<NitroxChangelog>> GetChangeLogsAsync(CancellationToken cancellationToken = default)

using WebResponse response = await GetResponseFromCache(BLOGS_URL);
try
{
using WebResponse response = await GetResponseFromCacheAsync(BLOGS_URL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using WebResponse response = await GetResponseFromCacheAsync(BLOGS_URL);
using WebResponse response = await GetResponseFromCacheAsync(BLOGS_URL, cancellationToken);

IsFolderPicker = true,
Title = "Select Subnautica installation directory"
})
GameInstallation currentInstallation = GameInstallations.Where(x => x.Path == NitroxUser.PreferredGamePath).FirstOrDefault();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GameInstallation currentInstallation = GameInstallations.Where(x => x.Path == NitroxUser.PreferredGamePath).FirstOrDefault();
GameInstallation currentInstallation = GameInstallations.FirstOrDefault(x => x.Path == NitroxUser.PreferredGamePath);

NitroxModel/GameInfo.cs Show resolved Hide resolved
Comment on lines +22 to +23
[Description("Pirated")]
PIRATED = 255
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum is int by default.

This enum is supposed to contain real game stores. I recommend just removing the "Pirated" flag, and infer it from the detection trigger instead.

@Measurity
Copy link
Collaborator

Got an error trying to delete server save files via launcher:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at NitroxModel.Platforms.OS.Windows.Internal.Win32Native.SHFileOperation(SHFILEOPSTRUCT& FileOp)
   at NitroxModel.Platforms.OS.Windows.WinFileSystem.DeleteFileOrFolder(String path) in NitroxModel\Platforms\OS\Windows\WinFileSystem.cs:line 108
   at NitroxModel.Platforms.OS.Windows.WinFileSystem.MoveDirectoryToRecycleBin(DirectoryInfo directoryInfo) in NitroxModel\Platforms\OS\Windows\WinFileSystem.cs:line 127
   at NitroxModel.Platforms.OS.Shared.FileSystem.MoveDirectoryToRecycleBin(String path) in NitroxModel\Platforms\OS\Shared\FileSystem.cs:line 263
   at NitroxLauncher.Pages.ServerPage.YesConfirmBtn_Click(Object sender, RoutedEventArgs e) in NitroxLauncher\Pages\ServerPage.xaml.cs:line 291
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at NitroxLauncher.App.Main()

@dartasen dartasen marked this pull request as draft November 24, 2023 09:08
@tornac1234 tornac1234 added the Area: dev Related to development environment label Dec 23, 2023
@dartasen dartasen closed this Feb 11, 2024
@dartasen dartasen mentioned this pull request Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: dev Related to development environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants