From 401ca15393036d64f36f76c609cb688071cb7359 Mon Sep 17 00:00:00 2001 From: Soapwood Date: Wed, 24 Jul 2024 23:03:19 +0100 Subject: [PATCH] [Bug] SteamVR Integration failing when not installed in default location. Will lookup Steam installation path from registry. --- .../SteamVR/SteamVRNotificationClient.cs | 29 ---------------- .../Core/SteamVROverlayAppsInterface.cs | 33 +++++++++++++++++-- VXMusicDesktop/VXMusicDesktop.csproj | 2 +- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/VXMusic/Notifications/SteamVR/SteamVRNotificationClient.cs b/VXMusic/Notifications/SteamVR/SteamVRNotificationClient.cs index 13abab4..51e0b75 100644 --- a/VXMusic/Notifications/SteamVR/SteamVRNotificationClient.cs +++ b/VXMusic/Notifications/SteamVR/SteamVRNotificationClient.cs @@ -68,35 +68,6 @@ as ILogger ?? throw new ApplicationException("A logger must be created in service provider."); } - public static bool IsSteamVRRunningInternal() - { - - //OpenVR.Applications.RemoveApplicationManifest("C:\\Program Files\\VXMusic\\manifest.vrmanifest"); - //var inittoken = OpenVR.IsHmdPresent(); - //var response = OpenVR.Applications.GetSceneApplicationState(); - //var response2 = OpenVR.Applications.GetCurrentSceneProcessId(); - //var response3 = OpenVR.Applications.GetSceneApplicationStateNameFromEnum(EVRSceneApplicationState.Running); - // Check if the VR runtime is installed - bool isRuntimeInstalled = OpenVR.IsRuntimeInstalled(); - if (!isRuntimeInstalled) - { - Console.WriteLine("VR runtime is not installed."); - return false; - } - - OpenVR.GetInitToken(); - - // Check if an HMD is present - bool isHmdPresent = OpenVR.IsHmdPresent(); - if (!isHmdPresent) - { - Console.WriteLine("No HMD detected."); - return false; - } - - return true; - } - public void SendNotificationInternal(string title, string content, int timeout, string image) { _logger.LogTrace("Sending notification request to SteamVR."); diff --git a/VXMusicDesktop/Core/SteamVROverlayAppsInterface.cs b/VXMusicDesktop/Core/SteamVROverlayAppsInterface.cs index a310b57..6da5432 100644 --- a/VXMusicDesktop/Core/SteamVROverlayAppsInterface.cs +++ b/VXMusicDesktop/Core/SteamVROverlayAppsInterface.cs @@ -2,6 +2,7 @@ using System.IO; using Microsoft.Extensions.Logging; using Microsoft.VisualBasic.FileIO; +using Microsoft.Win32; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -12,9 +13,14 @@ public class SteamVROverlayAppsInterface private readonly IServiceProvider _serviceProvider; private readonly ILogger _logger; - // TODO Will this fail without admin privilages? - private static readonly string SteamAppConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Steam\\config\\appconfig.json"); private static readonly string DefaultVxMusicManifestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "VXMusic\\manifest.vrmanifest"); + private static readonly string DefaultSteamAppConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Steam\\config\\appconfig.json"); + + private string SteamAppConfigPath; + private string SteamInstallPath; + + private static readonly string SteamRegistryValue = "SteamPath"; + private static readonly string SteamRegistryKey = @"HKEY_CURRENT_USER\Software\Valve\Steam"; public SteamVROverlayAppsInterface(IServiceProvider serviceProvider) { @@ -23,6 +29,10 @@ public SteamVROverlayAppsInterface(IServiceProvider serviceProvider) as ILogger ?? throw new ApplicationException("A logger must be created in service provider."); _logger.LogTrace("Creating SteamVROverlayAppsInterface."); + + SteamInstallPath = GetSteamInstallationPath(); + + SteamAppConfigPath = Path.GetFullPath(Path.Combine(SteamInstallPath, "config", "appconfig.json")); } public bool InstallVxMusicAsSteamVrOverlay() @@ -30,7 +40,7 @@ public bool InstallVxMusicAsSteamVrOverlay() _logger.LogInformation("Installing VXMusic as a SteamVR Overlay."); return AddManifestEntryToAppConfig(DefaultVxMusicManifestPath); } - + public bool IsManifestEntryInAppConfig() { _logger.LogDebug("Checking if VXMusic is already added as a SteamVR Overlay.."); @@ -38,6 +48,23 @@ public bool IsManifestEntryInAppConfig() return SteamVrManifestPathExistsInAppConfig(manifestPaths, SteamAppConfigPath); } + private string GetSteamInstallationPath() + { + try + { + // Try to read the Steam installation path from the registry + object value = Registry.GetValue(SteamRegistryKey, SteamRegistryValue, null); + if (value != null) return value.ToString(); + } + catch (Exception ex) + { + _logger.LogError($"Error accessing registry entry {SteamRegistryKey}."); + _logger.LogError(ex.Message); + } + + return DefaultSteamAppConfigPath; + } + private bool AddManifestEntryToAppConfig(string vxMusicManifestFile) { try diff --git a/VXMusicDesktop/VXMusicDesktop.csproj b/VXMusicDesktop/VXMusicDesktop.csproj index 3607083..2c43761 100644 --- a/VXMusicDesktop/VXMusicDesktop.csproj +++ b/VXMusicDesktop/VXMusicDesktop.csproj @@ -9,7 +9,7 @@ VXLogo.png Images\VXLogoIcon.ico Always - 0.6.4.10 + 0.6.4.11 en VXMusicDesktop VirtualXtensions