如何让Inno Setup解压缩单个文件?

时间:2017-06-05 22:13:19

标签: winapi zip inno-setup pascalscript

有没有办法从zip解压缩一个文件? 我正在使用基于response How to get Inno Setup to unzip a file it installed (all as part of the one installation process)代码,非常适合解压缩,但不知道如何解压缩单个文件:

[Code]:

const
  NO_PROGRESS_BOX = 4;
  RESPOND_YES_TO_ALL = 16;

procedure UnZip(ZipPath, TargetPath: string); 
var
  Shell: Variant;
  ZipFile: Variant;
  TargetFolder: Variant;
begin
  Shell := CreateOleObject('Shell.Application');

  ZipFile := Shell.NameSpace(ZipPath);
  if VarIsClear(ZipFile) then
    RaiseException(Format('ZIP file "%s" does not exist or cannot be opened', [ZipPath]));

  TargetFolder := Shell.NameSpace(TargetPath);
  if VarIsClear(TargetFolder) then
    RaiseException(Format('Target path "%s" does not exist', [TargetPath]));

  TargetFolder.CopyHere(ZipFile.Items, NO_PROGRESS_BOX or RESPOND_YES_TO_ALL);
end;

2 个答案:

答案 0 :(得分:2)

使用Folder.ParseName检索对ZIP存档"文件夹"中特定文件的引用。然后将该引用传递给Folder.CopyHere以提取它。

const
  NO_PROGRESS_BOX = 4;
  RESPOND_YES_TO_ALL = 16;

procedure UnZip(ZipPath, FileName, TargetPath: string); 
var
  Shell: Variant;
  ZipFile: Variant;
  Item: Variant;
  TargetFolder: Variant;
begin
  Shell := CreateOleObject('Shell.Application');

  ZipFile := Shell.NameSpace(ZipPath);
  if VarIsClear(ZipFile) then
    RaiseException(Format('ZIP file "%s" does not exist or cannot be opened', [ZipPath]));

  Item := ZipFile.ParseName(FileName);
  if VarIsClear(Item) then
    RaiseException(Format('ZIP file "%s" does not contain file "%s"', [ZipPath, FileName]));

  TargetFolder := Shell.NameSpace(TargetPath);
  if VarIsClear(TargetFolder) then
    RaiseException(Format('Target path "%s" does not exist', [TargetPath]));

  TargetFolder.CopyHere(Item, NO_PROGRESS_BOX or RESPOND_YES_TO_ALL);
end;

答案 1 :(得分:1)

我发现了一种有效的方式,而不是我所期望的但功能正常。

UnZip(AppFolder+'\modulos\seimpresoras-2.2.zip', tmpFolder); 
FileCopy(tmpFolder+'\seimpresoras\resources\default.properties', AppFolder+'\printers.properties', False);