@@ -259,33 +259,61 @@ private void CreateMapWindow_OnCreateNewMap(object sender, CreateNewMapEventArgs
259259
260260 private void ReadGameInstallDirectoryFromRegistry ( )
261261 {
262- try
262+ string [ ] pathsToLookup = Constants . GameRegistryInstallPath . Split ( ',' , StringSplitOptions . TrimEntries | StringSplitOptions . RemoveEmptyEntries ) ;
263+
264+ if ( pathsToLookup . Length == 0 )
263265 {
264- RegistryKey key ;
266+ Logger . Log ( $ "No valid paths specified in { nameof ( Constants . GameRegistryInstallPath ) } . Unable to read game installation path from Windows registry.") ;
267+ return ;
268+ }
265269
266- if ( Constants . InstallPathAtHKLM )
267- {
268- key = Registry . LocalMachine . OpenSubKey ( Constants . GameRegistryInstallPath ) ;
269- }
270- else
270+ try
271+ {
272+ foreach ( string registryInstallPath in pathsToLookup )
271273 {
272- key = Registry . CurrentUser . OpenSubKey ( Constants . GameRegistryInstallPath ) ;
273- }
274+ RegistryKey key ;
274275
275- object value = key . GetValue ( "InstallPath" , string . Empty ) ;
276- if ( ! ( value is string valueAsString ) )
277- {
278- tbGameDirectory . Text = string . Empty ;
279- }
280- else
281- {
282- if ( File . Exists ( valueAsString ) )
283- tbGameDirectory . Text = Path . GetDirectoryName ( valueAsString ) ;
276+ const string hklmIdentifier = "HKLM:" ;
277+
278+ // By default, try to find the key from the current user's registry.
279+ // Optionally, if the path starts with the HKLM identifier, look for the key in the local machine's registry instead.
280+ if ( registryInstallPath . StartsWith ( hklmIdentifier ) )
281+ {
282+ key = Registry . LocalMachine . OpenSubKey ( registryInstallPath . Substring ( hklmIdentifier . Length ) ) ;
283+ }
284284 else
285- tbGameDirectory . Text = valueAsString ;
286- }
285+ {
286+ key = Registry . CurrentUser . OpenSubKey ( registryInstallPath ) ;
287+ }
287288
288- key . Close ( ) ;
289+ bool isValid = false ;
290+
291+ object value = key . GetValue ( "InstallPath" , string . Empty ) ;
292+ if ( ! ( value is string valueAsString ) )
293+ {
294+ tbGameDirectory . Text = string . Empty ;
295+ }
296+ else
297+ {
298+ if ( File . Exists ( valueAsString ) )
299+ {
300+ tbGameDirectory . Text = Path . GetDirectoryName ( valueAsString ) ;
301+ }
302+ else
303+ {
304+ tbGameDirectory . Text = valueAsString ;
305+ }
306+
307+ if ( File . Exists ( Path . Combine ( tbGameDirectory . Text , Constants . ExpectedClientExecutableName ) ) )
308+ isValid = true ;
309+ }
310+
311+ key . Close ( ) ;
312+
313+ // Break when we find the first valid installation path
314+ if ( isValid )
315+ break ;
316+ }
289317 }
290318 catch ( Exception ex )
291319 {
0 commit comments