- NSIS Discussion
- $INSTDIR does not initialize in .onInit function at runtime
Archive: $INSTDIR does not initialize in .onInit function at runtime
vtsaran
13th May 2003 19:01 UTC
$INSTDIR does not initialize in .onInit function at runtime
Hello, listers!
I am at a loss.
I have two almost identical scripts. In both of them I initialize $instdir at compile time. Then, in the .onInit I have:
IfFileExists "$INSTDIR\myfiles*.*" Jump_if_Good Jump_If_Bad
but $INSTDIR does not initialize and installer behaves as though the files are not found. If I substitute $INSTDIR with an actual directory, then everything works fine.
The interesting thing is that the function which initializes the $INSTDIR at compile time is exactly the same in both scripts.
Do you have any idea about the possible causes of this misbehavior?
Thanks,
Victor
rsegal
13th May 2003 19:31 UTC
It would be helpful to see the function that initializes $INSTDIR
Joel
13th May 2003 20:57 UTC
attach script, dude :)
kichik
14th May 2003 11:24 UTC
$INSTDIR is set before .onInit if InstallDir and/or InstallDirRegKey are specified.
vtsaran
14th May 2003 16:04 UTC
Hello, guys!
OK, here goes the script.
Regards,
Vic
Joel
14th May 2003 16:11 UTC
I find you error:
InstallDir "$INSTDIR"
The above line is wrong, is should:
InstallDir "$PROGRAMFILES\${MUI_PRODUCT}" ;or another you want
vtsaran
14th May 2003 16:36 UTC
Well, it works in another script. Plus I want my $INSTDIR to be generated at runtime depending on the conclutions drawn from reading appropriate registry keys.
Regards,
Victor
Joel
14th May 2003 17:01 UTC
$INSTDIR contains the installation directory "variable"
from one of these three:
1. From the registry using the InstallDirRegKey.
2. When you use the InstallDir.
3. When the user use the Browse button the change the Installation path.
Afrow UK
14th May 2003 17:34 UTC
Here's how it works:
InstallDir "$PROGRAMFILES\Jeff"
$INSTDIR="C:\Program Files\Jeff"
vtsaran
14th May 2003 17:51 UTC
Thank you everybody. I can't believe how unattentive I was. There was a typing error in the line
InstallDirRegKey HKLM "Software\${MUI_PRODUCT}" "Install_Dir"
I accidentally omitted a quote.
So the following reads correct and works fine.
InstallDir "$INSTDIR"
InstallDirRegKey HKLM "Software\${MUI_PRODUCT}" "Install_Dir"
Now my $INSTDIR is defined at run time.
Regards,
Vic
kichik
14th May 2003 20:44 UTC
Your code is still wrong. The InstallDir sets $INSTDIR if InstallDirRegKey fails. You set something to itself when it's empty. It only works for you because the registry key is there, once it's gone you'll get an empty one instead. If you do want an empty $INSTDIR if the registry key is not there then you just don't need InstallDir.
Joel
14th May 2003 21:16 UTC
I have this and it works:
InstallDirRegKey HKLM "Software\${MUI_PRODUCT}" "Install_Dir"
InstallDir "C:\path"
This isnĀ“t right: InstallDir "$INSTDIR"
vtsaran
19th May 2003 21:03 UTC
OK, but then I don't understand something. How would I change $INSTDIR at run time? A very basic scenario: my installation directory will change depending on the version of another application installed. If I declare some path for InstallDir, then I have to stick with it. That's not what I want.
My current scenario works because if there is no InstallRegKey for my application, then I assume it was never installed on this computer, otherwise, I check for existence of certain files.
Regards,
Vic
Joel
19th May 2003 21:08 UTC
In the Nsis Manual check for "SetOutPath" instruction.
vtsaran
19th May 2003 21:11 UTC
Hello,
Kichik, you were right, I grant. I took out the line
InstallDir "$INSTDIR"
and it still works the same. I think I understand my mistake now.
Thanks everybody.
Regards,
Vic
kichik
21st May 2003 13:04 UTC
Just to make sure everybody understand, this is how it works:
- Installer starts
- The value specified using InstallDir is copied to $INSTDIR
- The value specified using InstallDirRegKey (if found) is copied to $INSTDIR
- .onInit is called, and later everything else
You can change $INSTDIR wherever you want in the script with worrying about InstallDir and InstallDirRegKey. Those just give the initial values.