22using NLog ;
33using System ;
44using System . Collections . Generic ;
5+ using System . ComponentModel ;
56using System . Configuration ;
67using System . Data ;
78using System . Diagnostics ;
@@ -20,6 +21,7 @@ public partial class App : Application
2021 {
2122 const string DEFAULT_BOXVR_APPDATA = @"%userprofile%\AppData\LocalLow\FITXR\BOXVR" ;
2223 const string REGISTRY_UNINSTALL_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ;
24+ const string REGISTRY_OCULUS_LIB_KEY = @"Software\Oculus VR, LLC\Oculus\Libraries" ;
2325 const string REGISTRY_STEAM_KEY = @"HKEY_CURRENT_USER\Software\Valve\Steam" ;
2426
2527
@@ -76,20 +78,78 @@ private static string LocateBoxVRExe()
7678 {
7779 using ( var subkey = key . OpenSubKey ( subkey_name ) )
7880 {
79- logger . Trace ( $ "Checking reg key { REGISTRY_UNINSTALL_KEY } \\ { subkey_name } ") ;
81+ logger . Trace ( $ "Checking reg key HKLM \\ { REGISTRY_UNINSTALL_KEY } \\ { subkey_name } ") ;
8082 if ( string . Equals ( subkey . GetValue ( "DisplayName" ) ? . ToString ( ) , "BOXVR" , StringComparison . OrdinalIgnoreCase ) )
8183 {
8284 var location = subkey . GetValue ( "InstallLocation" ) ? . ToString ( ) ;
8385 if ( location != null )
8486 {
85- logger . Debug ( $ "BoxVR location found in reg key { REGISTRY_UNINSTALL_KEY } \\ { subkey_name } : { location } ") ;
87+ logger . Debug ( $ "BoxVR location found in reg key HKLM \\ { REGISTRY_UNINSTALL_KEY } \\ { subkey_name } : { location } ") ;
8688 return location ;
8789 }
8890 }
8991 }
9092 }
9193 }
9294
95+ logger . Debug ( "Searching registry for Oculus library location" ) ;
96+ using ( var key = Registry . CurrentUser . OpenSubKey ( REGISTRY_OCULUS_LIB_KEY ) )
97+ {
98+ if ( key == null )
99+ {
100+ logger . Trace ( $ "Couldn't locate Oculus registry key: { REGISTRY_OCULUS_LIB_KEY } ") ;
101+ }
102+ else
103+ {
104+ var mountPoints = new List < string > ( ) ;
105+ foreach ( var subkey_name in key . GetSubKeyNames ( ) )
106+ {
107+ using ( var subkey = key . OpenSubKey ( subkey_name ) )
108+ {
109+ logger . Trace ( $ "Checking reg key HKCU\\ { REGISTRY_OCULUS_LIB_KEY } \\ { subkey_name } ") ;
110+ var libPath = subkey . GetValue ( "Path" ) ? . ToString ( ) ;
111+ if ( libPath == null )
112+ {
113+ logger . Trace ( $ "No 'Path' value found, moving on") ;
114+ }
115+ else
116+ {
117+ logger . Trace ( $ "Path found: { libPath } , searching for 'fitxr-boxvr'") ;
118+ var volumeIdMatch = Regex . Match ( libPath , @"(\\\\\?\\Volume{.*?}\\)(.*)" ) ;
119+ if ( volumeIdMatch . Success )
120+ {
121+ logger . Trace ( $ "Getting mount points for volume { volumeIdMatch . Groups [ 1 ] . Value } ") ;
122+ try
123+ {
124+ var _mountPoints = SafeNativeMethods . GetMountPointsForVolume ( volumeIdMatch . Groups [ 1 ] . Value ) ;
125+ logger . Trace ( $ "Found the following mountpoints for { volumeIdMatch . Groups [ 1 ] . Value } :\r \n { string . Join ( "\r \n " , _mountPoints ) } ") ;
126+ mountPoints . AddRange ( _mountPoints . Select ( m => Path . Combine ( m , volumeIdMatch . Groups [ 2 ] . Value ) ) ) ;
127+ }
128+ catch ( Win32Exception ex )
129+ {
130+ logger . Error ( ex ) ;
131+ }
132+ }
133+ else
134+ {
135+ logger . Trace ( "Failed to find volume GUID path" ) ;
136+ }
137+ }
138+ }
139+ }
140+
141+ foreach ( var mountPoint in mountPoints )
142+ {
143+ var location = Path . Combine ( mountPoint , "Software" , "fitxr-boxvr" ) ;
144+ if ( File . Exists ( Path . Combine ( location , "BoxVR.exe" ) ) )
145+ {
146+ logger . Debug ( $ "BoxVR located in Oculus library: { location } ") ;
147+ return location ;
148+ }
149+ }
150+ }
151+ }
152+
93153 logger . Debug ( "Searching registry for Steam install location" ) ;
94154 var steamPath = Registry . GetValue ( REGISTRY_STEAM_KEY , "SteamPath" , null ) ? . ToString ( ) ;
95155 if ( steamPath != null )
0 commit comments