Search code examples
nsis

NSIS: call MUI_PAGE_LICENSE from function but get "XPStyle not valid" error


I have a custom dialog with an "License terms and conditions." checkbox where the Text to the checkbox is actually a link which is suppose to show the License Dialog.

; === LicenseLink (type: Link) ===
${NSD_CreateLink} 132.96u 100.92u 107.29u 14.15u "License terms and conditions."
Pop $hCtl_welcome_LicenseLink
${NSD_OnClick} $hCtl_welcome_LicenseLink ShowLicense

Now in the function "ShowLicense" I tried calling

!insertmacro MUI_PAGE_LICENSE

but get an error: Error: command XPStyle not valid in Function

evidently I'm approaching this wrong and I can't interpret the error. Would be happy for any ideas on how to resolve this.

Thanks!


Solution

  • You cannot call !insertmacro MUI_PAGE_LICENSE dynamically, the number of pages is determined at compile time.

    You can however skip pages to achieve this:

    InstallDir "$Temp\Test"
    
    !include MUI2.nsh
    !include nsDialogs.nsh
    !include WinMessages.nsh
    !include LogicLib.nsh
    
    !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicensePage
    !insertmacro MUI_PAGE_LICENSE "${__FILE__}"
    Page Custom InfoPageCreate InfoPageValidate
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE English
    
    
    Var ShowLicensePage
    Function SkipLicensePage
    ${IfThen} $ShowLicensePage = 0 ${|} Abort ${|} ; Skip it the first time
    FunctionEnd
    
    Function OnShowLicense
    SendMessage $hWndParent ${WM_COMMAND} 3 "" ; Click the (hidden) back button
    FunctionEnd
    
    Var InstDirCtl
    Function InfoPageCreate
    StrCpy $ShowLicensePage 1
    GetDlgItem $0 $hWndParent 3
    ShowWindow $0 0 ; Hide the back button
    !insertmacro MUI_HEADER_TEXT "Blah blah" "blah blah blah"
    nsDialogs::Create 1018
    Pop $0
    
    ${NSD_CreateText} 0 13u 100% 12u "$InstDir"
    Pop $InstDirCtl
    
    ${NSD_CreateLink} 2u 40u -4u 12u "License"
    Pop $0
    ${NSD_OnClick} $0 OnShowLicense
    
    nsDialogs::Show
    FunctionEnd
    
    Function InfoPageValidate
    ${NSD_GetText} $InstDirCtl $InstDir
    FunctionEnd