Downloading files in Custom NSIS Page - nsis

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

Related

is it possible in nsis from the dialog to pass the input value as a parameter to the called console application through the installer,

is it possible in nsis from the dialog to pass the input value as a parameter to the called console application through the installer, using the nsDialog plugin
Function customPage
!insertmacro MUI_HEADER_TEXT "Something" "Tool"
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 12u "enter text name"
Pop $0
Function customPage
!insertmacro MUI_HEADER_TEXT "Something" "Tool"
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 12u "enter text name"
Pop $0
${NSD_CreateText} 0 12u 93% 12u
Pop $TextBox
nsDialogs::Show
FunctionEnd
nsDialogs::Show
FunctionEnd
Yes this is a common pattern. Just save the value when the user leaves the page so you can use it in a Section:
!include MUI2.nsh
!include nsDialogs.nsh
Page Custom MyPageCreate MyPageLeave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Var TextBox
Var CustomValue
Function .onInit
StrCpy $CustomValue "Hello World" ; Default value used by silent installer
FunctionEnd
Function MyPageCreate
!insertmacro MUI_HEADER_TEXT "Something" "Tool"
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 0 100% 12u "enter text name"
Pop $0
${NSD_CreateText} 0 12u 93% 12u "$CustomValue"
Pop $TextBox
nsDialogs::Show
FunctionEnd
Function MyPageLeave
${NSD_GetText} $TextBox $CustomValue
FunctionEnd
Section
Exec '"$sysdir\cmd.exe" /K echo.$CustomValue&pause&exit'
SectionEnd

Jump to Next Page

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

How to Enable the disabled Next button in NSIS?

In My custom page, I have disabled the next button while the page loading... Because there is some background process need to complete, until we cant go to the next page. So I have disable the next button using following code.
GetDlgItem $1 $HWNDPARENT 1
EnableWindow $1 0
But I want to enable the next button once background process completed. I have used the follwoing code to enable
GetDlgItem $1 $HWNDPARENT 1
EnableWindow $1 1
But it was not worked... cld u please suggest the mistake done by me or how achieve this in NSIS?
Following is My Code
Function StartProgressPage
; Set dialog text:
!insertmacro MUI_HEADER_TEXT "$(STARTPRGDIA_TITLE)" "$(STARTPRGDIA_SUBTITLE)"
; Display the page:
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "StartPrgDia"
;Disable Next Button
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 0
nsDialogs::Create 1018
Pop $dialog
nsDialogs::CreateControl "msctls_progress32" \
${DEFAULT_STYLES}|${PBS_SMOOTH} \
${PB_EXSTYLE} \
0 30 100% 10% \
"Test" \
Pop $hwnd
${NSD_CreateTimer} NSD_Timer.CallStop 10
nsDialogs::Show
FunctionEnd
Function NSD_Timer.CallStop
${NSD_KillTimer} NSD_Timer.CallStop ; Kill the timer
SendMessage $hwnd ${PBM_SETRANGE32} 0 100
SendMessage $hwnd ${PBM_SETPOS} 25 0
Call <Some Process>
SendMessage $hwnd ${PBM_SETPOS} 50 0
Call ConfPropertyChanges
SendMessage $hwnd ${PBM_SETPOS} 100 0
${NSD_CreateLabel} 0 10 20% 10u Completed
;Enable Next Button
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 1
FunctionEnd
As far as I know installer will wait inside this code:
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "StartPrgDia"
until user goes to the next page.
Are you sure that the code bellow this line is executed when custom page is displayed?
You should call
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "StartPrgDia"
after all your code or use this(MUI2 version)
Function CustomPage
!insertmacro INSTALLOPTIONS_INITDIALOG "page.ini"
# your code here
!insertmacro INSTALLOPTIONS_SHOW
FunctionEnd

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