There seems to be no way to change the script constant using scripts.
I think your best bet is to change the destination directory for each entry in the [Files] section, for example.
[Files] Source: "MYPROG.EXE"; DestDir: "{code:NewTargetDir}"
and get the new installation directory as follows:
[Code] function NewTargetDir(Param: String): String; begin Result := ExpandConstant('{app}') + '\MySubDir'; end;
Since the NewTargetDir function is called immediately before copying the file, this should work.
However, I think you should reconsider your approach. First, ask the user to specify the directory to install, and then actually install to another directory, which seems to be your intention, is the wrong way, IMO. Do you really have a good reason to install in a different directory than the one specified by the user? Also, the result of my sample code could be achieved by specifying
[Files] Source: "MYPROG.EXE"; DestDir: "{app}\MySubDir"
without any scripts. If in doubt, see a simpler solution.
source share