Skip to content

Commit

Permalink
[Bug] SteamVR Integration failing when not installed in default locat…
Browse files Browse the repository at this point in the history
…ion.

Will lookup Steam installation path from registry.
  • Loading branch information
Soapwood committed Jul 24, 2024
1 parent aa9b00e commit 401ca15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
29 changes: 0 additions & 29 deletions VXMusic/Notifications/SteamVR/SteamVRNotificationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,6 @@ as ILogger<SteamVRNotificationOverlay> ??
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.");
Expand Down
33 changes: 30 additions & 3 deletions VXMusicDesktop/Core/SteamVROverlayAppsInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -12,9 +13,14 @@ public class SteamVROverlayAppsInterface
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<SteamVROverlayAppsInterface> _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)
{
Expand All @@ -23,21 +29,42 @@ public SteamVROverlayAppsInterface(IServiceProvider serviceProvider)
as ILogger<SteamVROverlayAppsInterface> ?? 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()
{
_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..");
var (manifestPaths, _) = ReadContentsOfAppConfig();
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
Expand Down
2 changes: 1 addition & 1 deletion VXMusicDesktop/VXMusicDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageIcon>VXLogo.png</PackageIcon>
<ApplicationIcon>Images\VXLogoIcon.ico</ApplicationIcon>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<Version>0.6.4.10</Version>
<Version>0.6.4.11</Version>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<Title>VXMusicDesktop</Title>
<Authors>VirtualXtensions</Authors>
Expand Down

0 comments on commit 401ca15

Please sign in to comment.