在Inno Setup安装程序中更改安装类型,具体取决于它是否为新安装或更新?

时间:2016-04-26 16:34:08

标签: inno-setup

我使用Inno Setup创建了一个安装程序来安装数据库。我的剧本写作技巧非常基础。现在我需要提供更新,并需要安装程序:

  1. 检查是否有现有安装;
  2. 检查现有安装是否较旧;
  3. 如果存在现有安装,则提供Update作为选项,或者如果没有,则提供Admin或General数据库(新安装)。
  4. 我将下面的代码拼凑在一起,显示了下拉列表/组合框中的三个选项。我无法弄清楚如何在wpSelectComponents页面上更改组合框中提供的选项。

    [Code]
    function InitializeSetup(): Boolean;
    var
        OldVersion, NewVersion: String;
    begin
        Result := True;
    
        //Check in the registry for the uninstaller of PME Database. Compare version, exit if installed version is the same or newer.
        if RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1') then
        begin
            RegQueryStringValue(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1', 'DisplayVersion', OldVersion)
            NewVersion := '{#MyAppVersion}'
            If NewVersion < OldVersion then
            begin
                MsgBox(('This version (' + NewVersion + ') is older than the installed version (' + OldVersion +') - setup will close.'), mbError, MB_Ok)
                Result := False;
                exit;
            end;
            If NewVersion = OldVersion then
            begin
                MsgBox(('This version (' + NewVersion + ') is the same as the installed version - setup will close.'), mbError, MB_Ok)
                Result := False;
                exit;
            end;
            If NewVersion > OldVersion then
            begin
                if MsgBox(('The database will be updated from version ' + OldVersion + ' to version ' + NewVersion + '.' + chr(13) + chr(13) + 'Continue?'), mbInformation, MB_YesNo) = idNo then
                begin
                    Result := False;
                    exit;
                end;
            end;
        end;
    ...more code, to check Windows / Office versions...
    
    [Code]
    Procedure CurPageChanged(CurPage: Integer);
    begin
      if CurPage = wpSelectComponents then 
      begin
          if RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1') then
          begin
    //Do something: only show Update as combobox option - HOW???
          end else begin
    //Do something: only show Admin and General as combobox options - HOW???
          end;
      end;
    end;
    
    [Types]
    Name: "Other1"; Description: "General Database"; Languages: en
    Name: "Admin1"; Description: "Administrator Database"; Languages: en
    Name: "Update1"; Description: "Database update"; Languages: en
    Name: "Other2"; Description: "Base de Données Générale"; Languages: fr
    Name: "Admin2"; Description: "Base de Données de L'administrateur"; Languages: fr
    Name: "Update2"; Description: "Mise à jour de Base de Données"; Languages: fr
    Name: "Other3"; Description: "Base de Dados Geral"; Languages: pt
    Name: "Admin3"; Description: "Base de Dados do Administrador"; Languages: pt
    Name: "Update3"; Description: "Atualização da Base de Dados"; Languages: pt
    
    [Components]
    Name: "General"; Description: "General"; Types: other1 other2 other3; Flags: fixed disablenouninstallwarning
    Name: "Admin"; Description: "Admin"; Types: admin1 admin2 admin3; Flags: fixed disablenouninstallwarning
    Name: "Update"; Description: "Update"; Types: update1 update2 update3; Flags: fixed disablenouninstallwarning
    
    [Files]
    ; Database files.
    Source: "C:\PME SETUP\pme versions\v2.02\PME Database.accde"; DestDir: "{app}"; Components: admin general update
    ; Data files are ONLY copied for a new installation of the central administrator database.
    Source: "C:\PME SETUP\pme versions\v2.02\PME Data Storage.accdb"; DestDir: "{app}"; Components: admin
    Source: "C:\PME SETUP\pme versions\v2.02\PME Data Storage.accdb"; DestDir: "{app}\System Files"; Components: admin
    Source: "C:\PME SETUP\pme versions\v2.02\PME Data Storage.accdb"; DestDir: "{app}\Exchange"; Components: admin 
    ...more follows for different component-combinations...
    

1 个答案:

答案 0 :(得分:0)

您正在寻找Check parameter

[Types]
Name: "Other"; Description: "General Database"; Check: not IsUpdate
Name: "Admin"; Description: "Administrator Database"; Check: not IsUpdate
Name: "Update"; Description: "Database update"; Check: IsUpdate

[Code]

function IsUpdate: Boolean;
begin
  Result :=
    RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1') and
    /*IsNewer*/;
end;

请注意,您也应该检查HKEY_LOCAL_MACHINE以确定是否已安装该应用程序。

相关问题