UpgradeDLL.nsh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. NOTE:
  3. -----
  4. This macro is provided for backwards compatibility with NSIS 2.0 scripts.
  5. It's recommended you update your scripts to use the new Library.nsh macros.
  6. Macro - Upgrade DLL File
  7. Written by Joost Verburg
  8. ------------------------
  9. Parameters:
  10. LOCALFILE Location of the new DLL file (on the compiler system)
  11. DESTFILE Location of the DLL file that should be upgraded (on the user's system)
  12. TEMPBASEDIR Directory on the user's system to store a temporary file when the system has
  13. to be rebooted.
  14. For Win9x/ME support, this should be on the same volume as DESTFILE.
  15. The Windows temp directory could be located on any volume, so you cannot use
  16. this directory.
  17. Define UPGRADEDLL_NOREGISTER if you want to upgrade a DLL that does not have to be registered.
  18. Notes:
  19. * If you want to support Windows 9x/ME, you can only use short filenames (8.3).
  20. * This macro uses the GetDLLVersionLocal command to retrieve the version of local libraries.
  21. This command is only supported when compiling on a Windows system.
  22. ------------------------
  23. Example:
  24. !insertmacro UpgradeDLL "dllname.dll" "$SYSDIR\dllname.dll" "$SYSDIR"
  25. */
  26. !ifndef UPGRADEDLL_INCLUDED
  27. !define UPGRADEDLL_INCLUDED
  28. !macro __UpgradeDLL_Helper_AddRegToolEntry mode filename tempdir
  29. Push $R0
  30. Push $R1
  31. Push $R2
  32. Push $R3
  33. ;------------------------
  34. ;Copy the parameters
  35. Push "${filename}"
  36. Push "${tempdir}"
  37. Pop $R2 ; temporary directory
  38. Pop $R1 ; file name to register
  39. ;------------------------
  40. ;Advance counter
  41. StrCpy $R0 0
  42. ReadRegDWORD $R0 HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "count"
  43. IntOp $R0 $R0 + 1
  44. WriteRegDWORD HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "count" "$R0"
  45. ;------------------------
  46. ;Setup RegTool
  47. !if ! /FileExists "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin"
  48. !error "Missing RegTool for ${NSIS_CPU}!"
  49. !endif
  50. ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "NSIS.Library.RegTool.v3"
  51. StrCpy $R3 $R3 -4 1
  52. IfFileExists $R3 +3
  53. File /oname=$R2\NSIS.Library.RegTool.v3.$HWNDPARENT.exe "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin"
  54. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
  55. "NSIS.Library.RegTool.v3" '"$R2\NSIS.Library.RegTool.v3.$HWNDPARENT.exe" /S'
  56. ;------------------------
  57. ;Add RegTool entry
  58. WriteRegStr HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "$R0.file" "$R1"
  59. WriteRegStr HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "$R0.mode" "${mode}"
  60. Pop $R3
  61. Pop $R2
  62. Pop $R1
  63. Pop $R0
  64. !macroend
  65. !macro UpgradeDLL LOCALFILE DESTFILE TEMPBASEDIR
  66. Push $R0
  67. Push $R1
  68. Push $R2
  69. Push $R3
  70. Push $R4
  71. Push $R5
  72. !define UPGRADEDLL_UNIQUE "${__FILE__}${__LINE__}"
  73. SetOverwrite try
  74. ;------------------------
  75. ;Copy the macro parameters to a run-time to a variable,
  76. ;this allows the usage of variables as parameter
  77. StrCpy $R4 "${DESTFILE}"
  78. StrCpy $R5 "${TEMPBASEDIR}"
  79. ;------------------------
  80. ;Get version information
  81. IfFileExists $R4 0 "upgradedll.copy_${UPGRADEDLL_UNIQUE}"
  82. ClearErrors
  83. GetDLLVersionLocal "${LOCALFILE}" $R0 $R1
  84. GetDLLVersion $R4 $R2 $R3
  85. IfErrors "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
  86. IntCmpU $R0 $R2 0 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
  87. IntCmpU $R1 $R3 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.done_${UPGRADEDLL_UNIQUE}" \
  88. "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
  89. ;------------------------
  90. ;Upgrade
  91. "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}:"
  92. !ifndef UPGRADEDLL_NOREGISTER
  93. ;Unregister the DLL
  94. UnRegDLL $R4
  95. !endif
  96. ;------------------------
  97. ;Copy
  98. ClearErrors
  99. StrCpy $R0 $R4
  100. Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
  101. IfErrors 0 "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}"
  102. ;------------------------
  103. ;Copy on reboot
  104. GetTempFileName $R0 $R5
  105. Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
  106. Rename /REBOOTOK $R0 $R4
  107. ;------------------------
  108. ;Register on reboot
  109. !insertmacro __UpgradeDLL_Helper_AddRegToolEntry 'D' $R4 $R5
  110. Goto "upgradedll.done_${UPGRADEDLL_UNIQUE}"
  111. ;------------------------
  112. ;DLL does not exist
  113. "upgradedll.copy_${UPGRADEDLL_UNIQUE}:"
  114. StrCpy $R0 $R4
  115. Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
  116. ;------------------------
  117. ;Register
  118. "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}:"
  119. !ifndef UPGRADEDLL_NOREGISTER
  120. RegDLL $R4
  121. !endif
  122. ;------------------------
  123. ;Done
  124. "upgradedll.done_${UPGRADEDLL_UNIQUE}:"
  125. Pop $R5
  126. Pop $R4
  127. Pop $R3
  128. Pop $R2
  129. Pop $R1
  130. Pop $R0
  131. ;------------------------
  132. ;End
  133. Goto "upgradedll.end_${UPGRADEDLL_UNIQUE}"
  134. ;------------------------
  135. ;Extract
  136. "upgradedll.file_${UPGRADEDLL_UNIQUE}:"
  137. File /oname=$R0 "${LOCALFILE}"
  138. Return
  139. "upgradedll.end_${UPGRADEDLL_UNIQUE}:"
  140. SetOverwrite lastused
  141. !undef UPGRADEDLL_UNIQUE
  142. !macroend
  143. !endif