Library.nsh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. #
  2. # Library.nsh
  3. #
  4. # A system for the installation and uninstallation of dynamic
  5. # link libraries (DLL) and type libraries (TLB). Using this
  6. # system you can handle the complete setup with one single
  7. # line of code:
  8. #
  9. # * File copying
  10. # * File copying on reboot
  11. # * Version checks
  12. # * Registration and unregistration
  13. # * Registration and unregistration on reboot
  14. # * Shared DLL counting
  15. # * Windows File Protection checks
  16. #
  17. # For more information, read appendix B in the documentation.
  18. #
  19. !verbose push
  20. !verbose 3
  21. !ifndef LIB_INCLUDED
  22. !define LIB_INCLUDED
  23. !ifndef SHCNE_ASSOCCHANGED
  24. !define SHCNE_ASSOCCHANGED 0x08000000
  25. !endif
  26. !ifndef SHCNF_IDLIST
  27. !define SHCNF_IDLIST 0x0000
  28. !endif
  29. !define REGTOOL_VERSION v3
  30. !define REGTOOL_KEY NSIS.Library.RegTool.${REGTOOL_VERSION}
  31. !include LogicLib.nsh
  32. !include x64.nsh
  33. ### GetParent macro, don't pass $1 or $2 as INTPUT or OUTPUT
  34. !macro __InstallLib_Helper_GetParent INPUT OUTPUT
  35. # Copied from FileFunc.nsh
  36. StrCpy ${OUTPUT} ${INPUT}
  37. Push $1
  38. Push $2
  39. StrCpy $2 ${OUTPUT} 1 -1
  40. StrCmp $2 '\' 0 +3
  41. StrCpy ${OUTPUT} ${OUTPUT} -1
  42. goto -3
  43. StrCpy $1 0
  44. IntOp $1 $1 - 1
  45. StrCpy $2 ${OUTPUT} 1 $1
  46. StrCmp $2 '\' +2
  47. StrCmp $2 '' 0 -3
  48. StrCpy ${OUTPUT} ${OUTPUT} $1
  49. Pop $2
  50. Pop $1
  51. !macroend
  52. ### Initialize session id (GUID)
  53. !macro __InstallLib_Helper_InitSession
  54. !ifndef __InstallLib_SessionGUID_Defined
  55. !define __InstallLib_SessionGUID_Defined
  56. Var /GLOBAL __INSTALLLLIB_SESSIONGUID
  57. !endif
  58. !define __InstallLib_Helper_InitSession_Label "Library_${__FILE__}${__LINE__}"
  59. StrCmp $__INSTALLLLIB_SESSIONGUID '' 0 "${__InstallLib_Helper_InitSession_Label}"
  60. System::Call 'ole32::CoCreateGuid(g .s)'
  61. Pop $__INSTALLLLIB_SESSIONGUID
  62. "${__InstallLib_Helper_InitSession_Label}:"
  63. !undef __InstallLib_Helper_InitSession_Label
  64. !macroend
  65. ### Add a RegTool entry to register after reboot
  66. !macro __InstallLib_Helper_AddRegToolEntry mode filename tempdir
  67. Push $R0
  68. Push $R1
  69. Push $R2
  70. Push $R3
  71. ;------------------------
  72. ;Copy the parameters
  73. Push "${filename}"
  74. Push "${tempdir}"
  75. Pop $R2 ; temporary directory
  76. Pop $R1 ; file name to register
  77. ;------------------------
  78. ;Initialize session id
  79. !insertmacro __InstallLib_Helper_InitSession
  80. ;------------------------
  81. ;Advance counter
  82. StrCpy $R0 0
  83. ReadRegDWORD $R0 HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "count"
  84. IntOp $R0 $R0 + 1
  85. WriteRegDWORD HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "count" "$R0"
  86. ;------------------------
  87. ;Setup RegTool
  88. !if ! /FileExists "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin"
  89. !error "Missing RegTool for ${NSIS_CPU}!"
  90. !endif
  91. ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "${REGTOOL_KEY}"
  92. StrCpy $R3 $R3 -4 1
  93. IfFileExists $R3 +3
  94. File /oname=$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin"
  95. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
  96. "${REGTOOL_KEY}" '"$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe" /S'
  97. ;------------------------
  98. ;Add RegTool entry
  99. WriteRegStr HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "$R0.file" "$R1"
  100. WriteRegStr HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "$R0.mode" "${mode}"
  101. Pop $R3
  102. Pop $R2
  103. Pop $R1
  104. Pop $R0
  105. !macroend
  106. !macro __InstallLib_Helper_CmpPackedVer64 oldhi oldlo newhi newlo jeq jle jgt
  107. IntCmpU ${oldhi} ${newhi} "0" "${jle}" "${jgt}"
  108. IntCmpU ${oldlo} ${newlo} "${jeq}" "${jle}" "${jgt}"
  109. !macroend
  110. ### Get library version
  111. !macro __InstallLib_Helper_GetVersion TYPE FILE
  112. !if "${TYPE}" == "D"
  113. !getdllversion /NoErrors /Packed "${FILE}" LIBRARY_VERSION_
  114. !else if "${TYPE}" == "T"
  115. !gettlbversion /NoErrors /Packed "${FILE}" LIBRARY_VERSION_
  116. !endif
  117. ; Emulate the old LibraryLocal defines
  118. !ifndef LIBRARY_VERSION_HIGH
  119. !define LIBRARY_VERSION_FILENOTFOUND
  120. !else if "${LIBRARY_VERSION_HIGH}" == ""
  121. !define LIBRARY_VERSION_NONE
  122. !undef LIBRARY_VERSION_HIGH
  123. !undef LIBRARY_VERSION_LOW
  124. !endif
  125. !macroend
  126. ### Install library
  127. !macro InstallLib libtype shared install localfile destfile tempbasedir
  128. !verbose push
  129. !verbose 3
  130. Push $R0
  131. Push $R1
  132. Push $R2
  133. Push $R3
  134. Push $R4
  135. Push $R5
  136. ;------------------------
  137. ;Define
  138. !define INSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  139. !define INSTALLLIB_LIBTYPE_${libtype}
  140. !define INSTALLLIB_LIBTYPE_SET INSTALLLIB_LIBTYPE_${libtype}
  141. !define INSTALLLIB_SHARED_${shared}
  142. !define INSTALLLIB_SHARED_SET INSTALLLIB_SHARED_${shared}
  143. !define INSTALLLIB_INSTALL_${install}
  144. !define INSTALLLIB_INSTALL_SET INSTALLLIB_INSTALL_${install}
  145. ;------------------------
  146. ;Validate
  147. !ifndef INSTALLLIB_LIBTYPE_DLL & INSTALLLIB_LIBTYPE_REGDLL & INSTALLLIB_LIBTYPE_TLB & \
  148. INSTALLLIB_LIBTYPE_REGDLLTLB & INSTALLLIB_LIBTYPE_REGEXE
  149. !error "InstallLib: Incorrect setting for parameter: libtype"
  150. !endif
  151. !ifndef INSTALLLIB_INSTALL_REBOOT_PROTECTED & INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED & \
  152. INSTALLLIB_INSTALL_NOREBOOT_PROTECTED & INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  153. !error "InstallLib: Incorrect setting for parameter: install"
  154. !endif
  155. ;------------------------
  156. ;x64 settings
  157. !ifdef LIBRARY_X64
  158. ${DisableX64FSRedirection}
  159. !endif
  160. ;------------------------
  161. ;Copy the parameters used on run-time to a variable
  162. ;This allows the usage of variables as parameter
  163. StrCpy $R4 "${destfile}"
  164. StrCpy $R5 "${tempbasedir}"
  165. ;------------------------
  166. ;Shared library count
  167. !ifndef INSTALLLIB_SHARED_NOTSHARED
  168. StrCmp ${shared} "" 0 "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}"
  169. !ifdef LIBRARY_X64
  170. SetRegView 64
  171. !endif
  172. ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4
  173. ClearErrors
  174. IntOp $R0 $R0 + 1
  175. WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4 $R0
  176. !ifdef LIBRARY_X64
  177. SetRegView lastused
  178. !endif
  179. "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}:"
  180. !endif
  181. ;------------------------
  182. ;Check Windows File Protection
  183. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_PROTECTED
  184. !define LIBRARY_DEFINE_DONE_LABEL
  185. System::Call "sfc::SfcIsFileProtected(i 0, w R4) i.R0"
  186. StrCmp $R0 "error" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  187. StrCmp $R0 "0" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  188. Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  189. "installlib.notprotected_${INSTALLLIB_UNIQUE}:"
  190. !endif
  191. ;------------------------
  192. ;Check file
  193. IfFileExists $R4 0 "installlib.copy_${INSTALLLIB_UNIQUE}"
  194. ;------------------------
  195. ;Get version information
  196. !ifndef LIBRARY_IGNORE_VERSION
  197. !insertmacro __InstallLib_Helper_GetVersion D "${LOCALFILE}"
  198. !ifdef LIBRARY_VERSION_FILENOTFOUND
  199. !error "InstallLib: The library ${LOCALFILE} could not be found."
  200. !endif
  201. !ifndef LIBRARY_VERSION_NONE
  202. !define LIBRARY_DEFINE_UPGRADE_LABEL
  203. !define LIBRARY_DEFINE_REGISTER_LABEL
  204. StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  205. StrCpy $R1 ${LIBRARY_VERSION_LOW}
  206. GetDLLVersion $R4 $R2 $R3
  207. !undef LIBRARY_VERSION_HIGH
  208. !undef LIBRARY_VERSION_LOW
  209. !ifndef INSTALLLIB_LIBTYPE_TLB & INSTALLLIB_LIBTYPE_REGDLLTLB
  210. !ifdef LIBRARY_INSTALL_EQUAL_VERSION
  211. !insertmacro __InstallLib_Helper_CmpPackedVer64 $R0 $R1 $R2 $R3 "installlib.upgrade_${INSTALLLIB_UNIQUE}" \
  212. "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  213. !else
  214. !insertmacro __InstallLib_Helper_CmpPackedVer64 $R0 $R1 $R2 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" \
  215. "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  216. !endif
  217. !else
  218. !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  219. !ifdef LIBRARY_VERSION_FILENOTFOUND
  220. !error "InstallLib: The library ${LOCALFILE} could not be found."
  221. !endif
  222. !ifndef LIBRARY_VERSION_NONE
  223. !insertmacro __InstallLib_Helper_CmpPackedVer64 $R0 $R1 $R2 $R3 0 \
  224. "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  225. !else
  226. !ifdef LIBRARY_INSTALL_EQUAL_VERSION
  227. !insertmacro __InstallLib_Helper_CmpPackedVer64 $R0 $R1 $R2 $R3 "installlib.upgrade_${INSTALLLIB_UNIQUE}" \
  228. "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  229. !else
  230. !insertmacro __InstallLib_Helper_CmpPackedVer64 $R0 $R1 $R2 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" \
  231. "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  232. !endif
  233. !endif
  234. !endif
  235. !else
  236. !undef LIBRARY_VERSION_NONE
  237. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  238. !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  239. !endif
  240. !endif
  241. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  242. !ifndef LIBRARY_VERSION_NONE
  243. !ifndef LIBRARY_DEFINE_UPGRADE_LABEL
  244. !define LIBRARY_DEFINE_UPGRADE_LABEL
  245. !endif
  246. !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  247. !define LIBRARY_DEFINE_REGISTER_LABEL
  248. !endif
  249. StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  250. StrCpy $R1 ${LIBRARY_VERSION_LOW}
  251. TypeLib::GetLibVersion $R4
  252. Pop $R3
  253. Pop $R2
  254. !ifdef LIBRARY_INSTALL_EQUAL_VERSION
  255. !insertmacro __InstallLib_Helper_CmpPackedVer64 $R0 $R1 $R2 $R3 "installlib.upgrade_${INSTALLLIB_UNIQUE}" \
  256. "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  257. !else
  258. !insertmacro __InstallLib_Helper_CmpPackedVer64 $R0 $R1 $R2 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" \
  259. "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  260. !endif
  261. !undef LIBRARY_VERSION_HIGH
  262. !undef LIBRARY_VERSION_LOW
  263. !else
  264. !undef LIBRARY_VERSION_NONE
  265. !endif
  266. !endif
  267. !endif ;~LIBRARY_IGNORE_VERSION
  268. ;------------------------
  269. ;Upgrade
  270. !ifdef LIBRARY_DEFINE_UPGRADE_LABEL
  271. !undef LIBRARY_DEFINE_UPGRADE_LABEL
  272. "installlib.upgrade_${INSTALLLIB_UNIQUE}:"
  273. !endif
  274. ;------------------------
  275. ;Copy
  276. !ifdef INSTALLLIB_INSTALL_NOREBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  277. "installlib.copy_${INSTALLLIB_UNIQUE}:"
  278. StrCpy $R0 $R4
  279. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  280. !else
  281. !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  282. !define LIBRARY_DEFINE_REGISTER_LABEL
  283. !endif
  284. !ifndef LIBRARY_DEFINE_DONE_LABEL
  285. !define LIBRARY_DEFINE_DONE_LABEL
  286. !endif
  287. ClearErrors
  288. StrCpy $R0 $R4
  289. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  290. IfErrors 0 "installlib.register_${INSTALLLIB_UNIQUE}"
  291. SetOverwrite lastused
  292. ;------------------------
  293. ;Copy on reboot
  294. GetTempFileName $R0 $R5
  295. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  296. Rename /REBOOTOK $R0 $R4
  297. ;------------------------
  298. ;Register on reboot
  299. Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  300. Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  301. "installlib.copy_${INSTALLLIB_UNIQUE}:"
  302. StrCpy $R0 $R4
  303. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  304. !endif
  305. ;------------------------
  306. ;Register
  307. !ifdef LIBRARY_DEFINE_REGISTER_LABEL
  308. !undef LIBRARY_DEFINE_REGISTER_LABEL
  309. "installlib.register_${INSTALLLIB_UNIQUE}:"
  310. !endif
  311. !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB | INSTALLLIB_LIBTYPE_REGEXE
  312. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  313. IfRebootFlag 0 "installlib.regnoreboot_${INSTALLLIB_UNIQUE}"
  314. Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  315. Goto "installlib.registerfinish_${INSTALLLIB_UNIQUE}"
  316. "installlib.regnoreboot_${INSTALLLIB_UNIQUE}:"
  317. !endif
  318. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  319. TypeLib::Register $R4
  320. !endif
  321. !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  322. !ifndef LIBRARY_X64
  323. RegDll $R4
  324. !else
  325. ExecWait '"$SYSDIR\regsvr32.exe" /s "$R4"'
  326. !endif
  327. !endif
  328. !ifdef INSTALLLIB_LIBTYPE_REGEXE
  329. ExecWait '"$R4" /regserver'
  330. !endif
  331. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  332. "installlib.registerfinish_${INSTALLLIB_UNIQUE}:"
  333. !endif
  334. !endif
  335. !ifdef LIBRARY_SHELL_EXTENSION
  336. System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  337. !endif
  338. !ifdef LIBRARY_COM
  339. System::Call 'Ole32::CoFreeUnusedLibraries()'
  340. !endif
  341. ;------------------------
  342. ;Done
  343. !ifdef LIBRARY_DEFINE_DONE_LABEL
  344. !undef LIBRARY_DEFINE_DONE_LABEL
  345. "installlib.done_${INSTALLLIB_UNIQUE}:"
  346. !endif
  347. Pop $R5
  348. Pop $R4
  349. Pop $R3
  350. Pop $R2
  351. Pop $R1
  352. Pop $R0
  353. ;------------------------
  354. ;End
  355. Goto "installlib.end_${INSTALLLIB_UNIQUE}"
  356. ;------------------------
  357. ;Extract
  358. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  359. SetOverwrite try
  360. !else
  361. SetOverwrite on
  362. !endif
  363. "installlib.file_${INSTALLLIB_UNIQUE}:"
  364. SetFileAttributes $R0 FILE_ATTRIBUTE_NORMAL
  365. ClearErrors
  366. File /oname=$R0 "${LOCALFILE}"
  367. Return
  368. SetOverwrite lastused
  369. ;------------------------
  370. ;Register on reboot
  371. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  372. "installlib.regonreboot_${INSTALLLIB_UNIQUE}:"
  373. !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  374. !ifndef LIBRARY_X64
  375. !insertmacro __InstallLib_Helper_AddRegToolEntry 'D' "$R4" "$R5"
  376. !else
  377. !insertmacro __InstallLib_Helper_AddRegToolEntry 'DX' "$R4" "$R5"
  378. !endif
  379. !endif
  380. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  381. !insertmacro __InstallLib_Helper_AddRegToolEntry 'T' "$R4" "$R5"
  382. !endif
  383. !ifdef INSTALLLIB_LIBTYPE_REGEXE
  384. !insertmacro __InstallLib_Helper_AddRegToolEntry 'E' "$R4" "$R5"
  385. !endif
  386. Return
  387. !endif
  388. ;------------------------
  389. ;End label
  390. "installlib.end_${INSTALLLIB_UNIQUE}:"
  391. !ifdef LIBRARY_X64
  392. ${EnableX64FSRedirection}
  393. !endif
  394. ;------------------------
  395. ;Undefine
  396. !undef INSTALLLIB_UNIQUE
  397. !undef ${INSTALLLIB_LIBTYPE_SET}
  398. !undef INSTALLLIB_LIBTYPE_SET
  399. !undef ${INSTALLLIB_SHARED_SET}
  400. !undef INSTALLLIB_SHARED_SET
  401. !undef ${INSTALLLIB_INSTALL_SET}
  402. !undef INSTALLLIB_INSTALL_SET
  403. !verbose pop
  404. !macroend
  405. ### Uninstall library
  406. !macro UnInstallLib libtype shared uninstall file
  407. !verbose push
  408. !verbose 3
  409. Push $R0
  410. Push $R1
  411. ;------------------------
  412. ;Define
  413. !define UNINSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  414. !define UNINSTALLLIB_LIBTYPE_${libtype}
  415. !define UNINSTALLLIB_LIBTYPE_SET UNINSTALLLIB_LIBTYPE_${libtype}
  416. !define UNINSTALLLIB_SHARED_${shared}
  417. !define UNINSTALLLIB_SHARED_SET UNINSTALLLIB_SHARED_${shared}
  418. !define UNINSTALLLIB_UNINSTALL_${uninstall}
  419. !define UNINSTALLLIB_UNINSTALL_SET UNINSTALLLIB_UNINSTALL_${uninstall}
  420. ;------------------------
  421. ;Validate
  422. !ifndef UNINSTALLLIB_LIBTYPE_DLL & UNINSTALLLIB_LIBTYPE_REGDLL & UNINSTALLLIB_LIBTYPE_TLB & \
  423. UNINSTALLLIB_LIBTYPE_REGDLLTLB & UNINSTALLLIB_LIBTYPE_REGEXE
  424. !error "UnInstallLib: Incorrect setting for parameter: libtype"
  425. !endif
  426. !ifndef UNINSTALLLIB_SHARED_NOTSHARED & UNINSTALLLIB_SHARED_SHARED
  427. !error "UnInstallLib: Incorrect setting for parameter: shared"
  428. !endif
  429. !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE & UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED & \
  430. UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED & UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED & \
  431. UNINSTALLLIB_UNINSTALL_NOREBOOT_NOTPROTECTED
  432. !error "UnInstallLib: Incorrect setting for parameter: uninstall"
  433. !endif
  434. ;------------------------
  435. ;x64 settings
  436. !ifdef LIBRARY_X64
  437. ${DisableX64FSRedirection}
  438. !endif
  439. ;------------------------
  440. ;Copy the parameters used on run-time to a variable
  441. ;This allows the usage of variables as parameter
  442. StrCpy $R1 "${file}"
  443. ;------------------------
  444. ;Shared library count
  445. !ifdef UNINSTALLLIB_SHARED_SHARED
  446. !define UNINSTALLLIB_DONE_LABEL
  447. !ifdef LIBRARY_X64
  448. SetRegView 64
  449. !endif
  450. ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  451. StrCmp $R0 "" "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  452. IntOp $R0 $R0 - 1
  453. IntCmp $R0 0 "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" \
  454. "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}"
  455. "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}:"
  456. DeleteRegValue HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  457. !ifndef UNINSTALLLIB_SHARED_SHAREDNOREMOVE
  458. Goto "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  459. !endif
  460. "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}:"
  461. WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1 $R0
  462. !ifdef LIBRARY_X64
  463. SetRegView lastused
  464. !endif
  465. Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  466. "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}:"
  467. !ifdef LIBRARY_X64
  468. SetRegView lastused
  469. !endif
  470. !endif
  471. ;------------------------
  472. ;Remove
  473. !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE
  474. ;------------------------
  475. ;Check Windows File Protection
  476. !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED
  477. !ifndef UNINSTALLLIB_DONE_LABEL
  478. !define UNINSTALLLIB_DONE_LABEL
  479. !endif
  480. System::Call "sfc::SfcIsFileProtected(i 0, w $R1) i.R0"
  481. StrCmp $R0 "error" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  482. StrCmp $R0 "0" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  483. Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  484. "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}:"
  485. !endif
  486. ;------------------------
  487. ;Unregister
  488. !ifdef UNINSTALLLIB_LIBTYPE_REGDLL | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  489. !ifndef LIBRARY_X64
  490. UnRegDLL $R1
  491. !else
  492. ExecWait '"$SYSDIR\regsvr32.exe" /s /u "$R1"'
  493. !endif
  494. !endif
  495. !ifdef UNINSTALLLIB_LIBTYPE_REGEXE
  496. ExecWait '"$R1" /unregserver'
  497. !endif
  498. !ifdef UNINSTALLLIB_LIBTYPE_TLB | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  499. TypeLib::UnRegister $R1
  500. !endif
  501. !ifdef LIBRARY_SHELL_EXTENSION
  502. System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  503. !endif
  504. !ifdef LIBRARY_COM
  505. System::Call 'Ole32::CoFreeUnusedLibraries()'
  506. !endif
  507. ;------------------------
  508. ;Delete
  509. Delete $R1
  510. !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED
  511. ${If} ${FileExists} $R1
  512. # File is in use, can't just delete.
  513. # Move file to another location before using Delete /REBOOTOK. This way, if
  514. # the user installs a new version of the DLL, it won't be deleted after
  515. # reboot. See bug #1097642 for more information on this.
  516. # Try moving to $TEMP.
  517. GetTempFileName $R0
  518. Delete $R0
  519. Rename $R1 $R0
  520. ${If} ${FileExists} $R1
  521. # Still here, delete temporary file, in case the file was copied
  522. # and not deleted. This happens when moving from network drives,
  523. # for example.
  524. Delete $R0
  525. # Try moving to directory containing the file.
  526. !insertmacro __InstallLib_Helper_GetParent $R1 $R0
  527. GetTempFileName $R0 $R0
  528. Delete $R0
  529. Rename $R1 $R0
  530. ${If} ${FileExists} $R1
  531. # Still here, delete temporary file.
  532. Delete $R0
  533. # Give up moving, simply Delete /REBOOTOK the file.
  534. StrCpy $R0 $R1
  535. ${EndIf}
  536. ${EndIf}
  537. # Delete the moved file.
  538. Delete /REBOOTOK $R0
  539. ${EndIf}
  540. !endif
  541. !endif
  542. ;------------------------
  543. ;Done
  544. !ifdef UNINSTALLLIB_DONE_LABEL
  545. !undef UNINSTALLLIB_DONE_LABEL
  546. "uninstalllib.done_${UNINSTALLLIB_UNIQUE}:"
  547. !endif
  548. !ifdef LIBRARY_X64
  549. ${EnableX64FSRedirection}
  550. !endif
  551. Pop $R1
  552. Pop $R0
  553. ;------------------------
  554. ;Undefine
  555. !undef UNINSTALLLIB_UNIQUE
  556. !undef ${UNINSTALLLIB_LIBTYPE_SET}
  557. !undef UNINSTALLLIB_LIBTYPE_SET
  558. !undef ${UNINSTALLLIB_SHARED_SET}
  559. !undef UNINSTALLLIB_SHARED_SET
  560. !undef ${UNINSTALLLIB_UNINSTALL_SET}
  561. !undef UNINSTALLLIB_UNINSTALL_SET
  562. !verbose pop
  563. !macroend
  564. !endif
  565. !verbose pop