Inno Setup - setting defaultdir using a lookup registry entry?

I recently started using Inno Setup to try to create a simple .exe installer to modify the game.

I have an installer that works fine for the most part, but it is a bit basic at the moment. What I really would like to do to the installer is to automatically find the game installation directory in which the mod is designed for (Dawn of War - Dark Crusade), so the user does not need to view it manually.

I read that the Inno installer can install DefaultDir according to the registry entry. However, while the game β€œtarget” creates a registry entry containing its installation directory, the game can be purchased either digitally (via Steam) or physically, and it creates various registry entries depending on the format in which it is bought it. My mod works with either format, but I do not know how to install DefaultDir if there is more than one possible registry key format.

Is there any "wilcard" function that will return the game installation directory from its registry entry without my entering the exact full value of the registry key (i.e. any kind of registry)? Or to search for two possible values ​​that he could have, and then default to {src} if he doesn't find any?

+4
source share
2 answers

You can assign a value to DefaultDirName via [Code] . For example, the following pseudo-script shows how to request two string values ​​in the registry and return the first one found in the DefaultDirName directive. If none of the requested registry values ​​are found, a constant default value is returned:

 [Setup] AppName=My Program AppVersion=1.5 DefaultDirName={code:GetDirName} [Code] function GetDirName(Value: string): string; var InstallPath: string; begin // initialize default path, which will be returned when the following registry // key queries fail due to missing keys or for some different reason Result := '{pf}\Default Dir Name'; // query the first registry value; if this succeeds, return the obtained value if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'First Key', InstallPath) then Result := InstallPath // otherwise the first registry key query failed, so... else // query the second registry value; if it succeeds, return the obtained value if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'Second Key', InstallPath) then Result := InstallPath; end; 
+4
source

In addition to using [Code] , as indicated elsewhere, you can also nest registry constants:

 DefaultDirName={reg:HKLM,Software\Vendor1\Application,InstallPath|{reg:HKLM,Software\Vendor2\Application,InstallPath|{pf}\DefaultInstallPath}} 

This will use the path Vendor1, if it exists; otherwise, he will try the Vendor2 path, and only if he cannot find any of them will he return to some default value.

+4
source

All Articles