scriptkitties.com

Random Programming Projects in C, Delphi, Lazarus and TCL

How to get Inno Setup to unzip a file it installed.

There is no need to use an external dll with Inno Setup to extract a ZIP file to a given directory.  Just add this to your ISS file below the code section.

[Code]

procedure unzip(ZipFile, TargetFldr: PAnsiChar);
var
  shellobj: variant;
  ZipFileV, TargetFldrV: variant;
  SrcFldr, DestFldr: variant;
  shellfldritems: variant;
begin
  if FileExists(ZipFile) then begin
    ForceDirectories(TargetFldr);
    shellobj := CreateOleObject('Shell.Application');
    ZipFileV := string(ZipFile);
    TargetFldrV := string(TargetFldr);
    SrcFldr := shellobj.NameSpace(ZipFileV);
    DestFldr := shellobj.NameSpace(TargetFldrV);
    shellfldritems := SrcFldr.Items;
    DestFldr.CopyHere(shellfldritems, SHCONTCH_NOPROGRESSBOX or SHCONTCH_RESPONDYESTOALL);  
  end;
end;

procedure ExtractSomething(src, target : AnsiString);
begin
  unzip(ExpandConstant(src), ExpandConstant(target));
end;