NSIS WndSubClass error - nsis

I want to study about WndSubClass Plugin
So I compiled WndSubClass Example Source
But It was errored with message
NSIS v2.42 and later required!
But I'm Using NSIS Lastest Version(3.0rc1)
What Should I do?
Code
!AddPluginDir ".\release\"
!include WndSubclass.nsh
!include WinMessages.nsh
!include LogicLib.nsh
!define N "WndSubclassExample"
Name ${N}
OutFile "$%temp%\${N}.exe"
ShowInstDetails show
LicenseText "<<< hover over the icon, or click it$\n>>> or move this window with the minimize button!!!"
Caption "${N}"
SubCaption 0 " "
page license "" licshow
var MainWndSubProc
var IconSubProc
var hLic
var IconAnim
var firstbrandscroll
Function .onInit
!if 0
FindWindow $0 dbgviewClass
SendMessage $0 ${WM_COMMAND} 40020 0
System::Call user32::SetForegroundWindow(i$0)
!endif
FunctionEnd
Function IconSubProc
#System::Call 'kernel32::OutputDebugString(t "IconSubProc: $1 $2 $3 $4 $\n")'
${If} $2 = ${WM_NCHITTEST}
${If} $IconAnim = 0
System::Call 'user32::SetTimer(i $HWNDPARENT,i 1,i 50,i0)'
StrCpy $IconAnim 1
System::Call 'user32::SetTimer(i $1,i 1,i 50,i0)'
${EndIf}
${WndSubClass_Ret} 1
${ElseIf} $2 = ${WM_TIMER}
System::Call *(i,i,i,i)i.r0
System::Call user32::GetWindowRect(i$1,i$0)
FindWindow $2 "#32770" "" $HWNDPARENT
System::Call 'user32::MapWindowPoints(i 0,i $2,i $0,i 2)'
System::Call '*$0(i.r5,i.r6)'
IntOp $IconAnim $IconAnim + 1
IntOp $9 $IconAnim % 2
${If} $9 = 1
IntOp $6 $6 + 2
${Else}
IntOp $6 $6 - 2
${EndIf}
${If} $IconAnim > 10
System::Call user32::KillTimer(i$1,i1)
call ResetLicTick
StrCpy $IconAnim 0
${EndIf}
System::Call 'user32::SetWindowPos(i $1,i 0,i $5,i $6,i0,i0,i 1)'
System::Free $0
${ElseIf} $2 = ${WM_LBUTTONUP}
${If} $hLic = 0
quit
${EndIf}
call ResetLicTick
StrCpy $0 $hLic
StrCpy $hLic 0
SendMessage $0 ${WM_SETTEXT} 0 "STR:You disabled the ticker, don't click the icon again"
${EndIf}
FunctionEnd
Function MainWndSubProc
#System::Call 'kernel32::OutputDebugString(t "MainWndSubProc: $1 $2 $3 $4 $\n")'
${If} $2 = ${WM_NCHITTEST}
${WndSubClass_CallNextWndProc} $MainWndSubProc "" "" "" "" ;result in $0
${IfThen} $0 = 8 ${|} StrCpy $0 2 ${|} ;take over minimize btn and fake as HTCAPTION
${WndSubClass_Ret} $0
${ElseIf} $2 = ${WM_TIMER}
${If} $3 == 1
System::Call kernel32::GetTickCount()i.r0
SendMessage $hLic ${WM_SETTEXT} 0 "STR:Tick=$0"
${ElseIf} $3 == 2
GetDlgItem $0 $HWNDPARENT 0x404
System::Call 'user32::SendMessage(i $0,i ${WM_GETTEXT},i 99,t.r1)'
${If} $firstbrandscroll != 1
StrCpy $firstbrandscroll 1
StrCpy $1 "$1... "
${EndIf}
StrCpy $2 $1 1
StrCpy $1 "$1$2" "" 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:$1"
${EndIf}
${EndIf}
FunctionEnd
Function ResetLicTick
System::Call user32::KillTimer(i$HWNDPARENT,i1)
SendMessage $hLic ${WM_SETTEXT} 0 "STR:Tick=?"
FunctionEnd
Function licshow
${WndSubclass_Subclass} $HWNDPARENT MainWndSubProc $MainWndSubProc $MainWndSubProc
CreateFont $9 Arial 22
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $hLic $0 1000
GetDlgItem $1 $0 0x407
${WndSubclass_Subclass} $1 IconSubProc $IconSubProc $IconSubProc
SendMessage $hLic ${WM_SETFONT} $9 0
call ResetLicTick
System::Call 'user32::SetTimer(i $HWNDPARENT,i 2,i 250,i0)'
FunctionEnd
Section
SectionEnd

If you just Google "NSIS v2.42 and later required!" the first result should be this forum thread and it says you can fix it by adding this to the top of your .nsi:
!if "${NSIS_CHAR_SIZE}" = 1
!define __WNDSUBCLASS_NSISVEROK
!endif
!include "WndSubclass.nsh"

Related

Customizing an exsisting NSIS MUI2 page using nsDialogs

I want to include custom controls to Finish Page, depending on IfRebootFlag is set or not, but I don't know why some of those are created but not displayed.
The $hWnd is for each added control a number != 0, so it means all the controls were created. The position of controls seems to be ok... surely it is not behind the image on the left, because the Left coordinate is high enough to put the controls beyond the image
I tried for hours without understanding which can be the problem
;--------------------------------
;Header Files
!include nsDialogs.nsh
!include LogicLib.nsh
!include MUI2.nsh
Name App
OutFile ctmFinishPage.exe
XPStyle on
;--------------------------------
;General
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
;--------------------------------
;Variables
Var hWndChkBoxRunApp
Var hWndChkBoxLinkApp
Var hWndHlineReboot
Var hWndLblReboot
Var hWndRadBtnRebootNow
Var hWndRadBtnRebootLater
Var ctlLeft
Var ctlTop
Var ctlWidht
Var ctlHeight
Var ctlText
;--------------------------------
;Pages
;install pages
!insertmacro MUI_PAGE_INSTFILES
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyFinishShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyFinishLeave
!insertmacro MUI_PAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
Section
SetRebootFlag true
SectionEnd
;--------------------------------
;Functions
Function MyFinishShow
;add custom Reboot section to Finish page (MUI_FINISHPAGE_NOREBOOTSUPPORT flag is required)
IfRebootFlag 0 noreboot
StrCpy $ctlLeft 120u
StrCpy $ctlWidht 61%
StrCpy $0 50
StrCpy $ctlTop $0u
StrCpy $R0 10
StrCpy $ctlHeight $R0u
StrCpy $ctlText "Create Desktop shortcut"
${NSD_CreateCheckBox} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndChkBoxLinkApp
SetCtlColors $hWndChkBoxLinkApp "" "ffffff"
${NSD_SetState} $hWndChkBoxLinkApp ${BST_CHECKED}
StrCpy $1 117
StrCpy $ctlTop $1u
StrCpy $R1 1
StrCpy $ctlHeight $R1u
StrCpy $ctlText ""
${NSD_CreateHLine} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndHlineReboot
IntOp $R1 $R1 + 4
IntOp $2 $1 + $R1
StrCpy $ctlTop $2u
StrCpy $R2 25
StrCpy $ctlHeight $R2u
StrCpy $ctlText "Your computer must be restarted in order to complete the installation of App. Do you want to reboot now?"
${NSD_CreateLabel} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndLblReboot
SetCtlColors $hWndLblReboot "" "ffffff"
IntOp $R2 $R2 + 8
IntOp $3 $2 + $R2
StrCpy $ctlTop $3u
StrCpy $R3 10
StrCpy $ctlHeight $R3u
StrCpy $ctlText "Reboot now"
${NSD_CreateRadioButton} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndRadBtnRebootNow
SetCtlColors $hWndRadBtnRebootNow "" "ffffff"
${NSD_SetState} $hWndRadBtnRebootNow ${BST_CHECKED}
IntOp $R3 $R3 + 9
IntOp $4 $3 + $R3
StrCpy $ctlTop $4u
StrCpy $R4 10
StrCpy $ctlHeight $R4u
StrCpy $ctlText "I want to manually reboot later"
${NSD_CreateRadioButton} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndRadBtnRebootLater
SetCtlColors $hWndRadBtnRebootLater "" "ffffff"
${NSD_SetState} $hWndRadBtnRebootLater ${BST_UNCHECKED}
${NSD_OnChange} $hWndChkBoxLinkApp ToggleChkBoxState
${NSD_OnChange} $hWndRadBtnRebootNow ToggleRadBtnState
${NSD_OnChange} $hWndRadBtnRebootLater ToggleRadBtnState
Goto end
noreboot:
StrCpy $ctlLeft 120u
StrCpy $ctlWidht 61%
StrCpy $0 110
StrCpy $ctlTop $0u
StrCpy $R0 10
StrCpy $ctlHeight $R0u
StrCpy $ctlText "Run App"
${NSD_CreateCheckBox} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndChkBoxRunApp
SetCtlColors $hWndChkBoxRunApp "" "ffffff"
${NSD_SetState} $hWndChkBoxRunApp ${BST_UNCHECKED}
IntOp $R0 $R0 + 9
IntOp $1 $0 + $R0
StrCpy $ctlTop $1u
StrCpy $R1 10
StrCpy $ctlHeight $R1u
StrCpy $ctlText "Create Desktop"
${NSD_CreateCheckBox} $ctlLeft $ctlTop $ctlWidht $ctlHeight $ctlText
Pop $hWndChkBoxLinkApp
SetCtlColors $hWndChkBoxLinkApp "" "ffffff"
${NSD_SetState} $hWndChkBoxLinkApp ${BST_CHECKED}
${NSD_OnChange} $hWndChkBoxRunApp ToggleChkBoxState
${NSD_OnChange} $hWndChkBoxLinkApp ToggleChkBoxState
end:
FunctionEnd
Function MyFinishLeave
;reboot the PC if radio button for "Reboot Now" option is checked (MUI_FINISHPAGE_NOREBOOTSUPPORT flag needed)
IfRebootFlag 0 noreboot
${NSD_GetState} $hWndChkBoxLinkApp $0
${If} $0 == ${BST_CHECKED}
Call CreateDesktopShortcut
${EndIf}
${NSD_GetState} $hWndRadBtnRebootNow $0
${If} $0 == ${BST_CHECKED}
;Reboot
MessageBox MB_OK "Reboot..."
${EndIf}
Goto end
noreboot:
${NSD_GetState} $hWndChkBoxRunApp $0
${If} $0 == ${BST_CHECKED}
Call LaunchAppFile
${EndIf}
${NSD_GetState} $hWndChkBoxLinkApp $0
${If} $0 == ${BST_CHECKED}
Call CreateDesktopShortcut
${EndIf}
end:
FunctionEnd
Function ToggleChkBoxState
;manage Reboot radio buttons state. If one is checked, the other one is not checked and the other way around
Pop $1 ;$1 = $hWndChkBoxRunApp/LinkApp
${NSD_GetState} $1 $0
${If} $0 == ${BST_CHECKED}
${NSD_SetState} $1 ${BST_UNCHECKED}
${Else}
${NSD_SetState} $1 ${BST_CHECKED}
${EndIf}
FunctionEnd
Function ToggleRadBtnState
;manage Reboot radio buttons state. If one is checked, the other one is not checked and the other way around
Pop $1 ;$1 = $hWndRadBtnRebootNow/Later
${NSD_GetState} $1 $0
${If} $0 == ${BST_CHECKED}
${If} $1 == $hWndRadBtnRebootNow
${NSD_SetState} $hWndRadBtnRebootLater ${BST_UNCHECKED}
${Else}
${NSD_SetState} $hWndRadBtnRebootNow ${BST_UNCHECKED}
${EndIf}
${Else}
${If} $1 == $hWndRadBtnRebootNow
${NSD_SetState} $hWndRadBtnRebootLater ${BST_CHECKED}
${Else}
${NSD_SetState} $hWndRadBtnRebootNow ${BST_CHECKED}
${EndIf}
${EndIf}
FunctionEnd
Function LaunchAppFile
;create a file batch at runtime for launching an excel instance pointing to the App file name
MessageBox MB_OK "App launched at runtime..."
FunctionEnd
Function CreateDesktopShortcut
;create App shortcut on DESKTOP folder with custom icon
MessageBox MB_OK "Desktop Shortcut created..."
FunctionEnd
No error message is received during displaying Finish page
EDIT: Solved using User32::SetWindowPos API function in order to modify the Custom controls Z-order
!define HWND_TOP 0
!define SWP_NOSIZE 0x0001
!define SWP_NOMOVE 0x0002
System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) b ($hWndCtmCtl, ${HWND_TOP}, 0, 0, 0, 0, ${SWP_NOSIZE}|${SWP_NOMOVE})"
$mui.FinishPage.Text MUI static control with ${MUI_FINISHPAGE_TEXT} text is displaying on top of some of your controls.
Hide it with
Function MyFinishShow
ShowWindow $mui.FinishPage.Text 0
...
Or make it transparent if you want to keep the text and see your controls under it. You would have to move the checkbox down a bit if you want to keep the text so that they don't overlap.
Function MyFinishShow
SetCtlColors $mui.FinishPage.Text "${MUI_TEXTCOLOR}" transparent
...

How to use nsdialogs REMOVE or REPAIR feature in NSIS script?

My installer working fine without nsdialogs, If i add nsdialogs its not working good.I can't call nsdialogs in correct place.where i need to call nsdialogs?
Var hwnd
Var Dialog
Page custom checkinstall
Page custom nsDialogsPage
.
.
.
Function .onInit
!define MUI_LANGDLL_ALWAYSSHOW
!insertmacro MUI_LANGDLL_DISPLAY
SetShellVarContext all
!insertmacro VerifyUserIsAdmin
FunctionEnd
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
SetShellVarContext all
SetRebootFlag true
MessageBox MB_OKCANCEL "Are you sure you want to uninstall
${APPNAME}?" IDOK next
Abort
next:
!insertmacro VerifyUserIsAdmin
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed
from your computer."
FunctionEnd
Function Repair
Call .onInit
FunctionEnd
Function Remove
ExecWait "$INSTDIR\Uninstall.exe"
FunctionEnd
Function checkinstall
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
"UninstallString"
IfFileExists $R0 +1 NotInstalled
Call nsDialogsPage
NotInstalled:
FunctionEnd
Function nsDialogsPage
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 Repair
${NSD_CreateRadioButton} 0 25u 100% 56u "Remove"
Pop $hwnd
${NSD_OnClick} $hwnd Remove
nsDialogs::Show
FunctionEnd
I can not call nsdialogs correctly. checkinstall function not working at all.I need a correct solution for that.
You are writing the uninstall command to the registry with quotes (correct) but you are not removing the quotes when reading the value so the file exists test is always going to be false.
You should remove the quotes from commands you read from the registry:
Function GetAppFromCommand
Exch $1
Push $2
Push $3
StrCpy $3 ""
StrCpy $2 $1 1
StrCmp $2 '"' qloop sloop
sloop:
StrCpy $2 $1 1 $3
IntOp $3 $3 + 1
StrCmp $2 "" +2
StrCmp $2 ' ' 0 sloop
IntOp $3 $3 - 1
Goto done
qloop:
StrCmp $3 "" 0 +2
StrCpy $1 $1 "" 1 ; Remove initial quote
IntOp $3 $3 + 1
StrCpy $2 $1 1 $3
StrCmp $2 "" +2
StrCmp $2 '"' 0 qloop
done:
StrCpy $1 $1 $3
Pop $3
Pop $2
Exch $1
FunctionEnd
!macro GetAppFromCommand cmd outvar
Push `${cmd}`
Call GetAppFromCommand
Pop ${outvar}
!macroend
Function checkinstall
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
"UninstallString"
!insertmacro GetAppFromCommand $R0 $R0
IfFileExists $R0 +1 NotInstalled
Call nsDialogsPage
NotInstalled:
FunctionEnd

NSIS window disappear

I have tried a lot of possibility with this code but it doesn't work. I need to check a VPN connection. If I run the code firs time it works, but if I don't restart the program and push the button secondly then the program just disappear. Any idea how to fix it? thanks.
Function VpnLoginWindow
${Do}
!insertmacro VpnLoginWindow
StrCpy $4 0
${If} $3 == 1
${Do}
!insertmacro VpnLoginWindow
StrCpy $4 1
StrCmp $3 "0" 0 +2
${ExitDo}
${Loop}
${EndIf}
${If} $4 == 1
${ExitDo}
${EndIf}
${Loop}
FunctionEnd
!macro VpnLoginWindow
StrCpy $5 $1
System::Get "(i.r1) iss"
Pop $R0
System::Call "user32::EnumWindows(k R0, i) i.s"
${Do}
Pop $0
StrCmp $0 "1" 0 +2
${ExitDo}
System::Call "user32::GetWindowText(ir1,t.r2,i ${NSIS_MAX_STRLEN})"
StrCpy $2 $2 7
StrCpy $3 0
${If} $2 == "SSL VPN"
StrCpy $3 1
${ExitDo}
${EndIf}
Push 1 # callback's return value
System::Call "$R0"
${Loop}
System::Free $R0
StrCpy $1 $5
!macroend
Callbacks are tricky to get right and the plug-in is a little buggy. Also, you should not use relative jumps to jump over macros like ${ExitDo}!
!include LogicLib.nsh
!macro FindVpnLoginWindow
Push "" ; Result: Window not found
System::Store S
System::Get '(p.r1, p)ir0r0'
Pop $9
System::Call 'USER32::EnumWindows(k r9, p 0)'
${Do}
${IfThen} $0 != "callback1" ${|} ${ExitDo} ${|} ; <-- adjust the callback# if required
StrCpy $0 1 ; Set callback return value, continue search
System::Call "USER32::GetWindowText(pr1, t.r2, i ${NSIS_MAX_STRLEN})"
StrCpy $2 $2 7
${If} $2 == "SSL VPN"
Pop $2 ; Throw away old result
Push $1 ; Result: HWND
StrCpy $0 0 ; Set callback return value, stop enum with 0
${EndIf}
System::Call $9 ; Return from callback function
${Loop}
System::Free $9
System::Store L
!macroend
Function BackgroundFindWindow
!insertmacro FindVpnLoginWindow
Pop $0
DetailPrint "Result:$0"
FunctionEnd
...
GetFunctionAddress $0 BackgroundFindWindow
BgWorker::CallAndWait
GetFunctionAddress $0 BackgroundFindWindow
BgWorker::CallAndWait

NSIS example of auto-update the installer itself?

I am looking for a NSIS example that is able to update itself with the latest version of the installer.
The logic is simple: check if the publish URL is newer than the current executable and download it and recall itself with the same parameters.
Mainly that's would me something like "wget --timestamp URL" but so far I wasn't able to find any NSIS file download extension that is able to download a file only if is newer.
INetC::head will grab just the HTTP headers from the server but IMHO downloading a .ini file with version info from the server is better...
Here's something I wrote that might be of help to you. I have not tested this thoroughly but it did work on the first couple tests I ran. This is just an example I threw together for a project I'm working on. Hope it's of use to you. =)
VersionCompare Function
;=#
;= Taken and modified from:
;= http://nsis.sourceforge.net/VersionCompare
Function VersionCompare
!define VersionCompare `!insertmacro _VersionCompare`
!macro _VersionCompare _VER1 _VER2 _RESULT
Push `${_VER1}`
Push `${_VER2}`
Call VersionCompare
Pop ${_RESULT}
!macroend
Exch $1
Exch
Exch $0
Exch
Push $2
Push $3
Push $4
Push $5
Push $6
Push $7
BEGIN:
StrCpy $2 -1
IntOp $2 $2 + 1
StrCpy $3 $0 1 $2
StrCmp $3 '' +2
StrCmp $3 '.' 0 -3
StrCpy $4 $0 $2
IntOp $2 $2 + 1
StrCpy $0 $0 '' $2
StrCpy $2 -1
IntOp $2 $2 + 1
StrCpy $3 $1 1 $2
StrCmp $3 '' +2
StrCmp $3 '.' 0 -3
StrCpy $5 $1 $2
IntOp $2 $2 + 1
StrCpy $1 $1 '' $2
StrCmp $4$5 '' EQUAL
StrCpy $6 -1
IntOp $6 $6 + 1
StrCpy $3 $4 1 $6
StrCmp $3 '0' -2
StrCmp $3 '' 0 +2
StrCpy $4 0
StrCpy $7 -1
IntOp $7 $7 + 1
StrCpy $3 $5 1 $7
StrCmp $3 '0' -2
StrCmp $3 '' 0 +2
StrCpy $5 0
StrCmp $4 0 0 +2
StrCmp $5 0 BEGIN NEWER2
StrCmp $5 0 NEWER1
IntCmp $6 $7 0 NEWER1 NEWER2
StrCpy $4 '1$4'
StrCpy $5 '1$5'
IntCmp $4 $5 BEGIN NEWER2 NEWER1
EQUAL:
StrCpy $0 0
Goto FINISH
NEWER1:
StrCpy $0 1
Goto FINISH
NEWER2:
StrCpy $0 2
FINISH:
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd
UpdateCheck Function
;=#
;= Author: demon.devin
;= http://softables.tk/
Function UpdateCheck
!define UpdateCheck `!insertmacro _UpdateCheck`
!macro _UpdateCheck _NAME _LINK _URL _VERSION
Push `${_URL}`
Push `${_VERSION}`
Call UpdateCheck
Pop `${_NAME}`
Pop `${_LINK}`
!macroend
Exch $1
Exch
Exch $0
Push $0
Push $1
DetailPrint "Current Version: $1"
GetTempFileName $R1
NSISdl::download $0 $R1
ReadINIStr $R0 "$R1" "PAFInfo" "Version"
DetailPrint "Latest Version: $R0"
${VersionCompare} $1 $R0 $R4
${If} $R4 == 0
${OrIf} $R4 == 1
ReadINIStr $R3 "$R1" "PAFInfo" "Name"
StrCpy $File `$R3`
StrCpy $R2 ""
StrCpy $Link ``
${Else}
ReadINIStr $R2 "$R1" "PAFInfo" "DownloadLink"
StrCpy $Link `$R2`
ReadINIStr $R3 "$R1" "PAFInfo" "Filename"
StrCpy $File `$R3`
${EndIf}
SetDetailsPrint none
Delete $R1
SetDetailsPrint lastused
Pop $1
Pop $0
Exch $R2
Exch
Exch $R3
FunctionEnd
WGetDownload Function
;=#
;= Author: demon.devin
;= http://softables.tk/
Function WGetDownload
!define WGetDownload "!insertmacro _WGetDownload"
!macro _WGetDownload _RETURN _TEMPFILE _URL _FILENAME
Push ${_URL}
Push ${_FILENAME}
Call WGetDownload
Pop ${_TEMPFILE}
Pop ${_RETURN}
!macroend
Exch $1
Exch
Exch $2
Push $1
Push $2
!define WGET `$PLUGINSDIR\wget.exe`
!define WGETCMD `"${WGET}" --html-extension --referer="http://www.google.com" --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" -T 10 --no-check-certificate "$Link" --output-document=$File`
MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Package: $File$\r$\nLink: $Link$\r$\n$\r$\nClick OK to start download."
DetailPrint "Downloading: $Link"
SetOutPath `$PLUGINSDIR`
File `${NSISDIR}\Contrib\7zip\wget.exe`
WGET:
SetOutPath `$PLUGINSDIR`
ExecDos::Exec /TOSTACK `${WGETCMD}`
Pop $0
Pop $1
${If} $0 = 1
StrCmp $2 1 +3
StrCpy $2 1
Goto WGET
Goto FAIL
${EndIf}
${If} ${FileExists} "$PLUGINSDIR\$File"
ClearErrors
StrCpy $R5 true
StrCpy $R7 "$PLUGINSDIR\$File"
${GetSize} "$PLUGINSDIR" "/M=$File /S=0K" $0 $1 $2
IfErrors 0 +2
StrCpy $0 $0 * 1024
IntCmp $0 100 +3 0 +3
IntCmp $0 0 +2 +2 0
IntOp $0 103 + 0
IntOp $0 $0 * 10
IntOp $0 $0 / 1024
StrCpy $1 "$0" "" -1
IntCmp $0 9 +3 +3 0
StrCpy $0 "$0" -1 ""
Goto +2
StrCpy $0 "0"
MessageBox MB_OK|MB_USERICON|MB_TOPMOST "Your file $File was successfully downloaded! ($0.$1 MiB)"
Goto DONE
${Else}
FAIL:
StrCpy $R5 "Your file $File has failed to download using the WGet utility!"
Goto CANCEL
${EndIf}
CANCEL:
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "ERROR!$\r$\n$\r$\n$R5"
StrCpy $R5 false
StrCpy $R7 ""
SetErrors
DONE:
Pop $2
Pop $1
Exch $R5
Exch
Exch $R7
FunctionEnd
OpenWebPage Macro
;=#
;= Author: demon.devin
;= http://softables.tk/
!define OpenWebPage '!insertmacro "_OpenWebPage"'
!macro _OpenWebPage _URL
ExecShell open "${_URL}"
!macroend
EXAMPLE USAGE:
;=#
;= Author: demon.devin
;= More NSIS help:
;= http://softables.tk/docs
Section "MAIN"
ClearErrors
MessageBox MB_USERICON|MB_YESNO|MB_TOPMOST `Would you like to check for any possible upgrades?` IDYES CHECK IDNO NOCHECK
NOCHECK:
DetailPrint "What?! How can you improve if you don't check for upgrades?"
Goto DONE
CHECK:
DetailPrint "Checking for new version..."
${UpdateCheck} $0 $1 "http://softables.tk/repository/docs/manifests.ini" "6.25.11.0"
StrCmp $1 "" 0 +5
DetailPrint "You have the most recent version..."
MessageBox MB_USERICON|MB_OK|MB_TOPMOST `$0 is up to date!`
DetailPrint "Continuing with the rest of the operation..."
Goto DONE
DetailPrint "There's a new version available..."
MessageBox MB_ICONEXCLAMATION|MB_YESNO|MB_TOPMOST "New version of $File available.$\r$\nDownload now?" IDYES YES IDNO NO
NO:
DetailPrint "Fine! Stick with the old stuff. See if I care..."
Goto DONE
YES:
DetailPrint "Great! Downloading new updates now..."
${WGetDownload} $R0 $R1 "$Link" "$File"
${If} $R0 == true
${AndIf} $R1 != ""
DetailPrint "Downloaded: $R1"
DetailPrint "Awesome! The download was successful..."
CopyFiles /SILENT `$R1` `$INSTDIR\WGET\$R1`
DetailPrint "Extracting the contents now..."
File '/oname=$PLUGINSDIR\7z.dll' `${NSISDIR}\Contrib\7zip\7z.dll`
File '/oname=$PLUGINSDIR\7z.exe' `${NSISDIR}\Contrib\7zip\7z.exe`
ExecDos::Exec /TOSTACK `"$PLUGINSDIR\7z.exe" x "$R1" -o"$INSTDIR" -aoa -y` "" ""
Pop $0
DetailPrint "All done! Cleaning up temporary files..."
Delete `$R1`
DetailPrint "Finished. Enjoy..."
${Else}
DetailPrint "Something went wrong! The download was unsuccessful..."
MessageBox MB_ICONEXCLAMATION|MB_YESNO|MB_TOPMOST "You can manually download the upgrades by visiting:$\r$\n$Link$\r$\n$\r$\nGo there now?" IDYES WEB IDNO DONE
WEB:
DetailPrint "Launching web page now... "
SetDetailsPrint none
${OpenWebPage} "$Link"
SetDetailsPrint lastused
${EndIf}
DONE:
DetailPrint "Moving right along..."
SectionEnd

Display of product versions?

My product has version w.x.y.z. My upgrade of that product has w.x.y.z+1. But the requirement is that before upgrade the fourth field of the version i.e; z should not be checked...i.e; myproduct should not take into consideration the z field.....Please do reply me with an answer.
You can read you App Version from registry and keep it as Variable, then trim it to specific number of chars. Check http://nsis.sourceforge.net/TrimText:_Trim_text_e.g._to_fit_in_a_label
Script below is will work for ANSI NSIS if you have such version installed if not, please change ReadRegStr accordingly.
Name "TrimTest"
OutFile "TrimTest.exe"
!include "TextFunc.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "WordFunc.nsh"
!insertmacro VersionCompare
Function TrimText
Exch $R0 ; char
Exch
Exch $R1 ; length
Exch 2
Exch $R2 ; text
Push $R3
Push $R4
StrLen $R3 $R2
IntCmp $R3 $R1 Done Done
StrCpy $R2 $R2 $R1
StrCpy $R3 0
IntOp $R3 $R3 + 1
StrCpy $R4 $R2 1 -$R3
StrCmp $R4 "" Done
StrCmp $R4 $R0 0 -3
IntOp $R3 $R3 + 1
StrCpy $R4 $R2 1 -$R3
StrCmp $R4 "" Done
StrCmp $R4 $R0 -3
IntOp $R3 $R3 - 1
StrCpy $R2 $R2 -$R3
StrCpy $R2 $R2
Done:
StrCpy $R0 $R2
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0 ; output
FunctionEnd
!macro TrimText Text Length Char Var
Push "${Text}"
Push "${Length}"
Push "${Char}"
Call TrimText
Pop "${Var}"
!macroend
!define TrimText "!insertmacro TrimText"
Section
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NSIS ANSI" "DisplayVersion"
${TrimText} $0 7 "-" $R0
;set max lenght to 7, where only 6 chars are needed, as trimmer will stop on - char
;in your case you will probably want to trim to first . from right side
;${TrimText} "string" "max_length" "up_to_char" "$out_var"
MessageBox MB_ICONEXCLAMATION "Line: $R0"
;Input $0 from registry should be "2.46.4-ANSI" if the latest ANSI NSIS is installed
;$R0 after trimm will be "Line: 2.46.4"
${VersionCompare} $R0 "2.46.6" $R2
${If} $R2 == 1 ;if 2.46.6 is lower that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is newer than this version of update"
${EndIf}
${If} $R2 == 0 ;versions are equal
MessageBox MB_ICONEXCLAMATION "Your App Version is equal to this version of update"
${EndIf}
${If} $R2 == 2 ;if 2.46.6 is higher that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is older and will be updated"
;here you can write your update section
${EndIf}
SectionEnd
In this case this can be a solution (based on http://nsis.sourceforge.net/Sort_String_2).
I have created Test Registry Key just for check with your {3.1.123 4.0.112 4.1.119}. Please replace with the one your application uses.
Name "TrimTest2"
OutFile "TrimTest2.exe"
!include "TextFunc.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "WordFunc.nsh"
!insertmacro VersionCompare
Function AdvStrSort
Exch $0 ; input string
Exch
Exch $1 ; count to get part
Exch
Exch 2
Exch $2 ; get ammount of chunks from end
Exch 2
Push $3
Push $4
Push $5
Push $6
Push $7
StrCpy $0 " $0"
StrCpy $3 0
StrCpy $4 0
loop:
IntOp $3 $3 - 1
StrCpy $6 $0 1 $3
StrCmp $6 "" skip
StrCmp $6 " " roger ; to change chunk seperators, edit this (" ")
Goto loop
roger:
StrCpy $7 $0 "" $3
IntOp $4 $4 + 1
StrCmp $4 $2 0 loop
StrCmp $1 $2 0 +3
StrCpy $0 $7
Goto end
skip:
StrCpy $4 0
StrLen $5 $7
top:
IntOp $4 $4 + 1
loop2:
IntOp $5 $5 - 1
StrCpy $3 $7 1 -$5
StrCmp $3 "" end
StrCmp $3 " " 0 loop2 ; to change chunk seperators, edit this too (" ")
StrCmp $4 $1 0 top
StrCpy $0 $7 -$5
end:
StrLen $1 $0
IntOp $1 $1 - 1
StrCpy $0 $0 $1 -$1
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0 ; output string
FunctionEnd
Section
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\UserApplicationName" "Version"
Push 1 ; get text after 1st chunk from string end
Push 1 ; get 1 chunk before the 1st
Push "$R1" ; input string (string that has spaces)
Call AdvStrSort
Pop $R0
MessageBox MB_ICONEXCLAMATION "Result: $R0"
${VersionCompare} $R0 "5.0.114" $R2
;MessageBox MB_ICONEXCLAMATION "Result: $R2"
${If} $R2 == 1 ;if 5.0.114 is lower that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is newer than this version of update"
${EndIf}
${If} $R2 == 0 ;versions are equal
MessageBox MB_ICONEXCLAMATION "Your App Version is equal to this version of update"
${EndIf}
${If} $R2 == 2 ;if 5.0.114 is higher that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is older and will be updated"
;here you can write your update section
${EndIf}
SectionEnd

Resources