- NSIS Discussion
- Dynamic InstallDirRegKey
Archive: Dynamic InstallDirRegKey
progoth
11th November 2004 16:52 UTC
Dynamic InstallDirRegKey
I really can't figure this out, and it seems like it would be a simple straightforward thing...
I want to set the InstallDir dynamically, or something achieving that effect, but I can't figure out how to do it. If the program's never been installed, I want to read a different key and make that the default install directory...if it doesn't exist then I have a default place to put it. However, once PRODUCT_DIR_REGKEY has been set, I want all future installs to use that and not go through looking for the other key.
I thought the solution for this would be to create PRODUCT_DIR_REGKEY if it doesn't already exist in .onInit. However, apparently that key is read before .onInit is called, because it has no effect unless I quit the installer and run it again.
I hope I've made sense, I can clarify as needed.
Thanks
Afrow UK
11th November 2004 17:42 UTC
Rather than using InstallDirRegKey just do it all using Read/WriteRegStr
InstallDir "C:\myapp"
Function .onInit
Push $R0
ReadRegStr $R0 HKCU "Software\myapp1" "InstallDir"
StrCmp $R0 "" 0 +3
ReadRegStr $R0 HKCU "Software\myapp2" "Blah"
StrCmp $R0 "" +2
StrCpy $INSTDIR $R0
Pop $R0
FunctionEnd
-Stu
progoth
11th November 2004 17:52 UTC
Sorry, I didn't really mention that what I'm trying to do is set the default install location that is presented to the user during the install. I can't figure out how to do it dynamically at install time. As far as I know you can't change InstallDir or InstallDirRegKey at install time, so the only way I can think of to change the default install location is by changing the value of the key at PRODUCT_DIR_REGKEY. But that doesn't work, as the value is read BEFORE .onInit.
Dyflmez
24th January 2005 18:51 UTC
Ok. Why is it so hard to set the Install Dir?
Evey other install program out there can do it, so why can't NSIS?
This is my code, I keep getting the same error :
Usage: ReadRegStr $(user_var: output) rootkey subkey entry
root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)
Error in script "D:\Install Files\Essensuals\NSIS\WorkDir\DC_Map.nsi" on line 54 -- aborting creation process
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
>OutFile "DCMap.exe"
>InstallDir "$InstalDir\\Mods\\DC_Final\\Archives\\BF1942\\levels"
>ShowInstDetails show
ShowUnInstDetails show
>Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
ReadRegStr $InstalDir HKLM "SOFTWARE\\EA GAMES\\Battlefield 1942" "GAMEDIR"
StrCpy $INSTDIR "$InstalDir\\Mods\\DC_Final\\Archives\\BF1942\\levels"
>FunctionEnd
>
Dkom
24th January 2005 19:52 UTC
Try this code
!define GAME_KEY "SOFTWARE\EA GAMES\Battlefield 1942"
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "DCMap.exe"
InstallDir "C:\\Games (or other default dir)\Mods\DC_Final\Archives\BF1942\levels"
ShowInstDetails show
ShowUnInstDetails show
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
ClearErrors
ReadRegStr $0 HKLM "${GAME_KEY}" "GAMEDIR"
IfErrors +2
StrCpy $INSTDIR "$0\Mods\DC_Final\Archives\BF1942\levels"
FunctionEnd
Afrow UK
24th January 2005 21:01 UTC
Your code doesn't work because you are using an undefined variable: $InstalDir
You should use a ready-defined variable like $R0.
-Stu
Dkom
25th January 2005 16:17 UTC
2 Afrow UK (your post from 11-11-2004):
But if $R0 ends with exe name, how to trim last part of string until \.
For example if I read ReadRegStr $R0 HKCU "Software\myapp1" "InstallDir" - I get C:\SomeDir\SomeProg.exe
And when I read ReadRegStr $R0 HKCU "Software\myapp2" "Blah"
I get C:\AnotherDir\AnotherProg.exe
I don't now number of letters, so I can't use "StrCpy
user_var(destination) str [maxlen] [start_offset]"
How to convert this variables to C:\SomeDir\ and C:\AnotherDir\ ?
Dyflmez
25th January 2005 20:31 UTC
Dkom thanks man that worked.
superwan
25th January 2005 21:42 UTC
okay, I'm gonna try it for me...
that's what I too wanted to do...
but if somebody could explain why the installdirregkey does not change my instdir... :D
I'm sure I'm somewhere wrong, but don't know where...
Afrow UK
26th January 2005 10:59 UTC
Originally posted by Dkom
2 Afrow UK (your post from 11-11-2004):
But if $R0 ends with exe name, how to trim last part of string until \.
For example if I read ReadRegStr $R0 HKCU "Software\myapp1" "InstallDir" - I get C:\SomeDir\SomeProg.exe
And when I read ReadRegStr $R0 HKCU "Software\myapp2" "Blah"
I get C:\AnotherDir\AnotherProg.exe
I don't now number of letters, so I can't use "StrCpy
user_var(destination) str [maxlen] [start_offset]"
How to convert this variables to C:\SomeDir\ and C:\AnotherDir\ ?
GetParent function:
http://nsis.sourceforge.net/archive/...ances=0,11,211
-Stu