Archive: Another Problem with NAME


Another Problem with NAME
This code crashes when it is run:

;General
Name "My App"
!define VERSION "v. 1.0"
Caption "$(^NAME) ${VERSION}"
OutFile "MyApp.exe"

;Folder selection page
InstallDir "$PROGRAMFILES\MyFirm\$(^NAME)"

;Get install folder from registry if available
InstallDirRegKey HKCU "Software\MyFirm\$(^NAME)" ""

But this runs fine:

;General
Name "My App"
!define VERSION "v. 1.0"
Caption "$(^NAME) ${VERSION}"
OutFile "MyApp.exe"

;Folder selection page
InstallDir "$PROGRAMFILES\MyFirm\$(^NAME)"

;Get install folder from registry if available
InstallDirRegKey HKCU "Software\MyFirm\My App" ""

Obviously, the only difference is in the last line, so why does the call to InstallDirRegKey fail when $(^NAME) is used?

JAS


It's actually InstallDir that uses the language string when the language tables have not yet been initalized. If you want the folder name to be localized you'd have to copy the translation into $INSTDIR after the language have been chosen (.onGUIInit for example). I will address the crash, but I won't make it fill $INSTDIR after .onInit because usually .onInit is a place to test and set $INSTDIR.


I am sorry, but I don't understand. The code I showed is modeled directly on the WelcomeFinish.nsi example. All the lines I quoted are from the Configuration section of the script. I don't see how onInit or onGUIinit are relevant.

JAS


Because $(^Name) will only have the value you want it to have after .onInit. See the manual for more information about how the language is selected, that should clear it up.

Back to your question, set $INSTDIR on .onGUIInit with the LangString and it should work.


I am beginning to understand. If I customize onInit, can I us $(^Name) in my custom code, like this:

;--------------------------------
;Installer Functions

Function .onInit
check:
ReadRegStr $1 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^NAME)" "UninstallString"
StrCmp $1 "" done cont
cont:
HideWindow
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "'$(^NAME)' is already installed.$\n$\r$\n$\r \
Click 'OK' to remove the previous version or 'Cancel' to abandon this upgrade." IDOK uninst
Abort
uninst:
ClearErrors
ExecWait '$1'
IfErrors cont
uninst_wait:
Sleep 500
FindWindow $0 "" "$(^NAME) Uninstall"
IsWindow $0 uninst_wait ""
done:
BringToFront
FunctionEnd

Or would I have to move this code to onGUIinit?

JAS


Oh, that last piece of code was what you changed it too. As the InstallDirRegKey strings are not processed, LangStrings can be used in them. The crash still resulted from $(^Name) in InstallDir, but that has already been fixed in the latest CVS version.

You know what... I have seem to have taken this question a bit out of propertion. You don't want the key to depend on the language, otherwise you would have used Name with a LangString.

Simply add a define such as:

!define PRODUCT "My App"

and use it where needed, just like the old script. $(^Name) is only needed if you want it to be multilingual and to depend on the language used.


Yes, that makes sense. Thanks.

JAS