Skip to content

Commit

Permalink
Fix for discord game discovery (#1731)
Browse files Browse the repository at this point in the history
* Fix for discord game discovery

* Removed specific subnautica check for steam
  • Loading branch information
dartasen authored Feb 18, 2022
1 parent 6b9d686 commit 8c5c52c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 49 deletions.
3 changes: 2 additions & 1 deletion NitroxLauncher/LauncherConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.CompilerServices;
using NitroxLauncher.Properties;
using NitroxModel.Discovery;
using NitroxModel.Platforms.Store;

namespace NitroxLauncher
{
Expand Down Expand Up @@ -53,7 +54,7 @@ public string SubnauticaPath
{
// Ensures the path looks alright (no mixed / and \ path separators)
subnauticaPath = Path.GetFullPath(value);
SubnauticaPlatform = PlatformDetection.GetPlatform(subnauticaPath);
subnauticaPlatform = GamePlatforms.GetPlatformByGameDir(subnauticaPath)?.platform ?? Platform.NONE;
OnPropertyChanged();
}
}
Expand Down
2 changes: 1 addition & 1 deletion NitroxLauncher/LauncherLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private async Task<ProcessEx> StartSubnauticaAsync()
using ProcessEx game = platform switch
{
Steam s => await s.StartGameAsync(subnauticaExe, GameInfo.Subnautica.SteamAppId, subnauticaLaunchArguments),
Egs e => await e.StartGameAsync(subnauticaExe, subnauticaLaunchArguments),
EpicGames e => await e.StartGameAsync(subnauticaExe, subnauticaLaunchArguments),
MSStore m => await m.StartGameAsync(subnauticaExe),
DiscordStore d => await d.StartGameAsync(subnauticaExe, subnauticaLaunchArguments),
_ => throw new Exception($"Directory '{subnauticaPath}' is not a valid {GameInfo.Subnautica.Name} game installation or the game's platform is unsupported by Nitrox.")
Expand Down
31 changes: 0 additions & 31 deletions NitroxModel/Discovery/PlatformDetection.cs

This file was deleted.

4 changes: 3 additions & 1 deletion NitroxModel/Platforms/Store/Discord.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using NitroxModel.Discovery;
using NitroxModel.Helper;
using NitroxModel.Platforms.OS.Shared;
using NitroxModel.Platforms.Store.Interfaces;
Expand All @@ -13,10 +14,11 @@ public sealed class Discord : IGamePlatform
public static Discord Instance => instance ??= new Discord();

public string Name => nameof(Discord);
public Platform platform => Platform.DISCORD;

public bool OwnsGame(string gameDirectory)
{
return File.Exists(Path.Combine(Directory.GetParent(gameDirectory)?.FullName ?? "", "journal.sqlite"));
return File.Exists(Path.Combine(Directory.GetParent(gameDirectory)?.FullName ?? "..", "journal.sqlite"));
}

public async Task<ProcessEx> StartPlatformAsync()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
using System;
using System.IO;
using System.Threading.Tasks;
using NitroxModel.Discovery;
using NitroxModel.Helper;
using NitroxModel.Platforms.OS.Shared;
using NitroxModel.Platforms.Store.Interfaces;

namespace NitroxModel.Platforms.Store
{
/// <summary>
/// Epic games store.
/// </summary>
public sealed class Egs : IGamePlatform
public sealed class EpicGames : IGamePlatform
{
private static Egs instance;
public static Egs Instance => instance ??= new Egs();
private static EpicGames instance;
public static EpicGames Instance => instance ??= new EpicGames();

public string Name => "Epic Games Store";
public Platform platform => Platform.EPIC;

public bool OwnsGame(string gameDirectory)
{
return Directory.Exists(Path.Combine(gameDirectory, ".egstore"));
string path = Path.Combine(gameDirectory, ".egstore");
return Directory.Exists(path) && Directory.GetFiles(path).Length > 1;
}

public string Name => "Epic Games Store";

public async Task<ProcessEx> StartPlatformAsync()
{
await Task.CompletedTask; // Suppresses async-without-await warning - can be removed.
Expand Down
3 changes: 2 additions & 1 deletion NitroxModel/Platforms/Store/GamePlatforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NitroxModel.Platforms.Store
{
public static class GamePlatforms
{
public static readonly IGamePlatform[] AllPlatforms = { Steam.Instance, Egs.Instance, MSStore.Instance, Discord.Instance };
public static readonly IGamePlatform[] AllPlatforms = { Steam.Instance, EpicGames.Instance, Discord.Instance, MSStore.Instance };

public static IGamePlatform GetPlatformByGameDir(string gameDirectory)
{
Expand All @@ -21,6 +21,7 @@ public static IGamePlatform GetPlatformByGameDir(string gameDirectory)
return platform;
}
}

return null;
}
}
Expand Down
13 changes: 9 additions & 4 deletions NitroxModel/Platforms/Store/Interfaces/IGamePlatform.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
using System.Threading.Tasks;
using NitroxModel.Discovery;
using NitroxModel.Platforms.OS.Shared;

namespace NitroxModel.Platforms.Store.Interfaces
{
public interface IGamePlatform
{
string Name { get; }

Platform platform { get; }

/// <summary>
/// Tries to start the platform and waits for it to be ready to launch games. If it has already been started it will return true.
/// </summary>
/// <returns>Returns true if platform is running or has started successfully.</returns>
public Task<ProcessEx> StartPlatformAsync();

/// <summary>
/// Tries to find the executable of the platform or null if not found.
/// Tries to find the executable of the platform
/// </summary>
/// <returns></returns>
/// <returns>Returns path to the executable or null if not found</returns>
public string GetExeFile();

/// <summary>
/// True if game directory originates from the game platform.
/// </summary>
/// <param name="gameDirectory">Directory to a game, usually where the exe file is.</param>
/// <returns>True if the game platform owns this game.</returns>
/// <returns>Returns true if the game platform owns this game.</returns>
bool OwnsGame(string gameDirectory);

string Name { get; }

}
}
4 changes: 3 additions & 1 deletion NitroxModel/Platforms/Store/MSStore.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using NitroxModel.Discovery;
using NitroxModel.Platforms.OS.Shared;
using NitroxModel.Platforms.Store.Interfaces;

Expand All @@ -12,11 +13,12 @@ public sealed class MSStore : IGamePlatform
public static MSStore Instance => instance ??= new MSStore();

public string Name => "Microsoft Store";
public Platform platform => Platform.MICROSOFT;

public bool OwnsGame(string gameDirectory)
{
bool isLocalAppData = Path.GetFullPath(gameDirectory).StartsWith(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Packages"), StringComparison.InvariantCultureIgnoreCase);
return isLocalAppData;
return isLocalAppData || File.Exists(Path.Combine(gameDirectory, "appxmanifest.xml"));
}

public async Task<ProcessEx> StartPlatformAsync()
Expand Down
2 changes: 2 additions & 0 deletions NitroxModel/Platforms/Store/Steam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using NitroxModel.Discovery;
using NitroxModel.Helper;
using NitroxModel.Platforms.OS.Shared;
using NitroxModel.Platforms.OS.Windows.Internal;
Expand All @@ -16,6 +17,7 @@ public sealed class Steam : IGamePlatform
public static Steam Instance => instance ??= new Steam();

public string Name => nameof(Steam);
public Platform platform => Platform.STEAM;

public bool OwnsGame(string gameDirectory)
{
Expand Down

0 comments on commit 8c5c52c

Please sign in to comment.