skr
skr

Reputation: 1811

inno setup to browse and extract zip file at sepcific location

I want to enable users to browse and extract zip files at a specific location.

Requirements/steps:

  1. Display welcome page
  2. Next display browse button to select installation directory(DisableDirPage=no)
  3. Next display browse button to select zip file(JDK)
  4. Extract JDK zip file selected in step 3 at location selected in step 2, that means JDK should be extracted in installation directory that user selects in step 2

Problems with my code:

  1. After the first step my code directly jump into 3rd step and then it goes to 2nd.
  2. The code to extract zip is not working if I pass method name as the parameter. If I pass the hardcoded value of the location it works. I don't know pascal and it basically seems to be a syntax related issue.

[SETUP]

AppName=My Program
        AppVersion=1.5
        DefaultDirName={pf}\My Program
        DefaultGroupName=My Program
        UninstallDisplayIcon={app}\MyProg.exe
        DisableProgramGroupPage=no
        DisableWelcomePage=no
        DisableDirPage=no
        Compression=lzma2
        SolidCompression=yes
        OutputDir=userdocs:Inno Setup Examples Output

[Files]

Source: "{code:GetLicensePath}"; DestDir: "{app}"; Flags: external
Source: "7za.exe"; DestDir: "D:\authorized\Builds\Solo\"; Flags: deleteafterinstall;

[Icons]

Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"

[Run]

Filename: D:\authorized\Builds\Solo\7za.exe; Parameters: "x ""{{Code:GetZipPath}}"" -o""{app}\"" * -r -aoa"; Flags: runhidden runascurrentuser;

[Code]

 var
   Page: TInputFileWizardPage;
   DataDir:String;

 procedure InitializeWizard();
 begin
   Page :=
     CreateInputFilePage(
       wpWelcome,
       'Select Zip File Location',
       'Where is your Zip file located?',
       'Select where Zip file is located, then click Next.');

   Page.Add(
     'Location of Zip file:',         
     '*.7z|*.rar|All files|*.*', 
     '.zip');  

 // Set initial value (optional)
 Page.Values[0] := ExpandConstant('{%USERPROFILE}\Downloads\setup.7z'); 
     ;                   
 end;



 function GetZipPath(Param: string): string;
 begin
   DataDir := Page.Values[0];

 end;

Could you help me, please?

Upvotes: 1

Views: 1075

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202594

  1. The order of your custom page is determined by the first argument of the Create* function. So change wpWelcome to wpSelectDir.

  2. Why double {{...}} - That’s likely the problem. Also code: should be lowercase.

  3. Your scripted constant function does not really return anything. It should be:

     Result := Page.Values[0];
    

Upvotes: 2

Related Questions