如何从TOutPutProgressWizardPage,Inno Setup退出安装:

时间:2011-01-17 20:38:23

标签: inno-setup pascal

我一直有这个问题。直到这篇文章,我才真正在网上寻求帮助。

我使用Inno Setup编写了一个安装程序。它安装了许多东西,其中一个是Java Development Kit的当前版本。我的问题是我需要检查JDK安装是否存在。如果没有,请退出安装。如果不是因为我使用TOutPutProgressWiazrdPage来向用户说明这个过程,这似乎很容易。一切都很好,直到“中止”或“退出”。点击其中任何一个之后,安装就会变得混乱。请,任何帮助将不胜感激。我的示例代码如下:

//JDK Install
procedure InstallJDK();
var
  ErrorCode, x: Integer;
  Return,Path: String;
  Paths: TArrayOfString;
begin
    if (IsComponentSelectedLog('Prerequisites\JDK')) then
    begin
    GetJavaVersion();
    Path := GetEnv('path'); //(TNG-1463) 
        if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_LESS_THAN) and (Installed_Java_Version <> '') then
        begin
            if (Pos(Lowercase(JDK_ORACLE_DIR + '\jdk1.6.0_18'), Lowercase(Path)) <> 0) or (Pos(Lowercase(JDK_SUN_DIR + '\jdk1.6.0_18'), Lowercase(Path)) <> 0) or (Pos(Lowercase(JDK_ORACLE_DIR + '\jdk1.6.0_22'), Lowercase(Path)) <> 0)then
            begin
                SetFormText('Removing JDK Version: ' + Installed_Java_Version + '...', 'Preparing System...', JavaInstallationPage);
                //Remove Java Update 1.6.0_18
                ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{26A24AE4-039D-4CA4-87B4-2F83216018FF} /L ' + TNG_Install_Log_Dir + '\ju_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
                UpdateProgressBar(PBarJavaInstall, 76);
                //Remove JDK 1.6.0_18
                ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{32A3A4F4-B792-11D6-A78A-00B0D0160180} /L ' + TNG_Install_Log_Dir + '\jdk_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
                UpdateProgressBar(PBarJavaInstall, 80);
                //Remove Java Update 1.6.0_22
                ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{26A24AE4-039D-4CA4-87B4-2F83216022FF} /L ' + TNG_Install_Log_Dir + '\ju_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
                UpdateProgressBar(PBarJavaInstall, 76);
                //Remove JDK 1.6.0_22
                ShellExecLog('open', ExpandConstant('cmd'),ExpandConstant('/C "start /w MsiExec /qn /X {{32A3A4F4-B792-11D6-A78A-00B0D0160220} /L ' + TNG_Install_Log_Dir + '\jdk_' + Installed_Java_Version + '_uninstall.log"'), ExpandConstant('{sys}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode);
                UpdateProgressBar(PBarJavaInstall, 80);
                //Remove JDK 1.6.0_18 Directories
                if DirExists(JDK_SUN_DIR + '\jdk1.6.0_18') then
        begin
          DelTree(JDK_SUN_DIR + '\jdk1.6.0_18', True, True, True);
        end;
                if DirExists(JDK_ORACLE_DIR + '\jdk1.6.0_18') then
        begin
          DelTree(JDK_ORACLE_DIR + '\jdk1.6.0_18', True, True, True);
        end;
                //Remove JDK 1.6.0_22 Directories
                if DirExists(JDK_ORACLE_DIR + '\jdk1.6.0_22') then
        begin
          DelTree(JDK_ORACLE_DIR + '\jdk1.6.0_22', True, True, True);
        end;
                //Clean Up Path
                if (Pos(Lowercase(JDK_ORACLE_DIR), Lowercase(Path)) <> 0) or (Pos(Lowercase(JDK_SUN_DIR), Lowercase(Path)) <> 0) then
                begin
                    Paths := Split(Path,';',0);
                    Path := '';
                    for x := 0 to GetArrayLength(Paths)-1 do
                    begin
                    if (Pos(Lowercase(JDK_ORACLE_DIR), Lowercase(Paths[x])) <> 0) or (Pos(Lowercase(JDK_SUN_DIR), Lowercase(Paths[x])) <> 0) then
                    begin
                      Paths[x] := '';
                    end;
                end;
                for x := 0 to GetArrayLength(Paths)-1 do
                begin
                    if Paths[x] <> '' then
                    begin
                        if path = '' then
                        begin
                            Path := Paths[x];
                        end
                        else
                            Path := Path + ';' + Paths[x];
                        end;
                    end;
                end;
                SetxEnv('path', ExpandConstant(Path));
                UpdateProgressBar(PBarPostInstall1, 100);
            end;
            GetJavaVersion();
        end;    

        if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_LESS_THAN) then
        begin
            //Install JDK
            Log('In Progress......Executing jdk-6u23-windows-i586.exe');
            UpdateProgressBar(PBarJavaInstall, 10);
            if (CheckSupportExist('jdk-6u23-windows-i586.exe')) then
      begin
        Create_Dir(ExpandConstant('{sd}\apps'), JavaInstallationPage);
        Create_Dir(JDK_ORACLE_DIR, JavaInstallationPage);
        Create_Dir(ExpandConstant('{sd}\TNG2.0'), JavaInstallationPage);
        Create_Dir(ExpandConstant('{sd}\TNG2.0\install'), JavaInstallationPage);
        SetFormText('Installing JDK Version: ' + JDK_MIN_VERSION + '...', 'Preparing System...', JavaInstallationPage);
        ShellExecLog('open', 'jdk-6u23-windows-i586.exe',  '/s /v /qn" ADDLOCAL=ALL REBOOT=SUPPRESS INSTALLDIR=' + JDK_Dir + ' /L ' + TNG_Install_Log_Dir + '\jdk_' + JDK_MIN_VERSION + '_install.log"', ExpandConstant('{src}\Support\'), SW_HIDE, ewNoWait, ErrorCode);
        UpdateProgressBarUntilProgressHasEnded('jdk-6u23-windows-i586.exe', 100, 2, JavaInstallationPage, PBarJavaInstall);

        GetJavaVersion();

        if (not (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL)) then
        begin
          Log('Failed......' + JDK + ' ' + JDK_MIN_VERSION + ' Installation : Versions do not match.');
          LogError('Failed......' + JDK + ' ' + JDK_MIN_VERSION + ' Installation');
          ExitSetup := True;
        end
        else if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL) then
        begin
          Log('Success......' + JDK + ' ' + Installed_Java_Version + ' Installed');
          if GetEnv('JAVA_HOME') <> JDK_Dir then
          begin
            ErrorCode := SetxEnv('JAVA_HOME', ExpandConstant(JDK_Dir));
          end;
          //(TNG-1463) Prepend the %Java_Home%\bin so that it is the first JDK in the system's path
          SetxEnv('path', ExpandConstant(JDK_Bin_DIR + ';' +  Path));
        end;
      end
      else
      begin
        MsgBox('Please re-run the install after the jdk-6u23-windows-i586.exe support install is placed in the support folder.', mbInformation, MB_OK);
              Log('User chose not to install the ' + JDK + ' ' + JDK_MIN_VERSION);
        ExitSetup := True;
      end;
        end
        else if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL) then
        begin
            Log('Already Installed......' + JDK + ' ' + JDK_MIN_VERSION);      
        end
        else
        begin
            LogError('Failed......' + JDK + ' Installation');
      ExitSetup := True; 
        end;
  end;
end;
//Activate Setup Page
//
procedure JavaInstallationPage_Activate(Page: TWizardPage);
var
  ErrorCode: Integer;
begin
//Install JDK
    InstallJDK()
  if (ExitSetup = True)  then
  begin
        try
        finally
            JavaInstallationPage.Hide;
        end;
    **Abort**;
  end;
end;

procedure InitializeWizard();
begin
  // Installation Page
  JavaInstallationPage := CreateOutputProgressPage('JDK Installation', 'Setup is preparing the system.....');
    //JavaInstallationPage := CreateCustomPage(wpSQL_No_SQL_SelectSqlServer, 'POS Manufacturer Settings', 'Please select a supported manufacturer or select default');  
  lblJavaInstallDescription1 := TLabel.Create(JavaInstallationPage);
    with lblJavaInstallDescription1 do
    begin
    Top := 1;
    Caption := '';
    AutoSize := True;
    Parent := JavaInstallationPage.Surface;
  end;
    lblJavaInstallDescription2 := TLabel.Create(PreInstallationPage);
    with lblJavaInstallDescription2 do
    begin
    Top := lblJavaInstallDescription1.Top + lblJavaInstallDescription1.Height + 5;
    Caption := 'Installing Java Development Kit...';
    AutoSize := True;
    Parent := JavaInstallationPage.Surface;
  end;
    PBarJavaInstall := TNewProgressBar.Create(JavaInstallationPage);
    with PBarJavaInstall do
    begin
    Parent := JavaInstallationPage.Surface;
    Width := JavaInstallationPage.SurfaceWidth;
    Top := lblJavaInstallDescription2.Top + lblJavaInstallDescription2.Height + 3;
    Height := 19;
    Max := 105;
  end;





  JavaInstallationPage.OnActivate := @JavaInstallationPage_Activate;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
    ErrorCode: Integer;
    DisplayJavaInstallPage: boolean;
    FileName: string;
    FileLines: TArrayOfString;

begin     
    if CurPageID = wpTomCatPortSettings then
    begin
        DisplayJavaInstallPage := True;
    end;
    if DisplayJavaInstallPage then
    begin    
        GetJavaVersion();
        if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) <> VERSION_EQUAL) then
        begin
            JavaInstallationPage.Show;
            try
            finally
                JavaInstallationPage.Hide;
            end;

            if (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) <> VERSION_EQUAL) then
            begin
                **Abort**;          
            end;
        end;
    end;            

    if (not LocalesPopulated) and (CompareVersion(Installed_Java_Version, JDK_MIN_VERSION) = VERSION_EQUAL) and (PageCount >= 4) and isComponentSelected('XPressPOS\MWB\Locale') then 
    begin
        // Configure MWB_Localization Settings Page  
        FileName := ExpandConstant('{tmp}\GetAllAvailableLocalesbyLocale.class');
        ExtractTemporaryFile(ExtractFileName(FileName));
        FileName := ExpandConstant('{tmp}\GetLocaleDisplayName.class');
        ExtractTemporaryFile(ExtractFileName(FileName));
        FileName := ExpandConstant('{tmp}\GetLocaleByDescription.class');
        ExtractTemporaryFile(ExtractFileName(FileName));    

        if SelectedLangauge <> 'es' then
        begin
      #if Debug == "True"
      ShellExecLog('open', 'cmd', ExpandConstant('/K  "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale en US > .\Localizations.txt"'), '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
          #else
            ShellExecLog('open', 'cmd', ExpandConstant('/C  "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale en US > .\Localizations.txt"'), '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
            #endif
        end
        else
        begin
      #if Debug == "True"
      ShellExecLog('open', 'cmd', ExpandConstant('/K  "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale en MX > .\Localizations.txt"'), '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
          #else
            ShellExecLog('open', 'cmd', ExpandConstant('/C  "{sd}&&cd {tmp}\&&java GetAllAvailableLocalesbyLocale es MX > .\Localizations.txt"'), '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
            #endif
        end;

        lstLocalizations.Items.clear;
        chkDisplayUnsupported.Checked := False;
        if LoadStringsFromFile(ExpandConstant('{tmp}\Localizations.txt'), FileLines) then
        begin
            for I := 0 to GetArrayLength(FileLines)-1 do
            begin
                if ((FileLines[I] = 'English (United States)') or (FileLines[I] = 'Spanish (Mexico)')) then
                begin
                    lstLocalizations.Items.Add(FileLines[I]);
                end;
            end;
        end;
    LocalesPopulated := True;
    end;  
    Result := True;     
end;

function BackButtonClick(CurPageID: Integer): Boolean;
begin
  PageCount := PageCount - 1;
  Result := True;
end;

1 个答案:

答案 0 :(得分:0)

我通过在InializeSetup例程中放置任何可能需要中止的检查来修复此问题。中止在那里工作正常。当我尝试在其他地方中止时,脚本无法正确退出并生成不可预测的异常。特别是当从内部调用abort尝试finalize时。