How to get Inno Setup to unzip a file it installed (all as part of the one installation process)

前端 未结 4 2022
余生分开走
余生分开走 2020-11-29 06:37

To save bandwidth/space as well as prevent accidental meddling, the installation files for a database product (call it Ajax), have been zipped up (call that file \"AJAX_Inst

相关标签:
4条回答
  • 2020-11-29 07:21

    You can use the shell Folder.CopyHere method to extract a ZIP.

    const
      SHCONTCH_NOPROGRESSBOX = 4;
      SHCONTCH_RESPONDYESTOALL = 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, SHCONTCH_NOPROGRESSBOX or SHCONTCH_RESPONDYESTOALL);
    end;
    

    Note that the flags SHCONTCH_NOPROGRESSBOX and SHCONTCH_RESPONDYESTOALL work on Windows Vista and newer.


    For an example of extracting some files only, see:
    How to get Inno Setup to unzip a single file?

    0 讨论(0)
  • 2020-11-29 07:26

    I answered a very similar question and some of the details apply.

    I would question why you need a ZIP file of the contents? I personally would place the uncompressed files into the setup. I would then have two [category] entries one for the application and one for the data. Default both the be checked.

    This would allow the users to install a fresh set of the data if needed at a later date.

    If you really want a ZIP file and want to keep it easy you could, ship both the zip files and the uncompressed files in the same setup.

    Update:

    By default files that get placed in your setup.exe are compressed.

    You can also have the files extracted to a temporary location so you can run your installation application, then have them deleted.

    [Files]
    Source: "Install1.SQL"; DestDir: "{tmp}"; Flags:deleteafterinstall;
    Source: "Install2.SQL"; DestDir: "{tmp}"; Flags:deleteafterinstall;
    
    0 讨论(0)
  • 2020-11-29 07:27

    You can use an external command line tool for unzipping your archive, see here for example. Put it in your [Files] section:

    [Files]
    Source: "UNZIP.EXE"; DestDir: "{tmp}"; Flags: deleteafterinstall
    

    Then call it in your [Run] section, like this:

    [Run]
    Filename: "{tmp}\UNZIP.EXE"; Parameters: "{tmp}\ZipFile.ZIP -d C:\TargetDir"
    

    (You'll probably want to take your target directory from a script variable, so there is some more work that needs to be done)

    0 讨论(0)
  • 2020-11-29 07:27

    You can just create silent self-extracting archive (SFX) archive, example described here how to create SFX archive for stuff you need, and write Pascal code to just run it like this (script for Inno Setup 6.0.2):

    [Tasks]
    Name: "intallSenselockDriver"; Description: "Install Senselock driver."; GroupDescription: "Install the necessary software:";
    
    [Code]
    function ExecTmpFile(FileName: String): Boolean;
    var
      ResultCode: Integer;
    begin
      if not Exec(ExpandConstant('{tmp}\' + FileName), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode)
      then
        begin
          MsgBox('Other installer failed to run!' + #13#10 + SysErrorMessage(ResultCode), mbError, MB_OK);
          Result := False;
        end
      else
        Result := True;
    end;
    
    procedure RunOtherInstallerSFX(ArchiveName: String; ExePath: String);
    begin
      ExtractTemporaryFile(ArchiveName);
      ExecTmpFile(ArchiveName);
      ExecTmpFile(ExePath);
    end;
    
    function PrepareToInstall(var NeedsRestart: Boolean): String;
    begin
      if WizardIsTaskSelected('intallSenselockDriver') then
        RunOtherInstallerSFX('1_senselock_windows_3.1.0.0.exe', '1_senselock_windows_3.1.0.0\InstWiz3.exe');
    
      Result := '';
    end;
    

    It worked perfectly for me.

    0 讨论(0)
提交回复
热议问题