nsisnsis-mui

With NSIS can I share values between MUI_PAGE_DIRECTORY pages?


I have two MUI_PAGE_DIRECTORY pages. The first stores the entered data to the default, $INSTDIR. What I would like to do is copy the value in $INSTDIR to the defined var $DataDir so that before the second directory page is displayed, $DataDir becomes $INSTDIR\Data. When the second page is displayed I would like the default value to be $INSTDIR\Data.

Is this possible?


Solution

  • InstallDir $ProgramFiles\MyApp
    
    Var DataDir
    !include MUI2.nsh
    !define MUI_PAGE_CUSTOMFUNCTION_LEAVE InstDirPageLeave
    !insertmacro MUI_PAGE_DIRECTORY
    !define MUI_DIRECTORYPAGE_VARIABLE $DataDir
    !define MUI_DIRECTORYPAGE_TEXT_TOP "Choose Data directory for bla bla bla..."
    !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Data Directory:"
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW DataDirShowPage
    !insertmacro MUI_PAGE_DIRECTORY
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE English
    
    Function InstDirPageLeave
    StrCpy $DataDir "$InstDir\Data"
    FunctionEnd
    
    Function DataDirShowPage
    !insertmacro MUI_HEADER_TEXT "Foo" "Bar"
    FunctionEnd
    
    Section
    DetailPrint $InstDir
    DetailPrint $DataDir
    SectionEnd