2017-06-05 19 views
1

有沒有辦法從zip壓縮一個文件? 我使用基於response How to get Inno Setup to unzip a file it installed (all as part of the one installation process)代碼,可以完美的解壓,但沒有一個知道這是怎麼可以解壓縮單個文件:如何讓Inno Setup解壓縮單個文件?

[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; 

回答

1

使用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; 
+0

謝謝,作品完美。 –

1

我找到了一種方法,工程,不是我預期但功能。

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