home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Programming / nsis-2.46-setup.exe / Include / Library.nsh < prev    next >
Encoding:
Text File  |  2008-12-20  |  20.3 KB  |  871 lines

  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.  
  20. !verbose push
  21. !verbose 3
  22.  
  23. !ifndef LIB_INCLUDED
  24.  
  25. !define LIB_INCLUDED
  26.  
  27. !ifndef SHCNE_ASSOCCHANGED
  28.   !define SHCNE_ASSOCCHANGED 0x08000000
  29. !endif
  30. !ifndef SHCNF_IDLIST
  31.   !define SHCNF_IDLIST 0x0000
  32. !endif
  33.  
  34. !define REGTOOL_VERSION v3
  35. !define REGTOOL_KEY NSIS.Library.RegTool.${REGTOOL_VERSION}
  36.  
  37. !include LogicLib.nsh
  38. !include x64.nsh
  39.  
  40. ### GetParent macro, don't pass $1 or $2 as INTPUT or OUTPUT
  41. !macro __InstallLib_Helper_GetParent INPUT OUTPUT
  42.  
  43.   # Copied from FileFunc.nsh
  44.  
  45.   StrCpy ${OUTPUT} ${INPUT}
  46.  
  47.   Push $1
  48.   Push $2
  49.  
  50.   StrCpy $2 ${OUTPUT} 1 -1
  51.   StrCmp $2 '\' 0 +3
  52.   StrCpy ${OUTPUT} ${OUTPUT} -1
  53.   goto -3
  54.  
  55.   StrCpy $1 0
  56.   IntOp $1 $1 - 1
  57.   StrCpy $2 ${OUTPUT} 1 $1
  58.   StrCmp $2 '\' +2
  59.   StrCmp $2 '' 0 -3
  60.   StrCpy ${OUTPUT} ${OUTPUT} $1
  61.  
  62.   Pop $2
  63.   Pop $1
  64.  
  65. !macroend
  66.  
  67. ### Initialize session id (GUID)
  68. !macro __InstallLib_Helper_InitSession
  69.  
  70.   !ifndef __InstallLib_SessionGUID_Defined
  71.  
  72.     !define __InstallLib_SessionGUID_Defined
  73.  
  74.     Var /GLOBAL __INSTALLLLIB_SESSIONGUID
  75.  
  76.   !endif
  77.  
  78.   !define __InstallLib_Helper_InitSession_Label "Library_${__FILE__}${__LINE__}"
  79.  
  80.   StrCmp $__INSTALLLLIB_SESSIONGUID '' 0 "${__InstallLib_Helper_InitSession_Label}"
  81.  
  82.     System::Call 'ole32::CoCreateGuid(g .s)'
  83.     Pop $__INSTALLLLIB_SESSIONGUID
  84.  
  85.   "${__InstallLib_Helper_InitSession_Label}:"
  86.  
  87.   !undef __InstallLib_Helper_InitSession_Label
  88.  
  89. !macroend
  90.  
  91. ### Add a RegTool entry to register after reboot
  92. !macro __InstallLib_Helper_AddRegToolEntry mode filename tempdir
  93.  
  94.   Push $R0
  95.   Push $R1
  96.   Push $R2
  97.   Push $R3
  98.  
  99.   ;------------------------
  100.   ;Copy the parameters
  101.  
  102.   Push "${filename}"
  103.   Push "${tempdir}"
  104.  
  105.   Pop $R2 ; temporary directory
  106.   Pop $R1 ; file name to register
  107.  
  108.   ;------------------------
  109.   ;Initialize session id
  110.  
  111.   !insertmacro __InstallLib_Helper_InitSession
  112.  
  113.   ;------------------------
  114.   ;Advance counter
  115.  
  116.   StrCpy $R0 0
  117.   ReadRegDWORD $R0 HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "count"
  118.   IntOp $R0 $R0 + 1
  119.   WriteRegDWORD HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "count" "$R0"
  120.  
  121.   ;------------------------
  122.   ;Setup RegTool
  123.  
  124.   ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "${REGTOOL_KEY}"
  125.   StrCpy $R3 $R3 -4 1
  126.   IfFileExists $R3 +3
  127.  
  128.     File /oname=$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool.bin"
  129.     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
  130.       "${REGTOOL_KEY}" '"$R2\${REGTOOL_KEY}.$__INSTALLLLIB_SESSIONGUID.exe" /S'
  131.  
  132.   ;------------------------
  133.   ;Add RegTool entry
  134.  
  135.   WriteRegStr HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "$R0.file" "$R1"
  136.   WriteRegStr HKLM "Software\${REGTOOL_KEY}\$__INSTALLLLIB_SESSIONGUID" "$R0.mode" "${mode}"
  137.  
  138.   Pop $R3
  139.   Pop $R2
  140.   Pop $R1
  141.   Pop $R0
  142.  
  143. !macroend
  144.  
  145. ### Get library version
  146. !macro __InstallLib_Helper_GetVersion TYPE FILE
  147.  
  148.   !tempfile LIBRARY_TEMP_NSH
  149.  
  150.   !ifdef NSIS_WIN32_MAKENSIS
  151.  
  152.     !execute '"${NSISDIR}\Bin\LibraryLocal.exe" "${TYPE}" "${FILE}" "${LIBRARY_TEMP_NSH}"'
  153.  
  154.   !else
  155.  
  156.     !execute 'LibraryLocal "${TYPE}" "${FILE}" "${LIBRARY_TEMP_NSH}"'
  157.  
  158.     !if ${TYPE} == 'T'
  159.  
  160.       !warning "LibraryLocal currently supports TypeLibs version detection on Windows only"
  161.  
  162.     !endif
  163.  
  164.   !endif
  165.  
  166.   !include "${LIBRARY_TEMP_NSH}"
  167.   !delfile "${LIBRARY_TEMP_NSH}"
  168.   !undef LIBRARY_TEMP_NSH
  169.  
  170. !macroend
  171.  
  172. ### Install library
  173. !macro InstallLib libtype shared install localfile destfile tempbasedir
  174.  
  175.   !verbose push
  176.   !verbose 3
  177.  
  178.   Push $R0
  179.   Push $R1
  180.   Push $R2
  181.   Push $R3
  182.   Push $R4
  183.   Push $R5
  184.  
  185.   ;------------------------
  186.   ;Define
  187.  
  188.   !define INSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  189.  
  190.   !define INSTALLLIB_LIBTYPE_${libtype}
  191.   !define INSTALLLIB_LIBTYPE_SET INSTALLLIB_LIBTYPE_${libtype}
  192.   !define INSTALLLIB_SHARED_${shared}
  193.   !define INSTALLLIB_SHARED_SET INSTALLLIB_SHARED_${shared}
  194.   !define INSTALLLIB_INSTALL_${install}
  195.   !define INSTALLLIB_INSTALL_SET INSTALLLIB_INSTALL_${install}
  196.  
  197.   ;------------------------
  198.   ;Validate
  199.  
  200.   !ifndef INSTALLLIB_LIBTYPE_DLL & INSTALLLIB_LIBTYPE_REGDLL & INSTALLLIB_LIBTYPE_TLB & \
  201.     INSTALLLIB_LIBTYPE_REGDLLTLB & INSTALLLIB_LIBTYPE_REGEXE
  202.     !error "InstallLib: Incorrect setting for parameter: libtype"
  203.   !endif
  204.  
  205.   !ifndef INSTALLLIB_INSTALL_REBOOT_PROTECTED & INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED & \
  206.     INSTALLLIB_INSTALL_NOREBOOT_PROTECTED & INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  207.     !error "InstallLib: Incorrect setting for parameter: install"
  208.   !endif
  209.  
  210.   ;------------------------
  211.   ;x64 settings
  212.  
  213.   !ifdef LIBRARY_X64
  214.  
  215.     ${DisableX64FSRedirection}
  216.  
  217.   !endif
  218.  
  219.   ;------------------------
  220.   ;Copy the parameters used on run-time to a variable
  221.   ;This allows the usage of variables as parameter
  222.  
  223.   StrCpy $R4 "${destfile}"
  224.   StrCpy $R5 "${tempbasedir}"
  225.  
  226.   ;------------------------
  227.   ;Shared library count
  228.  
  229.   !ifndef INSTALLLIB_SHARED_NOTSHARED
  230.  
  231.     StrCmp ${shared} "" 0 "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}"
  232.  
  233.       !ifdef LIBRARY_X64
  234.  
  235.         SetRegView 64
  236.  
  237.       !endif
  238.  
  239.       ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4
  240.       ClearErrors
  241.       IntOp $R0 $R0 + 1
  242.       WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4 $R0
  243.  
  244.       !ifdef LIBRARY_X64
  245.  
  246.         SetRegView lastused
  247.  
  248.       !endif
  249.  
  250.     "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}:"
  251.  
  252.   !endif
  253.  
  254.   ;------------------------
  255.   ;Check Windows File Protection
  256.  
  257.   !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_PROTECTED
  258.  
  259.     !define LIBRARY_DEFINE_DONE_LABEL
  260.  
  261.     System::Call "sfc::SfcIsFileProtected(i 0, w R4) i.R0"
  262.  
  263.       StrCmp $R0 "error" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  264.       StrCmp $R0 "0" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  265.  
  266.     Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  267.  
  268.     "installlib.notprotected_${INSTALLLIB_UNIQUE}:"
  269.  
  270.   !endif
  271.  
  272.   ;------------------------
  273.   ;Check file
  274.  
  275.   IfFileExists $R4 0 "installlib.copy_${INSTALLLIB_UNIQUE}"
  276.  
  277.   ;------------------------
  278.   ;Get version information
  279.  
  280.   !ifndef LIBRARY_IGNORE_VERSION
  281.  
  282.     !insertmacro __InstallLib_Helper_GetVersion D "${LOCALFILE}"
  283.  
  284.     !ifdef LIBRARY_VERSION_FILENOTFOUND
  285.       !error "InstallLib: The library ${LOCALFILE} could not be found."
  286.     !endif
  287.  
  288.     !ifndef LIBRARY_VERSION_NONE
  289.  
  290.       !define LIBRARY_DEFINE_UPGRADE_LABEL
  291.       !define LIBRARY_DEFINE_REGISTER_LABEL
  292.  
  293.       StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  294.       StrCpy $R1 ${LIBRARY_VERSION_LOW}
  295.  
  296.       GetDLLVersion $R4 $R2 $R3
  297.  
  298.       !undef LIBRARY_VERSION_HIGH
  299.       !undef LIBRARY_VERSION_LOW
  300.  
  301.       !ifndef INSTALLLIB_LIBTYPE_TLB & INSTALLLIB_LIBTYPE_REGDLLTLB
  302.  
  303.         IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  304.         IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  305.           "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  306.  
  307.       !else
  308.  
  309.         !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  310.  
  311.         !ifdef LIBRARY_VERSION_FILENOTFOUND
  312.           !error "InstallLib: The library ${LOCALFILE} could not be found."
  313.         !endif
  314.  
  315.         !ifndef LIBRARY_VERSION_NONE
  316.  
  317.           IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  318.           IntCmpU $R1 $R3 0 "installlib.register_${INSTALLLIB_UNIQUE}" \
  319.             "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  320.  
  321.         !else
  322.  
  323.           IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  324.           IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  325.             "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  326.  
  327.         !endif
  328.  
  329.       !endif
  330.  
  331.     !else
  332.  
  333.       !undef LIBRARY_VERSION_NONE
  334.  
  335.       !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  336.  
  337.         !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  338.  
  339.       !endif
  340.  
  341.     !endif
  342.  
  343.     !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  344.  
  345.       !ifndef LIBRARY_VERSION_NONE
  346.  
  347.         !ifndef LIBRARY_DEFINE_UPGRADE_LABEL
  348.  
  349.           !define LIBRARY_DEFINE_UPGRADE_LABEL
  350.  
  351.         !endif
  352.  
  353.         !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  354.  
  355.           !define LIBRARY_DEFINE_REGISTER_LABEL
  356.  
  357.         !endif
  358.  
  359.         StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  360.         StrCpy $R1 ${LIBRARY_VERSION_LOW}
  361.  
  362.         TypeLib::GetLibVersion $R4
  363.         Pop $R3
  364.         Pop $R2
  365.  
  366.         IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  367.         IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  368.           "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  369.  
  370.         !undef LIBRARY_VERSION_HIGH
  371.         !undef LIBRARY_VERSION_LOW
  372.  
  373.       !else
  374.  
  375.         !undef LIBRARY_VERSION_NONE
  376.  
  377.       !endif
  378.  
  379.     !endif
  380.  
  381.   !endif
  382.  
  383.   ;------------------------
  384.   ;Upgrade
  385.  
  386.   !ifdef LIBRARY_DEFINE_UPGRADE_LABEL
  387.  
  388.     !undef LIBRARY_DEFINE_UPGRADE_LABEL
  389.  
  390.     "installlib.upgrade_${INSTALLLIB_UNIQUE}:"
  391.  
  392.   !endif
  393.  
  394.   ;------------------------
  395.   ;Copy
  396.  
  397.   !ifdef INSTALLLIB_INSTALL_NOREBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  398.  
  399.     "installlib.copy_${INSTALLLIB_UNIQUE}:"
  400.  
  401.     StrCpy $R0 $R4
  402.     Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  403.  
  404.   !else
  405.  
  406.     !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  407.  
  408.       !define LIBRARY_DEFINE_REGISTER_LABEL
  409.  
  410.     !endif
  411.  
  412.     !ifndef LIBRARY_DEFINE_DONE_LABEL
  413.  
  414.       !define LIBRARY_DEFINE_DONE_LABEL
  415.  
  416.     !endif
  417.  
  418.     ClearErrors
  419.  
  420.     StrCpy $R0 $R4
  421.     Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  422.  
  423.     IfErrors 0 "installlib.register_${INSTALLLIB_UNIQUE}"
  424.  
  425.     SetOverwrite lastused
  426.  
  427.     ;------------------------
  428.     ;Copy on reboot
  429.  
  430.     GetTempFileName $R0 $R5
  431.     Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  432.     Rename /REBOOTOK $R0 $R4
  433.  
  434.     ;------------------------
  435.     ;Register on reboot
  436.  
  437.     Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  438.  
  439.     Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  440.  
  441.     "installlib.copy_${INSTALLLIB_UNIQUE}:"
  442.       StrCpy $R0 $R4
  443.       Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  444.  
  445.   !endif
  446.  
  447.   ;------------------------
  448.   ;Register
  449.  
  450.   !ifdef LIBRARY_DEFINE_REGISTER_LABEL
  451.  
  452.     !undef LIBRARY_DEFINE_REGISTER_LABEL
  453.  
  454.     "installlib.register_${INSTALLLIB_UNIQUE}:"
  455.  
  456.   !endif
  457.  
  458.   !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB | INSTALLLIB_LIBTYPE_REGEXE
  459.  
  460.     !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  461.  
  462.       IfRebootFlag 0 "installlib.regnoreboot_${INSTALLLIB_UNIQUE}"
  463.  
  464.         Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  465.  
  466.         Goto "installlib.registerfinish_${INSTALLLIB_UNIQUE}"
  467.  
  468.       "installlib.regnoreboot_${INSTALLLIB_UNIQUE}:"
  469.  
  470.     !endif
  471.  
  472.     !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  473.  
  474.       TypeLib::Register $R4
  475.  
  476.     !endif
  477.  
  478.     !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  479.  
  480.       !ifndef LIBRARY_X64
  481.  
  482.         RegDll $R4
  483.  
  484.       !else
  485.  
  486.         ExecWait '"$SYSDIR\regsvr32.exe" /s "$R4"'
  487.  
  488.       !endif
  489.  
  490.     !endif
  491.  
  492.     !ifdef INSTALLLIB_LIBTYPE_REGEXE
  493.  
  494.       ExecWait '"$R4" /regserver'
  495.  
  496.     !endif
  497.  
  498.     !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  499.  
  500.       "installlib.registerfinish_${INSTALLLIB_UNIQUE}:"
  501.  
  502.     !endif
  503.  
  504.   !endif
  505.  
  506.   !ifdef LIBRARY_SHELL_EXTENSION
  507.  
  508.     System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  509.  
  510.   !endif
  511.  
  512.   !ifdef LIBRARY_COM
  513.  
  514.     System::Call 'Ole32::CoFreeUnusedLibraries()'
  515.  
  516.   !endif
  517.  
  518.   ;------------------------
  519.   ;Done
  520.  
  521.   !ifdef LIBRARY_DEFINE_DONE_LABEL
  522.  
  523.     !undef LIBRARY_DEFINE_DONE_LABEL
  524.  
  525.   "installlib.done_${INSTALLLIB_UNIQUE}:"
  526.  
  527.   !endif
  528.  
  529.   Pop $R5
  530.   Pop $R4
  531.   Pop $R3
  532.   Pop $R2
  533.   Pop $R1
  534.   Pop $R0
  535.  
  536.   ;------------------------
  537.   ;End
  538.  
  539.   Goto "installlib.end_${INSTALLLIB_UNIQUE}"
  540.  
  541.   ;------------------------
  542.   ;Extract
  543.  
  544.   !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  545.  
  546.     SetOverwrite try
  547.  
  548.   !else
  549.  
  550.     SetOverwrite on
  551.  
  552.   !endif
  553.  
  554.   "installlib.file_${INSTALLLIB_UNIQUE}:"
  555.     SetFileAttributes $R0 FILE_ATTRIBUTE_NORMAL
  556.     ClearErrors
  557.     File /oname=$R0 "${LOCALFILE}"
  558.     Return
  559.  
  560.   SetOverwrite lastused
  561.  
  562.   ;------------------------
  563.   ;Register on reboot
  564.  
  565.   !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  566.  
  567.     "installlib.regonreboot_${INSTALLLIB_UNIQUE}:"
  568.  
  569.       !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  570.         !ifndef LIBRARY_X64
  571.           !insertmacro __InstallLib_Helper_AddRegToolEntry 'D' "$R4" "$R5"
  572.         !else
  573.           !insertmacro __InstallLib_Helper_AddRegToolEntry 'DX' "$R4" "$R5"
  574.         !endif
  575.       !endif
  576.  
  577.       !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  578.         !insertmacro __InstallLib_Helper_AddRegToolEntry 'T' "$R4" "$R5"
  579.       !endif
  580.  
  581.       !ifdef INSTALLLIB_LIBTYPE_REGEXE
  582.         !insertmacro __InstallLib_Helper_AddRegToolEntry 'E' "$R4" "$R5"
  583.       !endif
  584.  
  585.       Return
  586.  
  587.   !endif
  588.  
  589.   ;------------------------
  590.   ;End label
  591.  
  592.   "installlib.end_${INSTALLLIB_UNIQUE}:"
  593.  
  594.   !ifdef LIBRARY_X64
  595.  
  596.     ${EnableX64FSRedirection}
  597.  
  598.   !endif
  599.  
  600.   ;------------------------
  601.   ;Undefine
  602.  
  603.   !undef INSTALLLIB_UNIQUE
  604.  
  605.   !undef ${INSTALLLIB_LIBTYPE_SET}
  606.   !undef INSTALLLIB_LIBTYPE_SET
  607.   !undef ${INSTALLLIB_SHARED_SET}
  608.   !undef INSTALLLIB_SHARED_SET
  609.   !undef ${INSTALLLIB_INSTALL_SET}
  610.   !undef INSTALLLIB_INSTALL_SET
  611.  
  612.   !verbose pop
  613.  
  614. !macroend
  615.  
  616. ### Uninstall library
  617. !macro UnInstallLib libtype shared uninstall file
  618.  
  619.   !verbose push
  620.   !verbose 3
  621.  
  622.   Push $R0
  623.   Push $R1
  624.  
  625.   ;------------------------
  626.   ;Define
  627.  
  628.   !define UNINSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  629.  
  630.   !define UNINSTALLLIB_LIBTYPE_${libtype}
  631.   !define UNINSTALLLIB_LIBTYPE_SET UNINSTALLLIB_LIBTYPE_${libtype}
  632.   !define UNINSTALLLIB_SHARED_${shared}
  633.   !define UNINSTALLLIB_SHARED_SET UNINSTALLLIB_SHARED_${shared}
  634.   !define UNINSTALLLIB_UNINSTALL_${uninstall}
  635.   !define UNINSTALLLIB_UNINSTALL_SET UNINSTALLLIB_UNINSTALL_${uninstall}
  636.  
  637.   ;------------------------
  638.   ;Validate
  639.  
  640.   !ifndef UNINSTALLLIB_LIBTYPE_DLL & UNINSTALLLIB_LIBTYPE_REGDLL & UNINSTALLLIB_LIBTYPE_TLB & \
  641.     UNINSTALLLIB_LIBTYPE_REGDLLTLB & UNINSTALLLIB_LIBTYPE_REGEXE
  642.     !error "UnInstallLib: Incorrect setting for parameter: libtype"
  643.   !endif
  644.  
  645.   !ifndef UNINSTALLLIB_SHARED_NOTSHARED & UNINSTALLLIB_SHARED_SHARED
  646.     !error "UnInstallLib: Incorrect setting for parameter: shared"
  647.   !endif
  648.  
  649.   !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE & UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED & \
  650.     UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED & UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED & \
  651.     UNINSTALLLIB_UNINSTALL_NOREBOOT_NOTPROTECTED
  652.     !error "UnInstallLib: Incorrect setting for parameter: uninstall"
  653.   !endif
  654.  
  655.   ;------------------------
  656.   ;x64 settings
  657.  
  658.   !ifdef LIBRARY_X64
  659.  
  660.     ${DisableX64FSRedirection}
  661.  
  662.   !endif
  663.  
  664.   ;------------------------
  665.   ;Copy the parameters used on run-time to a variable
  666.   ;This allows the usage of variables as parameter
  667.  
  668.   StrCpy $R1 "${file}"
  669.  
  670.   ;------------------------
  671.   ;Shared library count
  672.  
  673.   !ifdef UNINSTALLLIB_SHARED_SHARED
  674.  
  675.     !define UNINSTALLLIB_DONE_LABEL
  676.  
  677.     !ifdef LIBRARY_X64
  678.  
  679.       SetRegView 64
  680.  
  681.     !endif
  682.  
  683.     ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  684.     StrCmp $R0 "" "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  685.  
  686.     IntOp $R0 $R0 - 1
  687.     IntCmp $R0 0 "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" \
  688.       "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}"
  689.  
  690.     "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}:"
  691.       DeleteRegValue HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  692.       !ifndef UNINSTALLLIB_SHARED_SHAREDNOREMOVE
  693.         Goto "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  694.       !endif
  695.  
  696.     "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}:"
  697.       WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1 $R0
  698.  
  699.         !ifdef LIBRARY_X64
  700.  
  701.           SetRegView lastused
  702.  
  703.         !endif
  704.  
  705.       Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  706.  
  707.     "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}:"
  708.  
  709.     !ifdef LIBRARY_X64
  710.  
  711.       SetRegView lastused
  712.  
  713.     !endif
  714.  
  715.   !endif
  716.  
  717.   ;------------------------
  718.   ;Remove
  719.  
  720.   !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE
  721.  
  722.     ;------------------------
  723.     ;Check Windows File Protection
  724.  
  725.     !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED
  726.  
  727.       !ifndef UNINSTALLLIB_DONE_LABEL
  728.  
  729.         !define UNINSTALLLIB_DONE_LABEL
  730.  
  731.       !endif
  732.  
  733.       System::Call "sfc::SfcIsFileProtected(i 0, w $R1) i.R0"
  734.  
  735.         StrCmp $R0 "error" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  736.         StrCmp $R0 "0" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  737.  
  738.       Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  739.  
  740.       "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}:"
  741.  
  742.     !endif
  743.  
  744.     ;------------------------
  745.     ;Unregister
  746.  
  747.     !ifdef UNINSTALLLIB_LIBTYPE_REGDLL | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  748.  
  749.       !ifndef LIBRARY_X64
  750.  
  751.         UnRegDLL $R1
  752.  
  753.       !else
  754.  
  755.         ExecWait '"$SYSDIR\regsvr32.exe" /s /u "$R1"'
  756.  
  757.       !endif
  758.  
  759.     !endif
  760.  
  761.     !ifdef UNINSTALLLIB_LIBTYPE_REGEXE
  762.  
  763.       ExecWait '"$R1" /unregserver'
  764.  
  765.     !endif
  766.  
  767.     !ifdef UNINSTALLLIB_LIBTYPE_TLB | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  768.  
  769.       TypeLib::UnRegister $R1
  770.  
  771.     !endif
  772.  
  773.     !ifdef LIBRARY_SHELL_EXTENSION
  774.  
  775.       System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  776.  
  777.     !endif
  778.  
  779.     !ifdef LIBRARY_COM
  780.  
  781.       System::Call 'Ole32::CoFreeUnusedLibraries()'
  782.  
  783.     !endif
  784.  
  785.     ;------------------------
  786.     ;Delete
  787.  
  788.     Delete $R1
  789.  
  790.     !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED
  791.  
  792.       ${If} ${FileExists} $R1
  793.         # File is in use, can't just delete.
  794.         # Move file to another location before using Delete /REBOOTOK. This way, if
  795.         #  the user installs a new version of the DLL, it won't be deleted after
  796.         #  reboot. See bug #1097642 for more information on this.
  797.  
  798.         # Try moving to $TEMP.
  799.         GetTempFileName $R0
  800.         Delete $R0
  801.         Rename $R1 $R0
  802.  
  803.         ${If} ${FileExists} $R1
  804.           # Still here, delete temporary file, in case the file was copied
  805.           #  and not deleted. This happens when moving from network drives,
  806.           #  for example.
  807.           Delete $R0
  808.  
  809.           # Try moving to directory containing the file.
  810.           !insertmacro __InstallLib_Helper_GetParent $R1 $R0
  811.           GetTempFileName $R0 $R0
  812.           Delete $R0
  813.           Rename $R1 $R0
  814.  
  815.           ${If} ${FileExists} $R1
  816.             # Still here, delete temporary file.
  817.             Delete $R0
  818.  
  819.             # Give up moving, simply Delete /REBOOTOK the file.
  820.             StrCpy $R0 $R1
  821.           ${EndIf}
  822.         ${EndIf}
  823.  
  824.         # Delete the moved file.
  825.         Delete /REBOOTOK $R0
  826.       ${EndIf}
  827.  
  828.     !endif
  829.  
  830.   !endif
  831.  
  832.   ;------------------------
  833.   ;Done
  834.  
  835.   !ifdef UNINSTALLLIB_DONE_LABEL
  836.  
  837.     !undef UNINSTALLLIB_DONE_LABEL
  838.  
  839.     "uninstalllib.done_${UNINSTALLLIB_UNIQUE}:"
  840.  
  841.   !endif
  842.  
  843.   !ifdef LIBRARY_X64
  844.  
  845.     ${EnableX64FSRedirection}
  846.  
  847.   !endif
  848.  
  849.   Pop $R1
  850.   Pop $R0
  851.  
  852.   ;------------------------
  853.   ;Undefine
  854.  
  855.   !undef UNINSTALLLIB_UNIQUE
  856.  
  857.   !undef ${UNINSTALLLIB_LIBTYPE_SET}
  858.   !undef UNINSTALLLIB_LIBTYPE_SET
  859.   !undef ${UNINSTALLLIB_SHARED_SET}
  860.   !undef UNINSTALLLIB_SHARED_SET
  861.   !undef ${UNINSTALLLIB_UNINSTALL_SET}
  862.   !undef UNINSTALLLIB_UNINSTALL_SET
  863.  
  864.   !verbose pop
  865.  
  866. !macroend
  867.  
  868. !endif
  869.  
  870. !verbose pop
  871.