Skip to content

Commit

Permalink
Add a fallback on linux for flatpak users
Browse files Browse the repository at this point in the history
  • Loading branch information
Earu authored Oct 8, 2024
1 parent 5bd96b4 commit a243151
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions GmodInterop.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GTerm.Extensions;
using GTerm.Extensions;
using Microsoft.Win32;
using Spectre.Console;
using System.Diagnostics;
Expand Down Expand Up @@ -67,6 +67,11 @@ private static bool TryGetSteamVDFPath(out string vdfPath)
if (!File.Exists(vdfPath))
{
vdfPath = Path.Join(homeDir, "/.local/share/Steam/steamapps/libraryfolders.vdf");
if (!File.Exists(vdfPath))
{
// flatpak
vdfPath = Path.Join(homeDir, "/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/libraryfolders.vdf");
}
}

return File.Exists(vdfPath);
Expand Down Expand Up @@ -244,6 +249,39 @@ private static async Task<bool> InstallBinary(bool isX64, string gtermDir, strin
return false;
}

private static bool IsGmodX64(string gmodBinPath)
{
// Base assumption in case it fails later (windows can do x86 and x64, linux/mac only x64)
bool isX64 = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || gmodBinPath.Contains("win64", StringComparison.CurrentCulture);

// Fetch the gmod manifest to make a safer assumption of the current branch
if (TryGetSteamVDFPath(out string vdfPath))
{
try
{
string? vdfDirPath = Path.GetDirectoryName(vdfPath);
if (vdfDirPath != null)
{
string gmodManifiestPath = Path.Join(vdfDirPath, "appmanifest_4000.acf");
if (File.Exists(gmodManifiestPath))
{
FileStream gmodManifestFile = File.OpenRead(gmodManifiestPath);
VdfDeserializer deserializer = new();
dynamic result = deserializer.Deserialize(gmodManifestFile);

isX64 = result?.AppState?.UserConfig?.BetaKey == "x86-64";
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Could not find Garry's Mod manifest, assuming branch\n" + ex.Message);
}
}

return isX64;
}

internal static async Task<(bool, bool)> InstallXConsole()
{
bool modifiedGameFiles = false;
Expand All @@ -266,8 +304,7 @@ private static async Task<bool> InstallBinary(bool isX64, string gtermDir, strin
string? gtermDir = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName);
if (gtermDir == null) return (success, modifiedGameFiles);

// only x64 works on linux/mac
bool isX64 = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || gmodBinPath.Contains("win64", StringComparison.CurrentCulture);
bool isX64 = IsGmodX64(gmodBinPath);
bool justInstalledBin = await InstallBinary(isX64, gtermDir, luaBinPath);
if (justInstalledBin) {
modifiedGameFiles = true;
Expand Down

0 comments on commit a243151

Please sign in to comment.