UpgradeDLL.nsh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.v2\UpgradeDLLSession" "count"
  43. IntOp $R0 $R0 + 1
  44. WriteRegDWORD HKLM "Software\NSIS.Library.RegTool.v2\UpgradeDLLSession" "count" "$R0"
  45. ;------------------------
  46. ;Setup RegTool
  47. ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "NSIS.Library.RegTool.v2"
  48. StrCpy $R3 $R3 -4 1
  49. IfFileExists $R3 +3
  50. File /oname=$R2\NSIS.Library.RegTool.v2.$HWNDPARENT.exe "${NSISDIR}\Bin\RegTool.bin"
  51. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
  52. "NSIS.Library.RegTool.v2" '"$R2\NSIS.Library.RegTool.v2.$HWNDPARENT.exe" /S'
  53. ;------------------------
  54. ;Add RegTool entry
  55. WriteRegStr HKLM "Software\NSIS.Library.RegTool.v2\UpgradeDLLSession" "$R0.file" "$R1"
  56. WriteRegStr HKLM "Software\NSIS.Library.RegTool.v2\UpgradeDLLSession" "$R0.mode" "${mode}"
  57. Pop $R3
  58. Pop $R2
  59. Pop $R1
  60. Pop $R0
  61. !macroend
  62. !macro UpgradeDLL LOCALFILE DESTFILE TEMPBASEDIR
  63. Push $R0
  64. Push $R1
  65. Push $R2
  66. Push $R3
  67. Push $R4
  68. Push $R5
  69. !define UPGRADEDLL_UNIQUE "${__FILE__}${__LINE__}"
  70. SetOverwrite try
  71. ;------------------------
  72. ;Copy the macro parameters to a run-time to a variable,
  73. ;this allows the usage of variables as parameter
  74. StrCpy $R4 "${DESTFILE}"
  75. StrCpy $R5 "${TEMPBASEDIR}"
  76. ;------------------------
  77. ;Get version information
  78. IfFileExists $R4 0 "upgradedll.copy_${UPGRADEDLL_UNIQUE}"
  79. ClearErrors
  80. GetDLLVersionLocal "${LOCALFILE}" $R0 $R1
  81. GetDLLVersion $R4 $R2 $R3
  82. IfErrors "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
  83. IntCmpU $R0 $R2 0 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
  84. IntCmpU $R1 $R3 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.done_${UPGRADEDLL_UNIQUE}" \
  85. "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
  86. ;------------------------
  87. ;Upgrade
  88. "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}:"
  89. !ifndef UPGRADEDLL_NOREGISTER
  90. ;Unregister the DLL
  91. UnRegDLL $R4
  92. !endif
  93. ;------------------------
  94. ;Copy
  95. ClearErrors
  96. StrCpy $R0 $R4
  97. Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
  98. IfErrors 0 "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}"
  99. ;------------------------
  100. ;Copy on reboot
  101. GetTempFileName $R0 $R5
  102. Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
  103. Rename /REBOOTOK $R0 $R4
  104. ;------------------------
  105. ;Register on reboot
  106. !insertmacro __UpgradeDLL_Helper_AddRegToolEntry 'D' $R4 $R5
  107. Goto "upgradedll.done_${UPGRADEDLL_UNIQUE}"
  108. ;------------------------
  109. ;DLL does not exist
  110. "upgradedll.copy_${UPGRADEDLL_UNIQUE}:"
  111. StrCpy $R0 $R4
  112. Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
  113. ;------------------------
  114. ;Register
  115. "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}:"
  116. !ifndef UPGRADEDLL_NOREGISTER
  117. RegDLL $R4
  118. !endif
  119. ;------------------------
  120. ;Done
  121. "upgradedll.done_${UPGRADEDLL_UNIQUE}:"
  122. Pop $R5
  123. Pop $R4
  124. Pop $R3
  125. Pop $R2
  126. Pop $R1
  127. Pop $R0
  128. ;------------------------
  129. ;End
  130. Goto "upgradedll.end_${UPGRADEDLL_UNIQUE}"
  131. ;------------------------
  132. ;Extract
  133. "upgradedll.file_${UPGRADEDLL_UNIQUE}:"
  134. File /oname=$R0 "${LOCALFILE}"
  135. Return
  136. "upgradedll.end_${UPGRADEDLL_UNIQUE}:"
  137. SetOverwrite lastused
  138. !undef UPGRADEDLL_UNIQUE
  139. !macroend
  140. !endif