tags:

views:

1074

answers:

3

I want to change defaultdirname parameter in ssInstall part. How can I do that? Is there a function for setting [Setup] parameters.

A: 

There seems to be no way to change a script constant via scripting.
I think your best bet is to modify the target directory for each entry in the [Files] section, e.g.

[Files]
Source: "MYPROG.EXE"; DestDir: "{code:NewTargetDir}"

and derive your new installation directory like this:

[Code]
function NewTargetDir(Param: String): String;
begin
  Result := ExpandConstant('{app}') + '\MySubDir';
end;

Since the NewTargetDir function will be called just before the file is actually copied, this should work.

However, I think you should reconsider your approach. First asking the user to specify a directory to installinto, and then actually installing into a different directory, which seems to be your intent, is the wrong way, IMO. Do you really have a compelling reason to install into another directory than the one specified by the user? Besides, the result of my example code could just as well be achieved by specifying

[Files]
Source: "MYPROG.EXE"; DestDir: "{app}\MySubDir"

without any scripting needed. When in doubt, go for the simpler solution.

Treb
I've embedded another (host application) installer to the plugin installer. plugin upon start checks to see the installation path from registry (of the host app). However if it wasn't already installed, then this path is undefined at that moment. Plugin installer then launches the host app installer before the actual installation starts. This is the moment I want to update dirname to the (now defined) installation path of the host app. This is where I need to edit installdir. Actually even in this case, Inno installs the files to the correct dir but not the unins000.exe/dat files,which is odd.
Ok, this qualifies as a 'compelling reason' in my book ;-)
Treb
+1  A: 

The following global objects are available : MainForm of type TMainForm, WizardForm of type TWizardForm and UninstallProgressForm of type TUninstallProgressForm and one special constant: crHand of type TControl.Cursor.

If you want to set the default directory in the wizard, just access to it's componants like you would in normal delphi code.

For example, set the directory to a custom value:

WizardForm.DirEdit.Text := 'c:\test';

to read that value you can use the WizardDirValue function.

I say 'just access'... but it took me an hour to figure out ;)

Jonx
A: 

I have a similar situation, where the setup app is receiving the install path from the command line. I'm using the solution proposed by Jonx:

WizardForm.DirEdit.Text := 'c:\test';

Example:

function CompareParameter(param, expected: String): Boolean;
begin
  Result := False;
  if Length(param) >= Length(expected) then
  begin
    if CompareText(Copy(param, 1, Length(expected)), expected) = 0 then
    begin
      Result := True;
    end;
  end;
end;

function GetParameter(expectedParam: String): String;
var
  i : LongInt;
begin
  Result := '';
  for i := 0 to ParamCount() do
  begin
    if CompareParameter(ParamStr(i), '/' + expectedParam + '=') then
    begin
      Result := Copy(ParamStr(i), Length(expectedParam) + 3, Length(ParamStr(i)));
      break;
    end;
  end;
end;

procedure InitializeWizard();
var
  newInstallFolder: String;
begin
  newInstallFolder := GetParameter('INSTALL_FOLDER');
  if Length(newInstallFolder) > 2 then
  begin
    if Copy(newInstallFolder, 1, 1) = '"' then
      newInstallFolder := Copy(newInstallFolder, 2, Length(newInstallFolder) - 2)
    if Length(newInstallFolder) > 1 then
      WizardForm.DirEdit.Text := newInstallFolder;
  end;
end;

The setup app is being started from another setup, in silent mode. It worked OK for me.

golimpio