I have only written one NSIS script, so there is much I don't know. I have a fairly simple install and I have managed to write a script that works perfectly except for one thing that I can't figure out.
Mine is an update install, so it can be assumed that product files already exist. The install affects two folders, a main product folder and a personal data folder, so I present two folder pages. The default main product folder is hard coded. The default personal data folder is obtained by reading an INI file in the main product folder. I'm able to perform this read with an .onInit function.
This all works perfectly, but only if the main product folder is in the default location, because the .onInit function can only read from the default folder location (before the first directory window is presented). I cannot find a way to read the INI file using the folder location obtained from the first folder page but before the second folder page is presented. How can I do that?
The relevant parts of my script are
!define MUI_TEXT_DIRECTORY_TITLE "AviSys"
!define MUI_TEXT_DIRECTORY_SUBTITLE "Clements Taxonomy Update ${YEAR}"
# Setup for first window (AviSys main folder selection)
!define MUI_DIRECTORYPAGE_TEXT_TOP "Select your AviSys main folder. Normally this will be C:\AVI6 as shown below. \
If so, simply click $"Next >$". \
If you have AviSys installed in a non-standard location, select that location here."
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION 'AviSys main folder'
!insertmacro MUI_PAGE_DIRECTORY
# Setup for second window (AviSys DATA folder selection)
!define MUI_DIRECTORYPAGE_TEXT_TOP "Now select your AviSys DATA folder. \
If the folder shown below is not your correct data folder, navigate to the correct one. \
When ready, click $"Install$"."
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "AviSys DATA Folder"
Var DATA_FOLDER
!define MUI_DIRECTORYPAGE_VARIABLE $DATA_FOLDER
!insertmacro MUI_PAGE_DIRECTORY
Function .onInit
ReadINIStr $R0 $INSTDIR\AVISYS.INI "Options" "DirPref"
StrCpy $DATA_FOLDER "$INSTDIR\$R0"
FunctionEnd
How to obtain directory in the middle of the install
3 posts
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE read
!insertmacro MUI_PAGE_DIRECTORY ; The first dir page
...
Function read
ReadINIStr $R0 $INSTDIR\AVISYS.INI "Options" "DirPref"
StrCpy $DATA_FOLDER "$INSTDIR\$R0"
FunctionEnd or MUI_PAGE_CUSTOMFUNCTION_PRE before the 2nd dir page.Perfect! Thanks!