Rev 2340 | Blame | Compare with Previous | Last modification | View Log | RSS feed
!include "FileFunc.nsh";---------------------------------------------------------------------------------------------------; macro VIX_CREATE_UNINSTALLER_AND_REGISTRY; Creates the uninstaller and creates the registry entries for the uninstaller in the control panel; The macro should be inserted in an install section;; Uninstaller defaults to "$INSTDIR\${GBE_PACKAGE}_Uninstall.exe"; Can be changed by defining VIX_UNISTALL_EXE before inserting macro;; Install registry keys are in HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\${GBE_PACKAGE}; by default but GBE_PACKAGE can be overridden by defining VIX_UNINSTALL_UNIQUE_KEY before inserting macro; If Overriding then the key must be unique to this package;; The following defines are available after this macro is inserted; VIX_UNISTALL_EXE - The uninstaller location, use to remove itself during uninstall; VIX_UNINSTALL_KEY_BASE - The base uninstall registry key in HKLM, this is constant; VIX_UNINSTALL_KEY - The uninstall registry key where all the uninstall values are written;; Example; Section "-Core"; DetailPrint "---- Install -Core section";; ${VIX_CREATE_UNINSTALLER_AND_REGISTRY}; IfErrors 0 +2; Abort "Error creating uninstaller information"; SectionEnd!define VIX_CREATE_UNINSTALLER_AND_REGISTRY `!insertmacro VIX_CREATE_UNINSTALLER_AND_REGISTRY`!macro VIX_CREATE_UNINSTALLER_AND_REGISTRYClearErrors; Default uninstaller exe to "$INSTDIR\${GBE_PACKAGE}_Uninstall.exe"; Can be overridden by defining VIX_UNISTALL_EXE before macro!ifndef VIX_UNISTALL_EXE!define VIX_UNISTALL_EXE "$INSTDIR\${GBE_PACKAGE}_Uninstall.exe"!endifWriteUninstaller ${VIX_UNISTALL_EXE}; This is constant!ifdef VIX_UNINSTALL_KEY_BASE!undef VIX_UNINSTALL_KEY_BASE!endif!define VIX_UNINSTALL_KEY_BASE "Software\Microsoft\Windows\CurrentVersion\Uninstall"; Write the uninstall keys for Windows so that the package is seen in the; Add/Remove Program section of the Control Panel.; Create a 'unique' key in the windows registry; Default to package name ${GBE_PACKAGE}, Could use a GUID but it MUST NOT be copied if this file is copied; Can be overridden by defining VIX_UNINSTALL_UNIQUE_KEY before macro!ifndef VIX_UNINSTALL_UNIQUE_KEY!define VIX_UNINSTALL_UNIQUE_KEY ${GBE_PACKAGE}!endif!define VIX_UNINSTALL_KEY "${VIX_UNINSTALL_KEY_BASE}\${VIX_UNINSTALL_UNIQUE_KEY}"WriteRegStr HKLM ${VIX_UNINSTALL_KEY} "DisplayName" "${GBE_PACKAGE}, ${GBE_VERSION}"WriteRegStr HKLM ${VIX_UNINSTALL_KEY} "DisplayIcon" "${VIX_UNISTALL_EXE}"WriteRegStr HKLM ${VIX_UNINSTALL_KEY} "Version" "${GBE_VERSION}"WriteRegStr HKLM ${VIX_UNINSTALL_KEY} "DisplayVersion" "${GBE_VERSION_FULL}"WriteRegStr HKLM ${VIX_UNINSTALL_KEY} "Publisher" "${GBE_COMPANY}"WriteRegStr HKLM ${VIX_UNINSTALL_KEY} "InstallLocation" "$INSTDIR"WriteRegStr HKLM ${VIX_UNINSTALL_KEY} "UninstallString" '"${VIX_UNISTALL_EXE}"'WriteRegDWORD HKLM ${VIX_UNINSTALL_KEY} "NoModify" 1WriteRegDWORD HKLM ${VIX_UNINSTALL_KEY} "NoRepair" 1!undef VIX_UNINSTALL_UNIQUE_KEY!macroend;---------------------------------------------------------------------------------------------------; macro VIX_REMOVE_UNINSTALLER_AND_REGISTRY; Deletes the uninstaller and registry entries for the uninstaller in the control panel; The macro should be inserted in an uninstall section and must be after the section that calls the; VIX_CREATE_UNINSTALLER_AND_REGISTRY macro above, if not will abort with errors as defines create by; VIX_CREATE_UNINSTALLER_AND_REGISTRY will not be available;; Example, If using same section names as example, this section must appear after Section "-Core"; Section "-un.Core"; DetailPrint "---- Install -Core section"; ${VIX_REMOVE_UNINSTALLER_AND_REGISTRY}; SectionEnd!define VIX_REMOVE_UNINSTALLER_AND_REGISTRY `!insertmacro VIX_REMOVE_UNINSTALLER_AND_REGISTRY`!macro VIX_REMOVE_UNINSTALLER_AND_REGISTRYClearErrors!ifndef VIX_UNISTALL_EXE | VIX_UNINSTALL_KEY!error "The VIX_REMOVE_UNINSTALLER_AND_REGISTRY macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"!endifDelete "${VIX_UNISTALL_EXE}"; Remove Uninstaller registry keysDeleteRegKey HKLM ${VIX_UNINSTALL_KEY}!macroend;---------------------------------------------------------------------------------------------------; macro VIX_CREATE_PACKAGING_REGISTRY; Creates registry entries required by PkgMnt and procmgr in HKLM\SOFTWARE\ERG\AFC\${GBE_PACKAGE}; The macro should be inserted in an install section, usually the same one that calls VIX_CREATE_UNINSTALLER_AND_REGISTRY;; Uses registers $0, $1, $2, $3, $4, $5, $6 without saving them;; The following defines are available after this macro is inserted; VIX_PACKAGING_ROOTKEY - The Root key where VIX_PACKAGING_SUBKEY is rooted; VIX_PACKAGING_SUBKEY - The Registry key where the values are inserted; VIX_PACKAGING_PARAMETERS_SUBKEY - A Subdir of VIX_PACKAGING_SUBKEY that can contain installer parameters; Used by VIX_SAVE_PACKAGING_PARAMETER & VIX_GET_PACKAGING_PARAMETER macros; to save and retrieve installer parameters;; Example; Section "-Core"; DetailPrint "---- Install -Core section";; ${VIX_CREATE_UNINSTALLER_AND_REGISTRY}; IfErrors 0 +2; Abort "Error creating uninstaller information"; $VIX_CREATE_PACKAGING_REGISTRY; IfErrors 0 +2; Abort "Error creating Package Management registry information"; SectionEnd!define VIX_CREATE_PACKAGING_REGISTRY `!insertmacro VIX_CREATE_PACKAGING_REGISTRY`!macro VIX_CREATE_PACKAGING_REGISTRY!ifdef VIX_PACKAGING_ROOTKEY!undef VIX_PACKAGING_ROOTKEY!endif!define VIX_PACKAGING_ROOTKEY "SOFTWARE\ERG\AFC"!ifdef VIX_PACKAGING_SUBKEY!undef VIX_PACKAGING_SUBKEY!endif!define VIX_PACKAGING_SUBKEY "${VIX_PACKAGING_ROOTKEY}\${GBE_PACKAGE}"!ifdef VIX_PACKAGING_PARAMETERS_SUBKEY!undef VIX_PACKAGING_PARAMETERS_SUBKEY!endif!define VIX_PACKAGING_PARAMETERS_SUBKEY "${VIX_PACKAGING_ROOTKEY}\${GBE_PACKAGE}\InstallParameters"ClearErrors; Determine the install time in format MM-DD-YYYY HH:MM:SS${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6; $0="01" day; $1="04" month; $2="2005" year; $3="Friday" day of week name; $4="16" hour; $5="05" minute; $6="50" secondsStrCpy $0 "$1-$0-$2 $4:$5:$6"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "PkgVersion" "${GBE_VERSION}"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "PkgBuildNum" "1"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "PkgProjAcronym" "${GBE_PROJECT}"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "PkgName" "${GBE_PACKAGE}"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "PkgNameLong" "${PACKAGE_LONGNAME}"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "PkgDesc" "${PACKAGE_DESCRIPTION}"WriteRegExpandStr HKLM ${VIX_PACKAGING_SUBKEY} "BaseInstallDir" "$INSTDIR\"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "PkgInstalled" "$0"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "LatestPatchID" "0000000000000-00"WriteRegStr HKLM ${VIX_PACKAGING_SUBKEY} "LatestPatchInstalled" "00-00-0000 0:00:00"!macroend;---------------------------------------------------------------------------------------------------; macro VIX_REMOVE_PACKAGING_REGISTRY; Deletes the registry entries for pkgmnt and procmgr; The macro should be inserted in an uninstall section and must be after the section that calls the; VIX_CREATE_PACKAGING_REGISTRY macro above, if not will abort with errors as defines create by; VIX_CREATE_PACKAGING_REGISTRY will not be available;; Example, If using same section names as example, this section must appear after Section "-Core"; Section "-un.Core"; DetailPrint "---- Install -Core section"; ${VIX_REMOVE_UNINSTALLER_AND_REGISTRY}; ${VIX_REMOVE_PACKAGING_REGISTRY}; SectionEnd!define VIX_REMOVE_PACKAGING_REGISTRY `!insertmacro VIX_REMOVE_PACKAGING_REGISTRY`!macro VIX_REMOVE_PACKAGING_REGISTRYClearErrors!ifndef VIX_PACKAGING_SUBKEY!error "The VIX_REMOVE_PACKAGING_REGISTRY macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"!endifDeleteRegKey HKLM ${VIX_PACKAGING_SUBKEY}!macroend;---------------------------------------------------------------------------------------------------; macro VIX_CHECK_VIXPKG_PREREQ; Checks the VIX_PACKAGING_ROOTKEY for PKGNAME to see if package has been intalled.; This is for VIX packages that create the registry entries using VIX_CREATE_PACKAGING_REGISTRY in NSIS or in installshield; It does not use the Uninstaller registry locations;; Parameters; PKGNAME - The name of the VIX Package to look for; KEYVALUE - A Variable that has PKGNAME appended to it if PkgName is not installed.;; Used in .onInit function; Declare Global var first; Var MISSING_PREREQ; Then in .onInit; ${VIX_CHECK_VIXPKG_PREREQ} "ERGcots" $MISSING_PREREQ; ${VIX_CHECK_VIXPKG_PREREQ} "ERGsnmpagt" $MISSING_PREREQ;StrCmp $MISSING_PREREQ "" +2; MessageBox MB_OK|MB_ICONINFORMATION 'The following pre-requisite Package(s) are not installed. Please install to complete installation$\n$MISSING_PREREQ' /SD IDOK!define VIX_CHECK_VIXPKG_PREREQ `!insertmacro VIX_CHECK_VIXPKG_PREREQ`!macro VIX_CHECK_VIXPKG_PREREQ PKGNAME PKGSNOTFOUNDClearErrors!ifndef VIX_PACKAGING_ROOTKEY!error "The VIX_CHECK_VIXPKG_PREREQ macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"!endifpush $0ReadRegStr $0 HKLM "${VIX_PACKAGING_ROOTKEY}\${PKGNAME}" "PkgName"IfErrors 0 +5StrCmp ${PKGSNOTFOUND} "" +3StrCpy ${PKGSNOTFOUND} "${PKGSNOTFOUND}, ${PKGNAME}"Goto +2StrCpy ${PKGSNOTFOUND} "${PKGNAME}"pop $0!macroend;---------------------------------------------------------------------------------------------------; macro VIX_SAVE_PACKAGING_PARAMETER; Saves key values in VIX_PACKAGING_PARAMETERS_SUBKEY registry for recall on when installing new version; Must be inserted in your script after the insertion of VIX_CREATE_PACKAGING_REGISTRY for required defines;; Parameters; KEYNAME - The name of the key to save; KEYVALUE - The value of the key to save (string only)!define VIX_SAVE_PACKAGING_PARAMETER `!insertmacro VIX_SAVE_PACKAGING_PARAMETER`!macro VIX_SAVE_PACKAGING_PARAMETER KEYNAME KEYVALUEClearErrors!ifndef VIX_PACKAGING_PARAMETERS_SUBKEY!error "The VIX_SAVE_PACKAGING_PARAMETER macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"!endifWriteRegStr HKLM ${VIX_PACKAGING_PARAMETERS_SUBKEY} "${KEYNAME}" "${KEYVALUE}"!macroend;---------------------------------------------------------------------------------------------------; macro VIX_GET_PACKAGING_PARAMETER; Retreives key values in VIX_PACKAGING_PARAMETERS_SUBKEY registry for recall on when installing new version; Must be inserted in your script after the insertion of VIX_CREATE_PACKAGING_REGISTRY for required defines;; Parameters; KEYNAME - The name of the key to retrieve; VAR - The variable to save the entry to; DEFAULT - The default to use if not in registry!define VIX_GET_PACKAGING_PARAMETER `!insertmacro VIX_GET_PACKAGING_PARAMETER`!macro VIX_GET_PACKAGING_PARAMETER KEYNAME VAR DEFAULTClearErrors!ifndef VIX_PACKAGING_PARAMETERS_SUBKEY!error "The VIX_GET_PACKAGING_PARAMETER macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"!endifReadRegStr ${VAR} HKLM ${VIX_PACKAGING_PARAMETERS_SUBKEY} "${KEYNAME}"IfErrors 0 +2StrCpy ${VAR} "${DEFAULT}"Nop!macroend;---------------------------------------------------------------------------------------------------; macro VIX_SETINSTDIR_IFINSTALLED; This is to be inserted inside the .onInit function and sets the default installdir to the value used; if the package has already been installed, otherwise leaves it as it is;; Uses registers $0;!define VIX_SETINSTDIR_IFINSTALLED `!insertmacro VIX_SETINSTDIR_IFINSTALLED`!macro VIX_SETINSTDIR_IFINSTALLED!ifndef VIX_UNINSTALL_KEY!error "The VIX_SETINSTDIR_IFINSTALLED macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"!endifClearErrorspush $0ReadRegStr $0 HKLM ${VIX_UNINSTALL_KEY} "InstallLocation"IfErrors +2 0; set default installdir to what was previously usedStrCpy $INSTDIR $0Pop $0!macroend;---------------------------------------------------------------------------------------------------; macro VIX_ONINIT_UNINSTALL_EXISTING_VERSION; This is to be inserted inside the .onInit function and checks for the existance of an already installed; version and prompts the user to uninstall. If yes is selected it runs the uninstaller, otherwise it quits the installer; If in silent mode then it automatically Uninstalls;; Parameter:; OLDVERSION: Contains the version number of the uninstalled version (or ???? if old version is detected but cant get version number); otherwise set to empty string to indicate no uninstall is done;; Uses registers $0, $1, $2, $3;!define VIX_ONINIT_UNINSTALL_EXISTING_VERSION `!insertmacro VIX_ONINIT_UNINSTALL_EXISTING_VERSION`!macro VIX_ONINIT_UNINSTALL_EXISTING_VERSION OLDVERSION!ifndef VIX_UNINSTALL_KEY!error "The VIX_ONINIT_UNINSTALL_EXISTING_VERSION macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"!endifClearErrorspush $0push $1push $2push $3StrCpy ${OLDVERSION} "" ; Empty string indicates no uninstall done; If these are not in registry then package is not installed so do nothingReadRegStr $0 HKLM ${VIX_UNINSTALL_KEY} "UninstallString"IfErrors Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.doneReadRegStr $1 HKLM ${VIX_UNINSTALL_KEY} "InstallLocation"IfErrors Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done# if we cant get version number (in case of legacy installs without version number) then jump to display non versioned message boxReadRegStr ${OLDVERSION} HKLM ${VIX_UNINSTALL_KEY} "Version"IfErrors 0 +2 ; If Error set OldVersion next otherwise jump to message boxStrCpy ${OLDVERSION} "????" ; Just so there is something in there to indicate we did do an uninstallMessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \"${GBE_PACKAGE} version ${OLDVERSION} is currently installed and will be uninstalled first before installing this (${GBE_VERSION}) version.$\n$\n\Click 'OK' to do so or 'Cancel' to abort installation" \/SD IDOK IDOK +2Quit; We have to use $?=INSTDIR to stop uninstaller making a copy of itself before running, otherwise ExecWait cant wait for it; The problem is that uninstalling this way is unable to remove the uninstaller.exe itself as it is running; So to Solve it copy the uninstaller to a tmp dir and run it from there${StrRep} $2 $0 '"' '' ; remove quotes from $0 from registry otherwise copy wont workStrcpy $3 "$TEMP\${GBE_PACKAGE}_Uninstall-tmp.exe"CopyFiles /SILENT "$2" "$3"IfErrors 0 +3MessageBox MB_OK "Failed to copy uninstaller"AbortExecWait '"$3" /S _?=$1'IfErrors 0 +3MessageBox MB_OK "Failed to uninstall current version"AbortDelete $3Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done:pop $3pop $2pop $1pop $0!macroend