5

我想将文件安装在不同的文件夹中,具体取决于用户是选择为所有用户安装还是只为当前用户安装。

我添加了使用 CreateInputOptionPage() 来创建一个带有两个单选按钮的选项页面。

但是,我的安装程序现在到处都是重复的行,比如这两行:

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

有没有更优雅的方式来完成上述操作?例如,Pascal 代码可以创建一个像 #define 这样的变量,以便我可以使用它来代替上面的 {userdocs} 和 {commondocs} 吗?

更多细节:

上面的 IsAllUsers() 函数调用此代码:

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

和:

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; 
4

1 回答 1

8

会有这样的西装吗?

[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;
于 2012-06-08T00:33:33.397 回答