Jump to Next Page - nsis

I am trying to jump forward 1 page in my installer. I have a custom page in my NSIS installer. This custom page prompts the user to input a serial number. If they are valid I will jump the installer forward to the next page (the welcome page) if not we remain on the page. I will be jumping to the next page from within both the Initialse and Finalise functions.
Every time I try to jump to the next page the installer just closes. I have tried Abort and Return but both cause the installer to close. I have also trid Call RelGoToPage where $R9 is 1 but this sends the user back the page they are already on, ie, an infinite loop.
Whats going wrong and how can I make my installer jump to the next page.
# Page Definition
Page Custom SerialPageInitialise SerialPageFinalise
# Page Implementation
Function SerialPageInitialise
!insertmacro ValidateSUser
${If} $isValidUser > 0 # If user if valid
Return # Go to next page...Doesn't work just closes the whole installer
#Abort # Doesn't work just closes the whole installer
${EndIf}
FunctionEnd
# For the following function: the message "A" always shows then the installer closes
Function SerialPageFinalise
${NSD_GetText} $SerialEditBx $R9
!insertmacro ValidateUserExpanded "$R9"
${If} $isValidUser > 0 # If user if valid
MessageBox MB_OK "A"
${Else}
MessageBox MB_OK|MB_ICONEXCLAMATION "Authentication Failed. You are not a recognised client."
Abort
${EndIf}
FunctionEnd

Works fine for me:
!include LogicLib.nsh
!include nsDialogs.nsh
var isValidUser
var SerialEditBx
!macro ValidateUserExpanded param
StrCpy $isValidUser 0
${If} ${param} = 666
StrCpy $isValidUser 1
${EndIf}
!macroend
!macro ValidateSUser
MessageBox mb_yesno "ValidateSUser?" IDNO nope
!insertmacro ValidateUserExpanded 666
nope:
!macroend
Function SerialPageInitialise
!insertmacro ValidateSUser
${If} $isValidUser > 0
Abort ; Skip page
${EndIf}
nsDialogs::Create 1018
Pop $0
${NSD_CreateText} 0 13u 50% 13u "667"
Pop $SerialEditBx
nsDialogs::Show
FunctionEnd
Function SerialPageFinalise
${NSD_GetText} $SerialEditBx $R9
!insertmacro ValidateUserExpanded "$R9"
${If} $isValidUser > 0 # If user if valid
MessageBox MB_OK "OK"
${Else}
MessageBox MB_OK|MB_ICONEXCLAMATION "Authentication Failed. You are not a recognised client."
Abort ; Don't allow going to next page
${EndIf}
FunctionEnd
Page Custom SerialPageInitialise SerialPageFinalise
Page InstFiles

Related

Is there a way to link a part of text in DetailPrint in NSIS script to point to a file?

Example:
DetailPrint "Errors detected running post installation scripts. Click here to view the results."
Clicking on "here" should take user to specific file"
The log window is just a ListView control and it does not support this.
You can display a message to the user:
Section
; Post install steps...
MessageBox MB_YESNO|MB_ICONQUESTION "There was a problem, view results?" /SD IDNO IDNO skipresults
ExecShell "" "$Temp\InstallError.log"
skipresults:
SectionEnd
Or you can display a custom page with a link on it:
!include nsDialogs.nsh
!include LogicLib.nsh
Page Directory
Page InstFiles
Page Custom myPostFailureCreate
Var PostFailure
Function OpenPostReport
ExecShell ...
FunctionEnd
Function myPostFailureCreate
${If} $PostFailure = 0
Abort
${EndIf}
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 5u 0 80% 12u "Install scripts failed!"
Pop $0
${NSD_CreateLink} 5u 13u 80% 12u "View report"
Pop $1
${NSD_OnClick} $1 OpenPostReport
nsDialogs::Show
FunctionEnd
Section
; Post install steps...
${If} ${Errors}
StrCpy $PostFailure 1
${EndIf}
SectionEnd

Downloading files in Custom NSIS Page

I want to create an installer that downloads a file without freezing the UI using the inetc plugin. My question is that possible without using the ExecDos::Exec with the /ASYNC flag and then ExecDos::Wait.
In addition , i do not want installation page in my installer.
Here is my code:
!macro DOWNLOAD_PAGE
Function myTimer
${If} $0 == "OK"
${NSD_KillTimer} myTimer
SendMessage $hPBar ${PBM_SETRANGE32} 0 100
SendMessage $hPBar ${PBM_SETPOS} 100 0
Return
${EndIf}
SendMessage $hPBar ${PBM_SETRANGE32} 0 100
SendMessage $hPBar ${PBM_SETPOS} 50 0
FunctionEnd
function Page1
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateLabel} 0 0 100% 50% "Starting download..."
Pop $hInfo
${NSD_CreateProgressBar} 0 55% 100% 10u ""
Pop $hPBar
${NSD_CreateTimer} myTimer 1000
inetc::get /silent "$URL\skype.exe" "$EXEDIR\skype.exe" /end
Pop $0
nsDialogs::Show
functionEnd
function Page2
functionEnd
Page Custom Page1 Page2
!macroend
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro DOWNLOAD_PAGE
!insertmacro MUI_PAGE_FINISH
Or the only option i have is using the ExecDos::Exec with the /ASYNC flag?
Perhaps, a solution it is to create another nsis installer that does the download?
Performing a long operation between nsDialogs::Create and nsDialogs::Show will hang the UI.
The easy solution is to download in a Section because those are executed in a different thread. You are supposed to perform most of your tasks in a Section.
If you insist on downloading something on a custom page then you can use the InetBgDL plug-in:
!include nsDialogs.nsh
!include LogicLib.nsh
Page Custom Page1
Var hInfo
Function Page1
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 50% "Starting download..."
Pop $hInfo
InitPluginsDir
INetBgDl::Get "https://example.com/file.exe" "$PluginsDir\file.exe" /end
${NSD_CreateTimer} myTimer 1000
nsDialogs::Show
${NSD_KillTimer} myTimer
FunctionEnd
Function myTimer
InetBgDL::GetStats
${NSD_SetText} $hInfo "Status=$0$\nCompleted files=$1$\nDownloaded $3 of $4 bytes"
${If} $0 = 0 ; HTTP status code or 0 if completed without errors
${NSD_KillTimer} myTimer
MessageBox mb_ok Done
${EndIf}
FunctionEnd

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++.
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
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...

How to use REMOVE or REPAIR feature in NSIS script?

I have used nsis script for creating installer.When i run my installer second time with same name,REPAIR and REMOVE should be check and do the corresponding operation.I have find out my application already installed or not using following codes,
Function checkinstall
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\My app" "UninstallString"
IfFileExists $R0 +1 NotInstalled
call nsDialogpage
NotInstalled:
FunctionEnd
Function nsDialogpage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateRadioButton} 0 5u 100% 10u "Repair"
Pop $hwnd
${NSD_AddStyle} $hwnd ${WS_GROUP}
${NSD_OnClick} $hwnd ???
${NSD_CreateRadioButton} 0 25u 100% 56u "Remove"
Pop $hwnd
${NSD_OnClick} $hwnd ???
nsDialogs::Show
If the user select repair button it should overwrites existing installation path else uninstall existing installed and continue with new one.what am i need do to replace the (???) of the above code
page custom checkinstall
!insertmacro MUI_PAGE_DIRECTORY
My next page is Directory selection.so i need to call this page? How to achieve this?
1.How can i call un installer function if the user selects remove button?
Function un.Init, section /o -un.Main UNSEC000,section -un.post UNSE001
these are the un installer funtions.How can i call these functions? i have tried call method but it did not work.
You need to specify a callback function, like in the nsDialogs documentation, look for the nsDialogsPageLeave function in this example:
!include nsDialogs.nsh
!include LogicLib.nsh
Name nsDialogs
OutFile nsDialogs.exe
XPStyle on
Var Dialog
Var Label
Var Text
Page custom nsDialogsPage nsDialogsPageLeave
Page instfiles
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
Pop $Label
${NSD_CreateText} 0 13u 100% -13u "Type something here..."
Pop $Text
${NSD_OnChange} $Text nsDialogsPageTextChange
nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
${NSD_GetText} $Text $0
MessageBox MB_OK "You typed:$\n$\n$0"
FunctionEnd
Function nsDialogsPageTextChange
Pop $1 # $1 == $ Text
${NSD_GetText} $Text $0
${If} $0 == "hello"
MessageBox MB_OK "right back at ya!"
${EndIf}
FunctionEnd
Section
DetailPrint "hello world"
SectionEnd

How can I get a finish button after a nsDialogs page

I'm trying to create a post install configuration page in my nsis script using nsDialogs. My script for gathering the input and executing the configuration works however I'm never presented with a finish/close/exit button after I'm done. Currently my pages declaration looks like:
Page directory
Page instfiles
Page custom nsDialogsPage nsDialogsPageLeave
How can I get a finish/exit/done button to show after nsDialogsPageLeave executes?
The classic NSIS UI does not have a finish page, the instfiles page is usually the last page and it will show a "finish button" after all the sections have executed. You can set the text of any button to the same string with SendMessage $hwndButton ${WM_SETTEXT} 0 "STR:$(^CloseBtn)" if you want to provide your own finish page.
Most installers request the required information before the instfiles page, if you cannot do this then you might want to use the Modern UI, it will provide a finish page for you:
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
Page custom nsDialogsPage nsDialogsPageLeave
!insertmacro MUI_PAGE_FINISH
It was a little unclear to me if you wanted two pages; a input page and then a finish page or a combined input/finish page. A combined page is a little weird but it is possible:
!define AppName "Test"
Name "${AppName}"
Outfile "${AppName} setup.exe"
InstallDir $temp
!include LogicLib.nsh
!include WinMessages.nsh
!include nsDialogs.nsh
Var MyEndConfigPageStage
Page Directory
Page InstFiles
Page Custom MyEndConfigPageCreate MyEndConfigPageLeave /EnableCancel
Function MyEndConfigPageCreate
StrCpy $MyEndConfigPageStage 0
GetDlgItem $0 $hwndparent 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:&Apply"
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckBox} 0 13u 100% -13u "FooBar"
Pop $1
nsDialogs::Show
FunctionEnd
Function MyEndConfigPageLeave
${If} $MyEndConfigPageStage > 0
Return
${EndIf}
${NSD_GetState} $1 $2
ClearErrors
WriteIniStr "$instdir\settings.ini" Dummy "FooBar" $2
${If} ${Errors}
MessageBox mb_iconstop "Unable to apply settings!"
Abort
${EndIf}
IntOp $MyEndConfigPageStage $MyEndConfigPageStage + 1
GetDlgItem $0 $hwndparent 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^CloseBtn)"
GetDlgItem $0 $hwndparent 2
EnableWindow $0 0 ;Disable cancel
EnableWindow $1 0 ;Disable the checkbox
Abort
FunctionEnd
Section
SectionEnd

Resources