2004-01-08 21:26:02 +00:00
; NSIS Update
;--------------------------------
; Original version Copyright (C) 2002-2003 Nathan Purciful.
2005-01-04 14:54:48 +00:00
; Version for NSIS distribution Copyright (C) 2003-2005 Joost Verburg.
2004-01-08 21:26:02 +00:00
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any
; damages arising from the use of this software.
;
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute
; it freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must
; not claim that you wrote the original software. If you use this
; software in a product, an acknowledgment in the product
; documentation would be appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must
; not be misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source
; distribution.
;
; This program uses CVSNT software, http://www.cvsnt.org/
;--------------------------------
;Header files
!include " MUI.nsh "
!addplugindir " ${NSISDIR} \Contrib\NSIS Update "
;--------------------------------
;Configuration
Name " NSIS Update "
Caption " NSIS Update "
OutFile " ..\..\Bin\NSISUpdate.exe "
BrandingText " "
InstallButtonText " Update "
ShowInstDetails show
InstallColors /windows
;--------------------------------
;Variables
Var TEMP1
Var TEMP2
Var TEMP3
Var MISSINGFILES
Var NSISBINPATH
Var OUTDIRFULL
;--------------------------------
;Interface Settings
!define MUI_ICON " ${NSISDIR} \Contrib\Graphics\Icons\arrow2-install.ico "
;--------------------------------
;Pages
Page custom UpdateMethod UpdateLeave
!define MUI_PAGE_HEADER_TEXT " "
!define MUI_PAGE_HEADER_SUBTEXT " "
!define MUI_INSTFILESPAGE_FINISHHEADER_TEXT " Task Completed "
!define MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT " See the log window below for details. "
!define MUI_INSTFILESPAGE_ABORTHEADER_TEXT " Error "
!define MUI_INSTFILESPAGE_ABORTHEADER_SUBTEXT " NSIS Update was not completed succesfully. "
!insertmacro MUI_PAGE_INSTFILES
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE " English "
;--------------------------------
;Custom Interface
ChangeUI IDD_INSTFILES " UI.exe "
;--------------------------------
;Macros
2003-02-18 20:20:01 +00:00
!macro checkFile PATH FILE
IfFileExists " ${PATH}\${FILE} " + 2
2004-01-08 21:26:02 +00:00
StrCpy $MISSINGFILES " ${FILE} $MISSINGFILES "
2003-02-18 20:20:01 +00:00
!macroend
!macro checkFileDownload PATH FILE
IfFileExists " ${PATH}\${FILE} " " Done_${FILE} "
2003-04-02 20:29:05 +00:00
NSISdl :: download " http://nsis.sourceforge.net/nsisupdate/${FILE}.dat " " ${PATH}\${FILE}.dat "
2004-01-08 21:26:02 +00:00
Pop $TEMP 1
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 1 " success " " Extract_${FILE} "
MessageBox MB_OK | MB_ICONSTOP " Download failed: $TEMP1. "
2003-02-18 20:20:01 +00:00
Quit
" Extract_${FILE}: "
2003-04-02 20:29:05 +00:00
ExtractDLL :: extract " ${PATH}\${FILE} " " ${PATH}\${FILE}.dat "
Delete " ${PATH}\${FILE}.dat "
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
Pop $TEMP 1
StrCmp $TEMP 1 " success " + 3
MessageBox MB_OK | MB_ICONSTOP " Extraction failed: $TEMP1. "
2003-02-18 20:20:01 +00:00
Quit
2003-04-02 20:29:05 +00:00
2003-02-18 20:20:01 +00:00
" Done_${FILE}: "
!macroend
2004-01-08 21:26:02 +00:00
;--------------------------------
; Functions
2003-02-18 20:20:01 +00:00
Function .onInit
2004-01-08 21:26:02 +00:00
2003-11-19 17:40:27 +00:00
System :: Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1'
2003-02-18 21:11:09 +00:00
2004-01-08 21:26:02 +00:00
StrCpy $R0 $R0 " " - 14
StrCmp $R0 " NSISUpdate.bin " temp
2003-02-18 21:11:09 +00:00
2004-01-08 21:26:02 +00:00
;Create a temporary file, so NSIS Update can update itself
2003-02-18 21:11:09 +00:00
2003-02-20 18:43:31 +00:00
CopyFiles /SILENT " $EXEDIR \NSISUpdate.exe " " $TEMP \NSISUpdate.bin "
2003-02-21 21:38:45 +00:00
Exec '"$TEMP\NSISUpdate.bin" $EXEDIR'
2003-02-18 21:11:09 +00:00
Quit
temp :
2003-04-02 20:29:05 +00:00
2004-01-08 21:26:02 +00:00
;Close the NSIS Menu (files in use cannot be updated)
2003-02-21 19:29:04 +00:00
Call CloseMenu
2004-01-08 21:26:02 +00:00
;Remove temporary file on next reboot
2003-02-20 18:43:31 +00:00
Delete /REBOOTOK " $TEMP \NSISUpdate.bin "
2004-01-08 21:26:02 +00:00
;Get NSIS directory
2003-02-20 18:43:31 +00:00
Call GetParameters
2004-01-08 21:26:02 +00:00
Pop $NSISBINPATH
;InstallOptions INI File for the "Update Method" dialog
!insertmacro MUI_INSTALLOPTIONS_EXTRACT " Method.ini "
;Check for pserver CVS access
IfFileExists " $NSISBINPATH \..\Cvs\Root " 0 done
FileOpen $TEMP 1 " $NSISBINPATH \..\CVS\Root " r
FileRead $TEMP 1 $TEMP 2 9
FileClose $TEMP 1
2003-02-18 21:11:09 +00:00
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 2 " :pserver: " done
2003-02-18 21:11:09 +00:00
2004-01-08 21:26:02 +00:00
!insertmacro MUI_INSTALLOPTIONS_WRITE " Method.ini " " Field 2 " " Flags " " DISABLED "
!insertmacro MUI_INSTALLOPTIONS_WRITE " Method.ini " " Field 3 " " Flags " " DISABLED "
!insertmacro MUI_INSTALLOPTIONS_WRITE " Method.ini " " Field 5 " " Flags " " DISABLED "
!insertmacro MUI_INSTALLOPTIONS_WRITE " Method.ini " " Field 6 " " Flags " " DISABLED "
done :
2003-02-18 20:20:01 +00:00
FunctionEnd
2004-01-08 21:26:02 +00:00
Function UpdateMethod
!insertmacro MUI_HEADER_TEXT " Update Method " " Please select how you would like to update your NSIS files. "
!insertmacro MUI_INSTALLOPTIONS_DISPLAY " Method.ini "
FunctionEnd
Function UpdateLeave
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP 1 " Method.ini " " Field 1 " " State "
StrCmp $TEMP 1 " 1 " nocvs
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrCpy $MISSINGFILES " "
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
Call CheckCVSData
Call CheckCVSFiles
Call CheckCVSDownload
nocvs :
2003-02-18 20:20:01 +00:00
FunctionEnd
Function CheckCVSFiles
2004-01-08 21:26:02 +00:00
!insertmacro checkFile " $NSISBINPATH " " cvs95.exe "
2003-02-18 20:20:01 +00:00
!insertmacro checkFile " $SYSDIR " " msvcr70.dll "
!insertmacro checkFile " $SYSDIR " " msvcp70.dll "
2004-01-08 21:26:02 +00:00
!insertmacro checkFile " $NSISBINPATH " " pserver_protocol.dll "
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrCmp $MISSINGFILES " " done
MessageBox MB_YESNO | MB_ICONQUESTION " NSIS update has to download a few small CVS client files in order to be able to update your NSIS files.$\r$\nThese files only have to be download once. Do you want to download them now?$\r$\n$\r$\nRequired Files: $MISSINGFILES " IDYES Done
Abort
2003-02-18 20:20:01 +00:00
done :
FunctionEnd
Function CheckCVSDownload
2004-01-08 21:26:02 +00:00
StrCmp $MISSINGFILES " " done
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
!insertmacro MUI_HEADER_TEXT " Downloading... " " Please wait while NSIS Update downloads CVS client files. "
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
!insertmacro checkFileDownload " $NSISBINPATH " " cvs95.exe "
2003-02-18 20:20:01 +00:00
!insertmacro checkFileDownload " $SYSDIR " " msvcr70.dll "
!insertmacro checkFileDownload " $SYSDIR " " msvcp70.dll "
2004-01-08 21:26:02 +00:00
!insertmacro checkFileDownload " $NSISBINPATH " " pserver_protocol.dll "
2003-02-18 20:20:01 +00:00
done :
FunctionEnd
Function CheckCVSData
2004-01-08 21:26:02 +00:00
IfFileExists " $NSISBINPATH \..\CVS\Root " datainstalled
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
IfFileExists " $NSISBINPATH \InstallCVSData.exe " + 3
2003-02-18 20:20:01 +00:00
MessageBox MB_OK | MB_ICONSTOP " CVS Data Setup not found. "
2004-01-08 21:26:02 +00:00
Abort
2003-02-18 20:20:01 +00:00
SetDetailsPrint listonly
DetailPrint " Installing CVS data... "
SetDetailsPrint none
2004-01-08 21:26:02 +00:00
Exec " $NSISBINPATH \InstallCVSData.exe "
2003-02-18 20:20:01 +00:00
datainstalled :
FunctionEnd
2003-11-19 17:40:27 +00:00
Function GetParameters
2003-02-20 18:43:31 +00:00
2003-11-19 17:40:27 +00:00
Push $R0
Push $R1
Push $R2
Push $R3
2003-02-20 18:43:31 +00:00
2003-11-19 17:40:27 +00:00
StrCpy $R2 1
StrLen $R3 $CMDLINE
;Check for quote or space
StrCpy $R0 $CMDLINE $R2
StrCmp $R0 '"' 0 + 3
StrCpy $R1 '"'
Goto loop
StrCpy $R1 " "
loop :
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 $R1 get
StrCmp $R2 $R3 get
Goto loop
get :
IntOp $R2 $R2 + 1
StrCpy $R0 $CMDLINE 1 $R2
StrCmp $R0 " " get
StrCpy $R0 $CMDLINE " " $R2
Pop $R3
Pop $R2
Pop $R1
Exch $R0
2003-02-20 18:43:31 +00:00
FunctionEnd
2003-02-21 19:29:04 +00:00
Function CloseMenu
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
FindWindow $TEMP 1 " NSIS Menu "
IntCmp $TEMP 1 0 + 2
SendMessage $TEMP 1 ${WM_CLOSE} 0 0
2003-02-19 21:12:06 +00:00
2003-02-21 19:29:04 +00:00
FunctionEnd
Function ConnectInternet
2003-03-18 10:11:16 +00:00
Push $R0
2003-02-19 21:12:06 +00:00
2003-03-18 10:11:16 +00:00
ClearErrors
Dialer :: AttemptConnect
IfErrors noie3
2003-02-19 21:12:06 +00:00
2003-03-18 10:11:16 +00:00
Pop $R0
StrCmp $R0 " online " connected
MessageBox MB_OK | MB_ICONSTOP " Cannot connect to the internet. "
Quit
noie3 :
2003-02-19 21:12:06 +00:00
2004-01-08 21:26:02 +00:00
; IE3 not installed
2003-03-18 10:11:16 +00:00
MessageBox MB_OK | MB_ICONINFORMATION " Please connect to the internet now. "
connected :
2003-02-19 21:12:06 +00:00
2003-03-18 10:11:16 +00:00
Pop $R0
2003-02-21 19:29:04 +00:00
FunctionEnd
2003-06-03 11:51:50 +00:00
Function TrimNewlines
Exch $R0
Push $R1
Push $R2
StrCpy $R1 0
loop :
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 $R1
StrCmp $R2 " $\r " loop
StrCmp $R2 " $\n " loop
IntOp $R1 $R1 + 1
IntCmp $R1 0 no_trim_needed
StrCpy $R0 $R0 $R1
no_trim_needed :
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
Function FindFiles
2004-01-08 21:26:02 +00:00
Exch $R5 ; callback function
2003-06-03 11:51:50 +00:00
Exch
2004-01-08 21:26:02 +00:00
Exch $R4 ; file name
2003-06-03 11:51:50 +00:00
Exch 2
2004-01-08 21:26:02 +00:00
Exch $R0 ; directory
2003-06-03 11:51:50 +00:00
Push $R1
Push $R2
Push $R3
Push $R6
2004-01-08 21:26:02 +00:00
Push $R0 ; first dir to search
2003-06-03 11:51:50 +00:00
StrCpy $R3 1
nextDir :
Pop $R0
IntOp $R3 $R3 - 1
ClearErrors
FindFirst $R1 $R2 " $R0 \*.* "
nextFile :
StrCmp $R2 " . " gotoNextFile
StrCmp $R2 " .. " gotoNextFile
StrCmp $R2 $R4 0 isDir
Push " $R0 \$R2 "
Call $R5
Pop $R6
StrCmp $R6 " stop " 0 isDir
loop :
StrCmp $R3 0 done
Pop $R0
IntOp $R3 $R3 - 1
Goto loop
isDir :
IfFileExists " $R0 \$R2\*.* " 0 gotoNextFile
IntOp $R3 $R3 + 1
Push " $R0 \$R2 "
gotoNextFile :
FindNext $R1 $R2
IfErrors 0 nextFile
done :
FindClose $R1
StrCmp $R3 0 0 nextDir
Pop $R6
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $R5
Pop $R4
FunctionEnd
!macro CallFindFiles DIR FILE CBFUNC
2004-01-08 21:26:02 +00:00
Push ${DIR}
Push ${FILE}
GetFunctionAddress $TEMP 1 ${CBFUNC}
Push $TEMP 1
Call FindFiles
2003-06-03 11:51:50 +00:00
!macroend
Function PatchCVSRoot
2004-01-08 21:26:02 +00:00
Pop $TEMP 1
FileOpen $TEMP 2 $TEMP 1 " r "
FileRead $TEMP 2 $TEMP 3
2004-07-08 18:39:20 +00:00
FileClose $TEMP 2
2004-01-08 21:26:02 +00:00
Push $TEMP 3
2003-06-03 11:51:50 +00:00
Call TrimNewLines
2004-01-08 21:26:02 +00:00
Pop $TEMP 3
2004-06-01 12:29:46 +00:00
StrCmp $TEMP 3 " :pserver:anonymous:@cvs1:/cvsroot/nsis " go
2004-06-04 11:49:02 +00:00
StrCmp $TEMP 3 " :pserver:anonymous@cvs1:/cvsroot/nsis " go
2003-06-03 11:51:50 +00:00
Push " stop "
Return
go :
2004-07-08 18:39:20 +00:00
FileOpen $TEMP 2 $TEMP 1 " w "
2004-01-08 21:26:02 +00:00
FileWrite $TEMP 2 " :pserver:anonymous:@cvs.sourceforge.net:/cvsroot/nsis$\r$\n "
FileClose $TEMP 2
2003-06-03 11:51:50 +00:00
Push " go "
FunctionEnd
2004-01-08 21:26:02 +00:00
;--------------------------------
; Update (Installer Section)
2003-02-21 19:29:04 +00:00
Section " "
SetDetailsPrint none
Call ConnectInternet
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP 1 " Method.ini " " Field 1 " " State "
StrCmp $TEMP 1 " 1 " 0 CVS
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
;Check for a new release
2003-02-18 20:20:01 +00:00
SetDetailsPrint listonly
2004-01-08 21:26:02 +00:00
!insertmacro MUI_HEADER_TEXT " Checking for a release... " " Please wait while NSIS Update checks whether a new NSIS release is available. "
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
nsExec :: ExecToStack '"$NSISBINPATH\..\makensis.exe" "/version"'
Pop $TEMP 1
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 1 " error " " " + 3
2003-02-18 20:20:01 +00:00
MessageBox MB_OK | MB_ICONSTOP " Can't get NSIS version. "
Quit
2004-01-08 21:26:02 +00:00
Pop $TEMP 1
DetailPrint " Your NSIS version: $TEMP1 "
2003-02-18 20:20:01 +00:00
DetailPrint " "
2004-01-08 21:26:02 +00:00
StrCpy $TEMP 2 $TEMP 1 " " - 5
StrCmp $TEMP 2 " (CVS) " " " NoCVSVersion
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrLen $TEMP 2 $TEMP 1
IntOp $TEMP 2 $TEMP 2 - 6
StrCpy $TEMP 1 $TEMP 1 $TEMP 2
StrCpy $TEMP 2 1
2003-02-18 20:20:01 +00:00
DetailPrint " NOTE: You are using a development version of NSIS. "
2003-11-19 17:40:27 +00:00
DetailPrint " You can also use NSIS Update to get the latest development files. "
2003-02-18 20:20:01 +00:00
DetailPrint " "
Goto CheckUpdate
NoCVSVersion :
2004-01-08 21:26:02 +00:00
StrCpy $TEMP 2 0
2003-02-18 20:20:01 +00:00
CheckUpdate :
DetailPrint " Checking for a new release... "
DetailPrint " "
2004-01-08 21:26:02 +00:00
NSISdl : : download_quiet " http://nsis.sourceforge.net/update.php?version=$TEMP1&cvs=$TEMP2 " " $PLUGINSDIR \Update "
Pop $TEMP 1
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 1 " success " ReadVersion
MessageBox MB_OK | MB_ICONSTOP " Download failed: $TEMP1. "
2003-02-18 20:20:01 +00:00
Quit
ReadVersion :
2004-01-08 21:26:02 +00:00
FileOpen $TEMP 1 " $PLUGINSDIR \Update " r
FileRead $TEMP 1 $TEMP 2
FileClose $TEMP 1
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 2 " " " " + 3
2003-02-18 20:20:01 +00:00
MessageBox MB_OK | MB_ICONSTOP " Invalid version data. "
Quit
2004-01-08 21:26:02 +00:00
StrCpy $TEMP 1 $TEMP 2 1
StrCpy $TEMP 2 $TEMP 2 " " 2
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 1 " 1 " " " + 3
DetailPrint " A new stable release is available: $TEMP2 "
2003-02-18 20:20:01 +00:00
Goto UpdateMsg
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 1 " 2 " " " + 3
DetailPrint " A new pre-release is available: $TEMP2 "
2003-02-18 20:20:01 +00:00
Goto UpdateMsg
2004-01-08 21:26:02 +00:00
DetailPrint " No new release is available. Please check again later. "
2003-02-18 20:20:01 +00:00
Goto done
UpdateMsg :
MessageBox MB_YESNO | MB_ICONQUESTION " A new release is available. Would you like to go to the download page? " IDNO done
SetDetailsPrint none
2004-01-26 16:33:40 +00:00
ExecShell " open " " http://nsis.sourceforge.net/download/ "
2003-02-18 20:20:01 +00:00
Goto done
CVS :
2004-01-08 21:26:02 +00:00
;CVS Update
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
SetOutPath $NSISBINPATH \ ..
;patch CVS Root files that come from the development snapshot
GetFullPathName $OUTDIR FULL $OUTDIR
!insertmacro CallFindFiles $OUTDIR FULL Root PatchCVSRoot
2003-06-03 11:51:50 +00:00
2003-02-18 20:20:01 +00:00
SetDetailsPrint listonly
2004-01-08 21:26:02 +00:00
!insertmacro MUI_HEADER_TEXT " Updating... " " Please wait while NSIS Update is downloading development files. This may take several minutes to complete. "
2003-02-18 20:20:01 +00:00
DetailPrint " Initializing CVS Update... "
2004-01-08 21:26:02 +00:00
!insertmacro MUI_INSTALLOPTIONS_READ $TEMP 1 " Method.ini " " Field 2 " " State "
StrCmp $TEMP 1 " 1 " 0 CleanCVSUpdate
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
;Normal update
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
nsExec :: ExecToLog '"$NSISBINPATH\cvs95.exe" -q -z3 update -d -P'
Pop $TEMP 1
2003-02-18 20:20:01 +00:00
Goto CheckCVSReturn
CleanCVSUpdate :
2004-01-08 21:26:02 +00:00
;Clean copy
2003-02-18 20:20:01 +00:00
2004-01-08 21:26:02 +00:00
nsExec :: ExecToLog '"$NSISBINPATH\cvs95.exe" -q -z3 update -C -d -P'
Pop $TEMP 1
2003-02-18 20:20:01 +00:00
CheckCVSReturn :
2004-01-08 21:26:02 +00:00
StrCmp $TEMP 1 " error " " " + 3
2003-02-18 20:20:01 +00:00
MessageBox MB_OK | MB_ICONSTOP " Can't execute CVS client. "
Quit
2004-01-20 13:01:59 +00:00
DetailPrint " CVS Update Completed "
2004-01-08 21:26:02 +00:00
2003-02-18 20:20:01 +00:00
done :
SetDetailsPrint none
SectionEnd