Install two files into a user selected directory

43 Views Asked by At

I want to install two files into a installation directory. The directory shall be selected by the user during installation and shall be created if it does not exist. A default path shall be proposed.

What I have so far is:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
AppName=Testapp
AppVersion=1.0
DefaultDirName={code:GetOtherDir}
DefaultGroupName=TestProgram
PrivilegesRequired = lowest
OutputBaseFilename =TestProgram

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "program.exe"; DestDir: "{app}"
Source: "readme.txt";  Flags: onlyifdoesntexist; DestDir: "{app}"

[Icons]
Name: "{userdesktop}\Subdirectory"; Filename: "{userdocs}\Subdirectory\program.exe"; Tasks: desktopicon

[Code]
var
  OtherInputDirPage: TInputDirWizardPage;

procedure InitializeWizard;
begin
  OtherInputDirPage :=
    CreateInputDirPage(wpSelectDir, 'Installationsverzeichnis wählen:', '', '', False, '');
  OtherInputDirPage.Add('');
  // Set initial value (optional)
  OtherInputDirPage.Values[0] := ExpandConstant('{userdocs}\Subdirectory');
end;

function GetOtherDir(Param: String): String;
begin
  Result := OtherInputDirPage.Values[0];
end;

I am able to install one single file into a user defined location with a different code, but I am not able to use that location also for the second file, so this is why I came up with the code above. Can anyone help?

2

There are 2 best solutions below

0
Martin Prikryl On BEST ANSWER

The code you are trying seems unnecessarily complicated for such a trivial task. A basic Inno Setup script for installing two files into user-selected directory is like:

[Setup]
AppName=My Program
AppVersion=1.0
DefaultDirName={autopf}\My Program

[Files]
Source: "program.exe"; DestDir: "{app}"
Source: "readme.txt"; DestDir: "{app}"

You possibly got confused, because you have the application installed already and the standard directory selection page does not show. See:
Inno Setup generated installer does not show "Select Destination Location" page on some systems

8
tfv On

The comment from Martin Prikryl was rather helpful, and my additional problem was actually that the DisableDirPage=no was missing and therefore the directory selection dialog did not show up since the program was already installed once.

[Setup]
AppName=Test
AppVersion=1.0
DefaultDirName={userdocs}\Testprogramdir
//DisableProgramGroupPage=yes
AlwaysShowDirOnReadyPage = yes
DisableDirPage = no
OutputDir=Output

[Files]
Source: "program.exe"; DestDir: "{app}"
Source: "readme.txt"; DestDir: "{app}"

[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
  InstallDir: string;
begin
  Result := True;
  
  if CurPageID = wpSelectDir then begin
    InstallDir := WizardForm.DirEdit.Text;
    if not DirExists(InstallDir) then begin
      if not CreateDir(InstallDir) then begin
        MsgBox('Could not create installation directory.', mbError, MB_OK);
        Result := False;
      end;
    end;
    WizardForm.DirEdit.Text := InstallDir; // Update the directory edit field
  end;
end;