Archive: Variables error


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

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.


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).


Now it's working thanks


kichik still knows more about it than i do. Damn!


is there a way to add a dir to the InstallDirRegKey ?


Edit $INSTDIR in .onInit.


Sorry to ask you, but how do i Edit it?


For example:

StrCpy $INSTDIR $INSTDIR\MyProg


Aghhh it's working, thanks many times, i have many more questions, but i make a subject there match.


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.


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]

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


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


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.