Archive: Get last InstallDir - problem


Get last InstallDir - problem
  Hello

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

;------------------------

Function .onInit
; # GET FILE VERSION FROM MyPROGRAM.EXE
; http://nsis.sourceforge.net/Invoking_NSIS_run-time_commands_on_compile-time
!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 $1 "${VERSION}" -2
!define VERSION2 "$1"

>CALL alreadyexistcheckfunktion

FunctionEnd


>;-----
; -ALREADY EXIST INSTALLATION? - if yes, then 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"
Abort
>;---------EOS
alreadyexistcheckout:
ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyPROGRAM" "InstallPath"
!define targetdir $1
Goto jumpoutout
jumpout:
!ifndef targetdir
!define targetdir "$PROGRAMFILES64\MyPROGRAM"
!endif
>jumpoutout:
>FunctionEnd

>.
.
.

>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:


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!

bye

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


You're confusing compiletime and runtime functions:


        !define targetdir $1

Goto jumpoutout
jumpout:
!ifndef targetdir
!define targetdir "$PROGRAMFILES64\MyPROGRAM"
!endif
The above will always define targetdir as $1, never as programfiles\myprogram. You need to use StrCpy instead.

Edit: High-five Anders :)

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!