Search code examples
nsis

Add link to Abort page


As a follow-up to this answer, I'm trying to add the link after issuing Abort command, but for some reason it does not appear, no trace of it when viewed in Spy++.enter image description here

The idea is to add the link above the progress bar, but somehow the macro does not work. Is there a reason for this that I'm missing and is it possible to add that link after calling Abort? I've read somewhere that Abort command can have different effect so I'm guessing this is one of it.

I've tried to make this sample script as concise as best I can and would greatly appreciate any help as I'm still learning NSIS.

!include "MUI2.nsh"

;--------------------------------
;General
ShowInstDetails hide
SetCompressor /SOLID lzma

;Request application privileges for Windows Vista
RequestExecutionLevel user

;--------------------------------
;Interface Configuration

!define MUI_ABORTWARNING
!define MANUAL_DOWNLOAD_TEXT "Automatic download not working? Click here to download manually."

;--------------------------------
;Macros
!macro AddDownloadLink yCoord
    FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog
    System::Call 'USER32::CreateWindowEx(i0, t "STATIC", t "${MANUAL_DOWNLOAD_TEXT}", i${WS_CHILD}|${WS_VISIBLE}|${SS_NOTIFY}, i 1, i ${yCoord}, i 500, i 50, p $0, i 0x666, p 0, p 0)p.s'
    Pop $0
    SetCtlColors $0 0000ff transparent 
    CreateFont $1 "$(^Font)" "$(^FontSize)" "400" /UNDERLINE
    SendMessage $0 ${WM_SETFONT} $1 1

    GetFunctionAddress $1 fnLinkClicked
    ButtonEvent::AddEventHandler 0x666 $1
!macroend

;--------------------------------
;Pages
!insertmacro MUI_PAGE_INSTFILES

;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"

;--------------------------------
;Installer Sections
Section
    Var /global Filename    
    StrCpy $Filename "test100Mb.db"

    Var /global DownloadUrl 
    StrCpy $DownloadUrl "http://speedtest.ftp.otenet.gr/files/$Filename"

    !insertmacro AddDownloadLink 70

    inetc::get /caption "Downloading package" $DownloadUrl "$Filename" /end 
    Pop $R0 ;Get the return value
    StrCmp $R0 "OK" 0 dlfailed

    Goto quit

dlfailed:
    DetailPrint "Download failed: $R0 $DownloadUrl"
    SetDetailsView show 
    Abort

    !insertmacro AddDownloadLink 1

quit:
    Quit
SectionEnd

Function fnLinkClicked
    ExecShell "open" "$DownloadUrl"
FunctionEnd

Solution

  • Abort stops executing the section(s) code, you must do whatever you need to do before calling Abort.

    Adding controls in a section can be problematic because it executes on a different thread and windows are tied to the thread that created them. If you need the window to stick around longer than the install thread you can create it as a hidden window in the instfiles page show callback and simply call ShowWindow in the section when you need to display it...