Library.nsh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "${REGTOOL_KEY}"
  89. StrCpy $R3 $R3 -4 1
  90. IfFileExists $R3 +3
  91. File /oname=$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool.bin"
  92. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
  93. "${REGTOOL_KEY}" '"$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe" /S'
  94. ;------------------------
  95. ;Add RegTool entry
  96. WriteRegStr HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "$R0.file" "$R1"
  97. WriteRegStr HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "$R0.mode" "${mode}"
  98. Pop $R3
  99. Pop $R2
  100. Pop $R1
  101. Pop $R0
  102. !macroend
  103. ### Get library version
  104. !macro __InstallLib_Helper_GetVersion TYPE FILE
  105. !tempfile LIBRARY_TEMP_NSH
  106. !ifdef NSIS_WIN32_MAKENSIS
  107. !execute '"${NSISDIR}\Bin\LibraryLocal.exe" "${TYPE}" "${FILE}" "${LIBRARY_TEMP_NSH}"'
  108. !else
  109. !execute 'LibraryLocal "${TYPE}" "${FILE}" "${LIBRARY_TEMP_NSH}"'
  110. !if ${TYPE} == 'T'
  111. !warning "LibraryLocal currently supports TypeLibs version detection on Windows only"
  112. !endif
  113. !endif
  114. !include "${LIBRARY_TEMP_NSH}"
  115. !delfile "${LIBRARY_TEMP_NSH}"
  116. !undef LIBRARY_TEMP_NSH
  117. !macroend
  118. ### Install library
  119. !macro InstallLib libtype shared install localfile destfile tempbasedir
  120. !verbose push
  121. !verbose 3
  122. Push $R0
  123. Push $R1
  124. Push $R2
  125. Push $R3
  126. Push $R4
  127. Push $R5
  128. ;------------------------
  129. ;Define
  130. !define INSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  131. !define INSTALLLIB_LIBTYPE_${libtype}
  132. !define INSTALLLIB_LIBTYPE_SET INSTALLLIB_LIBTYPE_${libtype}
  133. !define INSTALLLIB_SHARED_${shared}
  134. !define INSTALLLIB_SHARED_SET INSTALLLIB_SHARED_${shared}
  135. !define INSTALLLIB_INSTALL_${install}
  136. !define INSTALLLIB_INSTALL_SET INSTALLLIB_INSTALL_${install}
  137. ;------------------------
  138. ;Validate
  139. !ifndef INSTALLLIB_LIBTYPE_DLL & INSTALLLIB_LIBTYPE_REGDLL & INSTALLLIB_LIBTYPE_TLB & \
  140. INSTALLLIB_LIBTYPE_REGDLLTLB & INSTALLLIB_LIBTYPE_REGEXE
  141. !error "InstallLib: Incorrect setting for parameter: libtype"
  142. !endif
  143. !ifndef INSTALLLIB_INSTALL_REBOOT_PROTECTED & INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED & \
  144. INSTALLLIB_INSTALL_NOREBOOT_PROTECTED & INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  145. !error "InstallLib: Incorrect setting for parameter: install"
  146. !endif
  147. ;------------------------
  148. ;x64 settings
  149. !ifdef LIBRARY_X64
  150. ${DisableX64FSRedirection}
  151. !endif
  152. ;------------------------
  153. ;Copy the parameters used on run-time to a variable
  154. ;This allows the usage of variables as parameter
  155. StrCpy $R4 "${destfile}"
  156. StrCpy $R5 "${tempbasedir}"
  157. ;------------------------
  158. ;Shared library count
  159. !ifndef INSTALLLIB_SHARED_NOTSHARED
  160. StrCmp ${shared} "" 0 "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}"
  161. !ifdef LIBRARY_X64
  162. SetRegView 64
  163. !endif
  164. ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4
  165. ClearErrors
  166. IntOp $R0 $R0 + 1
  167. WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4 $R0
  168. !ifdef LIBRARY_X64
  169. SetRegView lastused
  170. !endif
  171. "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}:"
  172. !endif
  173. ;------------------------
  174. ;Check Windows File Protection
  175. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_PROTECTED
  176. !define LIBRARY_DEFINE_DONE_LABEL
  177. System::Call "sfc::SfcIsFileProtected(i 0, w R4) i.R0"
  178. StrCmp $R0 "error" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  179. StrCmp $R0 "0" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  180. Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  181. "installlib.notprotected_${INSTALLLIB_UNIQUE}:"
  182. !endif
  183. ;------------------------
  184. ;Check file
  185. IfFileExists $R4 0 "installlib.copy_${INSTALLLIB_UNIQUE}"
  186. ;------------------------
  187. ;Get version information
  188. !ifndef LIBRARY_IGNORE_VERSION
  189. !insertmacro __InstallLib_Helper_GetVersion D "${LOCALFILE}"
  190. !ifdef LIBRARY_VERSION_FILENOTFOUND
  191. !error "InstallLib: The library ${LOCALFILE} could not be found."
  192. !endif
  193. !ifndef LIBRARY_VERSION_NONE
  194. !define LIBRARY_DEFINE_UPGRADE_LABEL
  195. !define LIBRARY_DEFINE_REGISTER_LABEL
  196. StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  197. StrCpy $R1 ${LIBRARY_VERSION_LOW}
  198. GetDLLVersion $R4 $R2 $R3
  199. !undef LIBRARY_VERSION_HIGH
  200. !undef LIBRARY_VERSION_LOW
  201. !ifndef INSTALLLIB_LIBTYPE_TLB & INSTALLLIB_LIBTYPE_REGDLLTLB
  202. IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  203. IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  204. "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  205. !else
  206. !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  207. !ifdef LIBRARY_VERSION_FILENOTFOUND
  208. !error "InstallLib: The library ${LOCALFILE} could not be found."
  209. !endif
  210. !ifndef LIBRARY_VERSION_NONE
  211. IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  212. IntCmpU $R1 $R3 0 "installlib.register_${INSTALLLIB_UNIQUE}" \
  213. "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  214. !else
  215. IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  216. IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  217. "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  218. !endif
  219. !endif
  220. !else
  221. !undef LIBRARY_VERSION_NONE
  222. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  223. !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  224. !endif
  225. !endif
  226. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  227. !ifndef LIBRARY_VERSION_NONE
  228. !ifndef LIBRARY_DEFINE_UPGRADE_LABEL
  229. !define LIBRARY_DEFINE_UPGRADE_LABEL
  230. !endif
  231. !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  232. !define LIBRARY_DEFINE_REGISTER_LABEL
  233. !endif
  234. StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  235. StrCpy $R1 ${LIBRARY_VERSION_LOW}
  236. TypeLib::GetLibVersion $R4
  237. Pop $R3
  238. Pop $R2
  239. IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  240. IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  241. "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  242. !undef LIBRARY_VERSION_HIGH
  243. !undef LIBRARY_VERSION_LOW
  244. !else
  245. !undef LIBRARY_VERSION_NONE
  246. !endif
  247. !endif
  248. !endif
  249. ;------------------------
  250. ;Upgrade
  251. !ifdef LIBRARY_DEFINE_UPGRADE_LABEL
  252. !undef LIBRARY_DEFINE_UPGRADE_LABEL
  253. "installlib.upgrade_${INSTALLLIB_UNIQUE}:"
  254. !endif
  255. ;------------------------
  256. ;Copy
  257. !ifdef INSTALLLIB_INSTALL_NOREBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  258. "installlib.copy_${INSTALLLIB_UNIQUE}:"
  259. StrCpy $R0 $R4
  260. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  261. !else
  262. !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  263. !define LIBRARY_DEFINE_REGISTER_LABEL
  264. !endif
  265. !ifndef LIBRARY_DEFINE_DONE_LABEL
  266. !define LIBRARY_DEFINE_DONE_LABEL
  267. !endif
  268. ClearErrors
  269. StrCpy $R0 $R4
  270. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  271. IfErrors 0 "installlib.register_${INSTALLLIB_UNIQUE}"
  272. SetOverwrite lastused
  273. ;------------------------
  274. ;Copy on reboot
  275. GetTempFileName $R0 $R5
  276. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  277. Rename /REBOOTOK $R0 $R4
  278. ;------------------------
  279. ;Register on reboot
  280. Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  281. Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  282. "installlib.copy_${INSTALLLIB_UNIQUE}:"
  283. StrCpy $R0 $R4
  284. Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  285. !endif
  286. ;------------------------
  287. ;Register
  288. !ifdef LIBRARY_DEFINE_REGISTER_LABEL
  289. !undef LIBRARY_DEFINE_REGISTER_LABEL
  290. "installlib.register_${INSTALLLIB_UNIQUE}:"
  291. !endif
  292. !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB | INSTALLLIB_LIBTYPE_REGEXE
  293. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  294. IfRebootFlag 0 "installlib.regnoreboot_${INSTALLLIB_UNIQUE}"
  295. Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  296. Goto "installlib.registerfinish_${INSTALLLIB_UNIQUE}"
  297. "installlib.regnoreboot_${INSTALLLIB_UNIQUE}:"
  298. !endif
  299. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  300. TypeLib::Register $R4
  301. !endif
  302. !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  303. !ifndef LIBRARY_X64
  304. RegDll $R4
  305. !else
  306. ExecWait '"$SYSDIR\regsvr32.exe" /s "$R4"'
  307. !endif
  308. !endif
  309. !ifdef INSTALLLIB_LIBTYPE_REGEXE
  310. ExecWait '"$R4" /regserver'
  311. !endif
  312. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  313. "installlib.registerfinish_${INSTALLLIB_UNIQUE}:"
  314. !endif
  315. !endif
  316. !ifdef LIBRARY_SHELL_EXTENSION
  317. System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  318. !endif
  319. !ifdef LIBRARY_COM
  320. System::Call 'Ole32::CoFreeUnusedLibraries()'
  321. !endif
  322. ;------------------------
  323. ;Done
  324. !ifdef LIBRARY_DEFINE_DONE_LABEL
  325. !undef LIBRARY_DEFINE_DONE_LABEL
  326. "installlib.done_${INSTALLLIB_UNIQUE}:"
  327. !endif
  328. Pop $R5
  329. Pop $R4
  330. Pop $R3
  331. Pop $R2
  332. Pop $R1
  333. Pop $R0
  334. ;------------------------
  335. ;End
  336. Goto "installlib.end_${INSTALLLIB_UNIQUE}"
  337. ;------------------------
  338. ;Extract
  339. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  340. SetOverwrite try
  341. !else
  342. SetOverwrite on
  343. !endif
  344. "installlib.file_${INSTALLLIB_UNIQUE}:"
  345. SetFileAttributes $R0 FILE_ATTRIBUTE_NORMAL
  346. ClearErrors
  347. File /oname=$R0 "${LOCALFILE}"
  348. Return
  349. SetOverwrite lastused
  350. ;------------------------
  351. ;Register on reboot
  352. !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  353. "installlib.regonreboot_${INSTALLLIB_UNIQUE}:"
  354. !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  355. !ifndef LIBRARY_X64
  356. !insertmacro __InstallLib_Helper_AddRegToolEntry 'D' "$R4" "$R5"
  357. !else
  358. !insertmacro __InstallLib_Helper_AddRegToolEntry 'DX' "$R4" "$R5"
  359. !endif
  360. !endif
  361. !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  362. !insertmacro __InstallLib_Helper_AddRegToolEntry 'T' "$R4" "$R5"
  363. !endif
  364. !ifdef INSTALLLIB_LIBTYPE_REGEXE
  365. !insertmacro __InstallLib_Helper_AddRegToolEntry 'E' "$R4" "$R5"
  366. !endif
  367. Return
  368. !endif
  369. ;------------------------
  370. ;End label
  371. "installlib.end_${INSTALLLIB_UNIQUE}:"
  372. !ifdef LIBRARY_X64
  373. ${EnableX64FSRedirection}
  374. !endif
  375. ;------------------------
  376. ;Undefine
  377. !undef INSTALLLIB_UNIQUE
  378. !undef ${INSTALLLIB_LIBTYPE_SET}
  379. !undef INSTALLLIB_LIBTYPE_SET
  380. !undef ${INSTALLLIB_SHARED_SET}
  381. !undef INSTALLLIB_SHARED_SET
  382. !undef ${INSTALLLIB_INSTALL_SET}
  383. !undef INSTALLLIB_INSTALL_SET
  384. !verbose pop
  385. !macroend
  386. ### Uninstall library
  387. !macro UnInstallLib libtype shared uninstall file
  388. !verbose push
  389. !verbose 3
  390. Push $R0
  391. Push $R1
  392. ;------------------------
  393. ;Define
  394. !define UNINSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  395. !define UNINSTALLLIB_LIBTYPE_${libtype}
  396. !define UNINSTALLLIB_LIBTYPE_SET UNINSTALLLIB_LIBTYPE_${libtype}
  397. !define UNINSTALLLIB_SHARED_${shared}
  398. !define UNINSTALLLIB_SHARED_SET UNINSTALLLIB_SHARED_${shared}
  399. !define UNINSTALLLIB_UNINSTALL_${uninstall}
  400. !define UNINSTALLLIB_UNINSTALL_SET UNINSTALLLIB_UNINSTALL_${uninstall}
  401. ;------------------------
  402. ;Validate
  403. !ifndef UNINSTALLLIB_LIBTYPE_DLL & UNINSTALLLIB_LIBTYPE_REGDLL & UNINSTALLLIB_LIBTYPE_TLB & \
  404. UNINSTALLLIB_LIBTYPE_REGDLLTLB & UNINSTALLLIB_LIBTYPE_REGEXE
  405. !error "UnInstallLib: Incorrect setting for parameter: libtype"
  406. !endif
  407. !ifndef UNINSTALLLIB_SHARED_NOTSHARED & UNINSTALLLIB_SHARED_SHARED
  408. !error "UnInstallLib: Incorrect setting for parameter: shared"
  409. !endif
  410. !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE & UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED & \
  411. UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED & UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED & \
  412. UNINSTALLLIB_UNINSTALL_NOREBOOT_NOTPROTECTED
  413. !error "UnInstallLib: Incorrect setting for parameter: uninstall"
  414. !endif
  415. ;------------------------
  416. ;x64 settings
  417. !ifdef LIBRARY_X64
  418. ${DisableX64FSRedirection}
  419. !endif
  420. ;------------------------
  421. ;Copy the parameters used on run-time to a variable
  422. ;This allows the usage of variables as parameter
  423. StrCpy $R1 "${file}"
  424. ;------------------------
  425. ;Shared library count
  426. !ifdef UNINSTALLLIB_SHARED_SHARED
  427. !define UNINSTALLLIB_DONE_LABEL
  428. !ifdef LIBRARY_X64
  429. SetRegView 64
  430. !endif
  431. ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  432. StrCmp $R0 "" "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  433. IntOp $R0 $R0 - 1
  434. IntCmp $R0 0 "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" \
  435. "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}"
  436. "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}:"
  437. DeleteRegValue HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  438. !ifndef UNINSTALLLIB_SHARED_SHAREDNOREMOVE
  439. Goto "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  440. !endif
  441. "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}:"
  442. WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1 $R0
  443. !ifdef LIBRARY_X64
  444. SetRegView lastused
  445. !endif
  446. Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  447. "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}:"
  448. !ifdef LIBRARY_X64
  449. SetRegView lastused
  450. !endif
  451. !endif
  452. ;------------------------
  453. ;Remove
  454. !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE
  455. ;------------------------
  456. ;Check Windows File Protection
  457. !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED
  458. !ifndef UNINSTALLLIB_DONE_LABEL
  459. !define UNINSTALLLIB_DONE_LABEL
  460. !endif
  461. System::Call "sfc::SfcIsFileProtected(i 0, w $R1) i.R0"
  462. StrCmp $R0 "error" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  463. StrCmp $R0 "0" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  464. Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  465. "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}:"
  466. !endif
  467. ;------------------------
  468. ;Unregister
  469. !ifdef UNINSTALLLIB_LIBTYPE_REGDLL | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  470. !ifndef LIBRARY_X64
  471. UnRegDLL $R1
  472. !else
  473. ExecWait '"$SYSDIR\regsvr32.exe" /s /u "$R1"'
  474. !endif
  475. !endif
  476. !ifdef UNINSTALLLIB_LIBTYPE_REGEXE
  477. ExecWait '"$R1" /unregserver'
  478. !endif
  479. !ifdef UNINSTALLLIB_LIBTYPE_TLB | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  480. TypeLib::UnRegister $R1
  481. !endif
  482. !ifdef LIBRARY_SHELL_EXTENSION
  483. System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  484. !endif
  485. !ifdef LIBRARY_COM
  486. System::Call 'Ole32::CoFreeUnusedLibraries()'
  487. !endif
  488. ;------------------------
  489. ;Delete
  490. Delete $R1
  491. !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED
  492. ${If} ${FileExists} $R1
  493. # File is in use, can't just delete.
  494. # Move file to another location before using Delete /REBOOTOK. This way, if
  495. # the user installs a new version of the DLL, it won't be deleted after
  496. # reboot. See bug #1097642 for more information on this.
  497. # Try moving to $TEMP.
  498. GetTempFileName $R0
  499. Delete $R0
  500. Rename $R1 $R0
  501. ${If} ${FileExists} $R1
  502. # Still here, delete temporary file, in case the file was copied
  503. # and not deleted. This happens when moving from network drives,
  504. # for example.
  505. Delete $R0
  506. # Try moving to directory containing the file.
  507. !insertmacro __InstallLib_Helper_GetParent $R1 $R0
  508. GetTempFileName $R0 $R0
  509. Delete $R0
  510. Rename $R1 $R0
  511. ${If} ${FileExists} $R1
  512. # Still here, delete temporary file.
  513. Delete $R0
  514. # Give up moving, simply Delete /REBOOTOK the file.
  515. StrCpy $R0 $R1
  516. ${EndIf}
  517. ${EndIf}
  518. # Delete the moved file.
  519. Delete /REBOOTOK $R0
  520. ${EndIf}
  521. !endif
  522. !endif
  523. ;------------------------
  524. ;Done
  525. !ifdef UNINSTALLLIB_DONE_LABEL
  526. !undef UNINSTALLLIB_DONE_LABEL
  527. "uninstalllib.done_${UNINSTALLLIB_UNIQUE}:"
  528. !endif
  529. !ifdef LIBRARY_X64
  530. ${EnableX64FSRedirection}
  531. !endif
  532. Pop $R1
  533. Pop $R0
  534. ;------------------------
  535. ;Undefine
  536. !undef UNINSTALLLIB_UNIQUE
  537. !undef ${UNINSTALLLIB_LIBTYPE_SET}
  538. !undef UNINSTALLLIB_LIBTYPE_SET
  539. !undef ${UNINSTALLLIB_SHARED_SET}
  540. !undef UNINSTALLLIB_SHARED_SET
  541. !undef ${UNINSTALLLIB_UNINSTALL_SET}
  542. !undef UNINSTALLLIB_UNINSTALL_SET
  543. !verbose pop
  544. !macroend
  545. !endif
  546. !verbose pop