diff --git a/src/IronyModManager.IO/Platforms/SteamHandler.cs b/src/IronyModManager.IO/Platforms/SteamHandler.cs index 49e16a22..f1ef97cf 100644 --- a/src/IronyModManager.IO/Platforms/SteamHandler.cs +++ b/src/IronyModManager.IO/Platforms/SteamHandler.cs @@ -1,10 +1,11 @@ -// *********************************************************************** + +// *********************************************************************** // Assembly : IronyModManager.IO // Author : Mario // Created : 07-11-2022 // // Last Modified By : Mario -// Last Modified On : 11-18-2022 +// Last Modified On : 11-03-2023 // *********************************************************************** // // Mario @@ -24,6 +25,7 @@ namespace IronyModManager.IO.Platforms { + /// /// Class SteamHandler. /// Implements the @@ -152,6 +154,7 @@ public async Task InitAsync(long appId) } var result = await InitializeAndValidateAsync(); var initCheckAttempts = 0; + // Will keep trying until steam starts while (!result) { @@ -177,6 +180,21 @@ public Task ShutdownAPIAsync() return Task.FromResult(true); } +#pragma warning disable SYSLIB1054 // Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time + /// + /// Setenvs the specified name. + /// + /// The name. + /// The value. + /// if set to true [overwrite]. + /// System.Int32. + [DllImport("libc", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] + + // No thanks, don't want to flag allow unsafe just yet + private static extern int setenv(string name, string value, bool overwrite); + +#pragma warning restore SYSLIB1054 // Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time + /// /// Cleanups the application identifier. /// @@ -248,10 +266,10 @@ private Task OpenAsync(string command) private async Task SetAppId(long appId) { var appIdValue = appId.ToString(); - Environment.SetEnvironmentVariable("SteamAppId", appIdValue); - Environment.SetEnvironmentVariable("SteamOverlayGameId", appIdValue); - Environment.SetEnvironmentVariable("SteamGameId", appIdValue); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + SetEnvironmentVariable("SteamAppId", appIdValue); + SetEnvironmentVariable("SteamOverlayGameId", appIdValue); + SetEnvironmentVariable("SteamGameId", appIdValue); + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { try { @@ -263,6 +281,24 @@ private async Task SetAppId(long appId) } } + /// + /// Sets the environment variable. + /// + /// The name. + /// The value. + private void SetEnvironmentVariable(string name, string value) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + // Way to go Microsoft + _ = setenv(name, value, true); + } + else + { + Environment.SetEnvironmentVariable(name, value); + } + } + #endregion Methods } }