; Macro - Upgrade DLL File ; Written by Joost Verburg ; modified by cube (cube (at) lp.net.pl) ; ------------------------ ; ; Example of usage: ; !insertmacro UpgradeDLL "dllname.dll" "$SYSDIR\dllname.dll" ; ; !define UPGRADEDLL_NOREGISTER if you want to upgrade a DLL which cannot ; be registered ; ; !define UPGRADEEXE if you want to upgrade COM exe server ; ; Note that this macro sets overwrite to ON (the default) when it has been ; inserted. ; If you are using another setting, set it again after inserting the macro. !macro UpgradeDLL LOCALFILE DESTFILE Push $R0 Push $R1 Push $R2 Push $R3 ;------------------------ ;Check file and version IfFileExists "${DESTFILE}" "" "copy_${LOCALFILE}" ClearErrors GetDLLVersionLocal "${LOCALFILE}" $R0 $R1 GetDLLVersion "${DESTFILE}" $R2 $R3 IfErrors "upgrade_${LOCALFILE}" IntCmpU $R0 $R2 "" "done_${LOCALFILE}" "upgrade_${LOCALFILE}" IntCmpU $R1 $R3 "done_${LOCALFILE}" "done_${LOCALFILE}" \ "upgrade_${LOCALFILE}" ;------------------------ ;Let's upgrade the DLL! SetOverwrite try "upgrade_${LOCALFILE}:" !ifndef UPGRADEDLL_NOREGISTER ;Unregister the file !ifdef UPGRADEEXE ExecWait '"${DESTFILE}" /UnregServer' !else UnRegDLL "${DESTFILE}" !endif !endif ;------------------------ ;Try to copy the DLL directly ClearErrors StrCpy $R0 "${DESTFILE}" Call ":file_${LOCALFILE}" IfErrors "" "noreboot_${LOCALFILE}" ;------------------------ ;DLL is in use. Copy it to a temp file and Rename it on reboot. GetTempFileName $R0 Call ":file_${LOCALFILE}" Rename /REBOOTOK $R0 "${DESTFILE}" SetRebootFlag true ;------------------------ ;Register the DLL on reboot !ifndef UPGRADEDLL_NOREGISTER !ifdef UPGRADEEXE WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \ "Register ${DESTFILE}" '"${DESTFILE}" \ /RegServer' !else WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \ "Register ${DESTFILE}" '"$SYSDIR\rundll32.exe" \ "${DESTFILE},DllRegisterServer"' !endif SetRebootFlag true !endif Goto "done_${LOCALFILE}" ;------------------------ ;DLL does not exist - just extract "copy_${LOCALFILE}:" StrCpy $R0 "${DESTFILE}" Call ":file_${LOCALFILE}" ;------------------------ ;Register the DLL "noreboot_${LOCALFILE}:" !ifndef UPGRADEDLL_NOREGISTER !ifdef UPGRADEEXE ExecWait '"${DESTFILE}" /RegServer' !else RegDLL "${DESTFILE}" !endif !endif ;------------------------ ;Done "done_${LOCALFILE}:" Pop $R3 Pop $R2 Pop $R1 Pop $R0 ;------------------------ ;End Goto "end_${LOCALFILE}" ;------------------------ ;Called to extract the DLL "file_${LOCALFILE}:" File /oname=$R0 "${LOCALFILE}" Return "end_${LOCALFILE}:" ;------------------------ ;Set overwrite to default ;(was set to TRY above) SetOverwrite on !macroend