Inno setup command line progress

How can I get progress when I'm executing inno script from a command line compiler (iscc.exe)?

I can pipeline the output but I want to get % completed as well.

Answers


Use ISCmplr library instead. For an inspiration, a very basic Delphi InnoSetup compiler might look like this (of course without hardcoded paths). It uses the original CompInt.pas unit from InnoSetup source pack:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, ComCtrls, CompInt;

const
  CompLib = ISCmplrDLL;
  CompPath = 'c:\Program Files (x86)\Inno Setup 5\';
  CompScriptProc = {$IFNDEF UNICODE}'ISDllCompileScript'{$ELSE}'ISDllCompileScriptW'{$ENDIF};

type
  TCompScriptProc = function(const Params: TCompileScriptParamsEx): Integer; stdcall;

  PAppData = ^TAppData;
  TAppData = record
    Lines: TStringList;
    LineNumber: Integer;
    StatusLabel: TLabel;
    ProgressBar: TProgressBar;
  end;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    ProgressBar1: TProgressBar;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FCompLibHandle: HMODULE;
    FCompScriptProc: TCompScriptProc;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FCompLibHandle := SafeLoadLibrary(CompPath + CompLib);
  if FCompLibHandle <> 0 then
    FCompScriptProc := GetProcAddress(FCompLibHandle, CompScriptProc);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if FCompLibHandle <> 0 then
    FreeLibrary(FCompLibHandle);
end;

function CompilerCallbackProc(Code: Integer; var Data: TCompilerCallbackData;
  AppData: Longint): Integer; stdcall;
begin
// in every stage you can cancel the compilation if you pass e.g. a Boolean
// field through the AppData by using the following line:
// Result := iscrRequestAbort;

  Result := iscrSuccess;
  case Code of
    iscbReadScript:
    with PAppData(AppData)^ do
    begin
      if Data.Reset then
        LineNumber := 0;
      if LineNumber < Lines.Count then
      begin
        Data.LineRead := PChar(Lines[LineNumber]);
        Inc(LineNumber);
      end;
    end;
    iscbNotifyStatus:
      Form1.Label1.Caption := Data.StatusMsg;
    iscbNotifyIdle:
    begin
      with PAppData(AppData)^ do
      begin
        ProgressBar.Max := Data.CompressProgressMax;
        ProgressBar.Position := Data.CompressProgress;
        StatusLabel.Caption := Format('Bitrate: %d B/s; Remaining time: %d s',
          [Data.BytesCompressedPerSecond, Data.SecondsRemaining]);
        Application.ProcessMessages;
      end;
    end;
    iscbNotifySuccess:
      ShowMessageFmt('Yipee! Compilation succeeded; Output: %s', [Data.OutputExeFilename]);
    iscbNotifyError:
      ShowMessageFmt('An error occured! File: %s; Line: %d; Message: %s', [Data.ErrorFilename,
        Data.ErrorLine, Data.ErrorMsg]);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  CustData: TAppData;
  CompParams: TCompileScriptParamsEx;
begin
  if Assigned(FCompScriptProc) then
  begin
    CustData.Lines := TStringList.Create;
    try
      CustData.Lines.LoadFromFile('c:\Program Files (x86)\Inno Setup 5\Examples\Example1.iss');
      CustData.LineNumber := 0;
      CustData.StatusLabel := Label1;
      CustData.ProgressBar := ProgressBar1;

      CompParams.Size := SizeOf(CompParams);
      CompParams.CompilerPath := CompPath;                                                  // path to the folder containing *.e32 files (InnoSetup install folder)
      CompParams.SourcePath := 'c:\Program Files (x86)\Inno Setup 5\Examples\';             // path to the script file to be compiled
      CompParams.CallbackProc := CompilerCallbackProc;                                      // callback procedure which the compiler calls to read the script and for status notifications
      Pointer(CompParams.AppData) := @CustData;                                             // custom data passed to the callback procedure
      CompParams.Options := '';                                                             // additional options; see CompInt.pas for description

      if FCompScriptProc(CompParams) <> isceNoError then
        ShowMessage('Compiler Error');
    finally
      CustData.Lines.Free;
    end;
  end;
end;

end.

Need Your Help

Integrating ASP.NET Identity to existing database

c# asp.net asp.net-mvc entity-framework asp.net-identity

I'm new to all this Entity Framework stuff, so excuse me in advance.

Twitpic not working, Posterous is… why?

iphone api twitpic yfrog posterous

I was using the Twitpic API from in my iPhone app for a while with no problem, then suddenly it started reporting: invalid username or password.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.