Old 14th April 2011, 15:06   #1
Junior Member
Join Date: Apr 2008
Posts: 21
Get last InstallDir - problem


NSIS have a very good documentation, in fact the best i have ever seen in a freeware tool.
I made an installer script and it worked so far, but i tried to insert an exist check of previously installed versions of my program.
I want to determine where it was installed and use that directory as the default output directory at the Install Page.

So i let the installer write the used InstallDir into the registry (no problem there). The installer should look at the start, for the regkey that is written by previously installations.
btw. I realised that the "Goto" thingie does not realy work like the Windows Batch "Goto". When ther there are 2 identical variables to define, the compiler exits with an error, even if is jumped with a "GOTO"! ... but this is another story.

Here is the part of the script that does not work: (everything above the CALL is OK!)

PHP Code:
Function .
!system "..\plugins\GetVersion-from-MyPROGRAM32\GetVersion-from-MyPROGRAM32.exe"
!include "..\plugins\GetVersion-from-MyPROGRAM32\Version.txt"
;            ; # cut from the 2. right position for the title name -> Caption "MyPROGRAM - ${VERSION2}"
StrCpy  $"${VERSION}-2
!define VERSION2 "$1"

CALL alreadyexistcheckfunktion


; - 
ALREADY EXIST INSTALLATION? - if yesthen get the install directory into -> InstallDir "$(TARGETDIR)"otherwise set default instal dir

Function alreadyexistcheckfunktion
# check key existence
ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyPROGRAM"  "InstallPath"
IfErrors jumpout ""
MessageBox MB_ICONQUESTION|MB_YESNO "Looks like MyPROGRAM is already installed$\r$\n$\r$\nDo you want to continue the installation anyway$\r$\nand update MyPROGRAM?" IDYES alreadyexistcheckout
# aborting end EXIT
MessageBox MB_ICONINFORMATION|MB_OK "Stopping installation process"
ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyPROGRAM"  "InstallPath"
!define targetdir $1
Goto jumpoutout
ifndef targetdir
!define targetdir "$PROGRAMFILES64\MyPROGRAM"


InstallDir "$(TARGETDIR)"
Caption "MyPROGRAM - ${VERSION2}"


The setup is OK but the compiler finish with a warning:
1 warning:
LangString "TARGETDIR" is not set in language table of language English

1. Question: what is the connection of this Function and the "language table of language English" ?

The Setup starts correctly.
-at the first time the InstallDir is empty.
-the second time, the Windows Title (caption) got the the $(targetdir) of the previous installation (=>MyPROGRAM - "C:\Program Files\xyz"), and the "InstallDir" @ the InstallPage is empty, too!
What went wrong?

I tried another way:
When i change "Function alreadyexistcheckfunktion" to "Function .onGUIInit" the compiler exits with:

PHP Code:
Error: Function named ".onGUIInit" already exists.
Error in macro MUI_FUNCTION_GUIINIT on macroline 2
Error in macro MUI_INSERT on macroline 11
Error in macro MUI_LANGUAGE on macroline 7
Error in script 
"stdin" on line 208 -- aborting creation process 
linie 208 is-> "!insertmacro MUI_LANGUAGE "English""

2. Question: What does this function have to do with the macro at all?
Isnt it alowed to use the ".onGUIInit" in the main .nsi file??

3. Question: Why does the window title change into the InstallDir and the default install page is empty?

I would be very thankful for any help!

Smurge is offline   Reply With Quote
Old 14th April 2011, 17:35   #2
Anders's Avatar
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,165
You are mixing compile time defines with run time variables and langstrings and whatnot:

Defines (compile time):
!define foo "bar"
MessageBox mb_ok ${foo}

Variables (run time):
StrCpy $0 "bar"
MessageBox mb_ok $0

and $(foo) would be a langstring, they are created at compile time, but "selected" in .onInit and are valid after .onInit

Lucky for you there is a installer attribute called InstallDirRegKey that will set $instdir to a value from the registry with InstallDir as its backup value if not found

Modern UI already uses .onGuiInit for its own internal handling, check the MUI docs, there is a define you can set so it calls your own private onGuiInit like function

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th April 2011, 17:37   #3
Major Dude
Join Date: Oct 2006
Posts: 1,892
You're confusing compiletime and runtime functions:
PHP Code:
        !define targetdir $1
Goto jumpoutout
ifndef targetdir
!define targetdir "$PROGRAMFILES64\MyPROGRAM"
The above will always define targetdir as $1, never as programfiles\myprogram. You need to use StrCpy instead.

Edit: High-five Anders
MSG is offline   Reply With Quote
Old 14th April 2011, 18:12   #4
Junior Member
Join Date: Apr 2008
Posts: 21
omg, that was an easy one
thanks for the hint!

i add the line and removed some stupid ones from my "alreadyexistcheckfunktion" Function and everything is fine.
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProgram" "InstallPath"

thank you!
Smurge is offline   Reply With Quote
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump