Install DestDir from Inno Pascal?

I want to install files in different folders, depending on whether the user is selected for installation for all users or only for the current user.

I added the used CreateInputOptionPage () to create the page with two radio buttons.

However, my installer is now littered with a lot of duplicate lines, such as these two:

Source: {#ProjectRootFolder}\License.txt; DestDir: {userdocs}\{#MyAppName}; Check: NOT IsAllUsers
Source: {#ProjectRootFolder}\License.txt; DestDir: {commondocs}\{#MyAppName}; Check:IsAllUsers

Is there a more elegant way to do this? Can Pascal code create a variable like #define so that I can use it instead of {userdocs} and {commondocs} above?

Additional Information:

The IsAllUsers () function above calls this code:

function IsAllUsers: Boolean;
begin
#ifdef UPDATE
  Result := AllUsersInRegistryIsTRUE;
#else
  Result := AllUsersOrCurrentUserPage.Values[1]; // wizard page second radio button
#endif
end; 

and

function AllUsersInRegistryIsTRUE: Boolean;  // True if preceding install was to all users' documents 
var
  AllUsersRegValue: AnsiString;
begin
  if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\MyApp', 'AllUsers', AllUsersRegValue) then
    Result := (UpperCase(AllUsersRegValue) = 'YES')
  else
    Result := FALSE;
end; 
+5
source share
1 answer

Will there be something like this costume?

[Files]
Source: {#ProjectRootFolder}\License.txt; DestDir: {code:GetDir}\{#MyAppName};

...

[Code]
var
  OptionsPage: TInputOptionWizardPage;

procedure InitializeWizard;
begin
  OptionsPage := CreateInputOptionPage(wpUserInfo, 
              'please select', 'the kind of installation', 'and continue..', 
              True, False);
  OptionsPage.Add('All users');
  OptionsPage.Values[0] := True;
  OptionsPage.Add('This user');
end;

function GetDir(Dummy: string): string;
begin
  if OptionsPage.Values[0] then
    Result := ExpandConstant('{commondocs}')
  else
    Result := ExpandConstant('{userdocs}');
end;
+6
source

All Articles