在欢迎页面上显示长时间运行操作的进度

时间:2015-09-11 03:00:12

标签: inno-setup

我想在安装过程中检查我的应用程序的更新,同时在Inno Setup的表单上显示该过程。

基本上就是这样:

WizardForm.WelcomeLabel2.Caption := 'Checking for update ...';
DownloadFile(VersionURL, LatestVersion)
WizardForm.WelcomeLabel2.Caption := 'New version available.';

下面是一个工作代码,除了在调用CurPageChanged时,表单尚未就绪。在完成新版本的检查之前,它没有正确显示。查看截图。使用调试器逐步执行代码时,它工作正常。

我错过了什么?任何解决方法?
主要目标是避免在没有任何反馈的情况下等待版本检查过程,因为它感觉不负责任。

两张照片。

  • 我得到了什么:

    enter image description here

  • 需要什么

    enter image description here

#if defined UNICODE
  ; signed 64bit integer, but using only positive numbers, 0 .. 9223372036854775807
  ; examples of version string:
  ; 0..255 . 0..255 . 0..255 . 0..255 . 0..255 . 0..255 . 0..255 . 0..127
  ; 0..65535 . 0..65535 . 0..65535 . 0..32767
  #define Int64_OR_LongWord "Int64"
#else
  ; LongWord, 0 .. 4294967295
  ; 0..255 . 0..255 . 0..255 . 0..255
  ; 0..65535 . 0..65535
  #define Int64_OR_LongWord "LongWord"
#endif

[Setup]
AppName=Check Version
AppVersion=1.2.3
DefaultDirName={pf}\My Program

[Code]
const
  SetupURL = 'http://hu.hu/huhu.exe';
  VersionURL = 'http://hu.hu/version.txt';
  sizeNumOfSubsets=4;
  sizeSubset=256;

function VerStrToNum(const strVersion: String): {#Int64_OR_LongWord};
var strVersionRemaining: String;
    tmpIntSubset: Integer;
    i: Byte;
begin
  // add period at the end, so that any valid number should end with a period
  // empty strVersionRemaining means all numbers are read and the rest are zeroes
  // v1.2.3 = v1.2.3.0.0
  strVersionRemaining := AddPeriod(strVersion);
  for i := 1 to sizeNumOfSubsets do begin
    if strVersionRemaining <> '' then begin
      tmpIntSubset := StrToIntDef(Copy(strVersionRemaining,1, Pos('.',strVersionRemaining)-1), -1);
      strVersionRemaining := Copy(strVersionRemaining,Pos('.',strVersionRemaining)+1,Length(strVersionRemaining));
    end
    else tmpIntSubset := 0;   
    if tmpIntSubset <> -1 then begin
      Result := Result * sizeSubset + tmpIntSubset;
    end                                                
    else begin
      // if version string format invalid, just return 0,
      // error would just confuse user. RaiseException('Invalid format of version string');
      Result := 0;
      Exit;
    end;
  end;
end;

function DownloadFile(const URL: string; var Response: string): Boolean;
var
  WinHttpRequest: Variant;
begin
  Result := True;
  try
    WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1');
    WinHttpRequest.Open('GET', URL, False);
    WinHttpRequest.Send;
    Response := WinHttpRequest.ResponseText;
  except
    Result := False;
    Response := GetExceptionMessage;
  end;
end;


// --- to show correct text when comming back to Welcome Page by pressing PREV button
var oldWelcomeCaption: String;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpWelcome then begin
    WizardForm.WelcomeLabel2.Caption := oldWelcomeCaption;
  end;
  Result := true
end;

var PanelDownloadButton: TPanel;

procedure CurPageChanged(CurPageID: Integer);
var LatestVersion: string;
begin
  case CurPageID of
    wpWelcome: begin
      // the Welcome Page was still hidden at this point
      WizardForm.Visible := True;
      // THIS IS WHAT I WAS MISSING:
      WizardForm.Repaint;
      oldWelcomeCaption := WizardForm.WelcomeLabel2.Caption;
      WizardForm.WelcomeLabel2.Caption := oldWelcomeCaption + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + 'Checking for update ...';
      if DownloadFile(VersionURL, LatestVersion) then begin
        if VerStrToNum(LatestVersion) > VerStrToNum('{#SetupSetting('AppVersion')}') then begin
          WizardForm.WelcomeLabel2.Caption := oldWelcomeCaption + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + 'New version available.';
          // PanelDownloadButton.Visible := True;
          // xxx Run downloaded setup, exit this one
        end
        else WizardForm.WelcomeLabel2.Caption := oldWelcomeCaption + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + #13 + #10 + 'No new versions.';
      end
      else WizardForm.WelcomeLabel2.Caption := WizardForm.WelcomeLabel2.Caption + #13 + #10 + Copy(LatestVersion,Pos(':',LatestVersion)+2,Length(LatestVersion));
    end;
  end;
end;

编辑:以上代码现已修复,以防有人想要使用版本检查。
我稍后会添加一个带有按钮和下载功能的最终代码链接。

1 个答案:

答案 0 :(得分:1)

调用WizardForm.Repaint强制表单完全绘制:

WizardForm.Visible := True;
WizardForm.Repaint;

请参阅http://docwiki.embarcadero.com/Libraries/en/Vcl.Controls.TControl.Repaint

  

强制控件在屏幕上重绘其图像。

     

调用Repaint强制控件立即重绘其图像。