- NSIS Discussion
- Variables error
Archive: Variables error
FreeGeG
18th January 2003 14:40 UTC
Variables error
I have tryed for first time to use NSIS * it's rules :cool: *
I'm still newbie, and can get the Variable set and Get to work... loog this code and tell whats wrong?
LicenseData "${NSISDIR}\Contrib\Modern UI\License.txt"
;Component-selection page
;Descriptions
LangString DESC_SecCopyUI ${LANG_Danish} "Installer Left Alone beta 0.019"
;--------------------------------
;Folder-selection page
EnumRegValue $REGINSTALL HKLM "SOFTWARE\Sierra OnLine\Setup\HALFLIFE" "Directory"
InstallDir "$REGINSTALL"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
!insertmacro MUI_RESERVEFILE_SPECIALINI
!insertmacro MUI_RESERVEFILE_SPECIALBITMAP
;--------------------------------
;Modern UI System
!insertmacro MUI_SYSTEM
;--------------------------------
;Installer Sections
Section "Left Alone" SecCopyUI
;Add your stuff here
SetOutPath "$INSTDIR"
File "C:\la\test.html"
;--------------------------------
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
;--------------------------------
;Descriptions
!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecCopyUI} $(DESC_SecCopyUI)
!insertmacro MUI_FUNCTIONS_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
;Add your stuff here
Delete "$INSTDIR"
RMDir "$INSTDIR"
!insertmacro MUI_UNFINISHHEADER
SectionEnd
virtlink
18th January 2003 14:57 UTC
Use ReadRegStr instead of EnumRegValue, since EnumRegValue returns the name of the x'th registry value in a key, not the value of a specified registry value. ReadRegStr does that for strings and ReadRegDWORD for DWORDs.
See also: 3.7.2.11 ReadRegStr.
kichik
18th January 2003 15:01 UTC
Commands that are not setting installer settings (name, caption, pages, etc.) can not be outside of functions or sections. NSIS must know when to execute the command so it must be in a function or a section.
Also $REGINSTALL is not a NSIS variable. NSIS have only 20 variables available for you to use: $0, $1, $2, ..., $9, $R0, $R1, $R2, ..., $R9 and $INSTDIR, $EXEDIR, etc. which are used for other things.
To set the installation directory according to the registry use InstallDirRegKey (outside of a function or a section because it sets an installer settings which is an automatic installation directory retrival from the registry).
FreeGeG
18th January 2003 15:09 UTC
Now it's working thanks
virtlink
18th January 2003 15:09 UTC
kichik still knows more about it than i do. Damn!
FreeGeG
18th January 2003 15:16 UTC
is there a way to add a dir to the InstallDirRegKey ?
kichik
18th January 2003 15:46 UTC
Edit $INSTDIR in .onInit.
FreeGeG
18th January 2003 16:14 UTC
Sorry to ask you, but how do i Edit it?
kichik
18th January 2003 16:48 UTC
For example:
StrCpy $INSTDIR $INSTDIR\MyProg
FreeGeG
18th January 2003 22:33 UTC
Aghhh it's working, thanks many times, i have many more questions, but i make a subject there match.
greg9504
14th August 2003 13:06 UTC
Bug in solution?
Hi,
I think there is a bug in the solution. I had
StrCpy $INSTDIR $INSTDIR\MyProg
in my .onInit function. It seemed to work, then something odd started to happen. Instead of seeing
C:\Program Files\mycompany\MyProg
in the directory dialog (modern UI) I was seeing
C:\Program Files\mycompany\MyProg\MyProg\MyProg\MyProg
After a bit of thought I figured it was a copy in place problem and changed the script to:
Function .onInit
StrCpy $0 $INSTDIR\MyProg
StrCpy $INSTDIR $0
FunctionEnd
This seems to have fixed it.
I would like to say what version I am using but can't seem to find that anywhere and can't remember what version I installed. It was 2 something... I most likely took the latest install from a week ago or so, so 2.0 beta 3a.
greg9504
14th August 2003 13:22 UTC
Arg! that didn't fix it, well it worked once. Now I am getting
C:\Program Files\MyCompany\MyApp\MyApp
when all I want is
C:\Program Files\MyCompany\MyApp
in the directory dialog. My script looks like:
!define MUI_PRODUCT "MyCompany"
#...
InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"
InstallDirRegKey HKCU "Software\${MUI_PRODUCT}" ""
#...
Function .onInit
StrCpy $0 $INSTDIR\MyApp
StrCpy $INSTDIR $0
FunctionEnd
[edited by kichik]Please don't copy and paste huge scripts. Attach them. Irrelevant parts of the script deleted.[/edit]
Afrow UK
14th August 2003 13:32 UTC
That is wrong.
You should set $INSTDIR with
InstallDir "C:\program files\blah"
Also, you are using the old NSIS 2.0b3. It is recommended that you download the latest Development version from http://nsis.sourceforge.net
Note that you may have to change a lot in your script (Modern UI has changed a lot too)
-Stu
kichik
14th August 2003 13:57 UTC
If there is no backslash at the end of InstallDir definition the part after the last backslash will be automatically appended to the user selected directory, if he chose it using the browse button.
If your InstallDir is $PROGRAMFILES\MyCompany and $INSTDIR is $PROGRAMFILES\MyApp in .onInit then its value is probably taken from InstallDirRegKey. Make sure the value is empty before trying again.
You don't need .onInit anyway. Just set InstallDir to be the desired value directly. Example:
InstallDir $PROGRAMFILES\MyCompany\MyApp
greg9504
14th August 2003 14:20 UTC
The date on my makensis.exe is 3/17/2003...
Should I be using the latest development build and not the 3abeta release?
Kichik, I tried setting
InstallDir $PROGRAMFILES\MyCompany\MyApp
using:
InstallDir "$PROGRAMFILES\${MUI_PRODUCT}\MyApp"
However in the directory dialog I only saw
"$PROGRAMFILES\${MUI_PRODUCT}"
displayed as the default install dir. However if I chose the default it would install to
"$PROGRAMFILES\${MUI_PRODUCT}\MyApp"
Anyway, you were correct and my repeating problem was due to InstallDirRegKey not being cleaned up.
Thanks.
[on edit]
I just tried setting
InstallDir "$PROGRAMFILES\${MUI_PRODUCT}\MyApp"
and it is working like it should (displayed in directory dialog). I guess it had to due with an old InstallDirRegKey.
Thanks again.