home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Include / UpgradeDLL.nsh < prev    next >
Text File  |  2003-12-24  |  4KB  |  147 lines

  1. !ifndef UPGRADEDLL_INCLUDED
  2.  
  3. !define UPGRADEDLL_INCLUDED
  4.  
  5. ; Macro - Upgrade DLL File
  6. ; Written by Joost Verburg
  7. ; ------------------------
  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 support, this should be on the same volume as the DESTFILE!
  15. ;               The Windows temp directory could be located on any volume, so you cannot use
  16. ;               this directory.
  17. ;
  18. ; Define UPGRADEDLL_NOREGISTER if you want to upgrade a DLL that does not have to be registered.
  19. ;
  20. ; Note: If you want to support Win9x, you can only use short filenames (8.3).
  21. ;
  22. ; Example of usage:
  23. ; !insertmacro UpgradeDLL "dllname.dll" "$SYSDIR\dllname.dll" "$SYSDIR"
  24. ;
  25.  
  26. !macro UpgradeDLL LOCALFILE DESTFILE TEMPBASEDIR
  27.  
  28.   Push $R0
  29.   Push $R1
  30.   Push $R2
  31.   Push $R3
  32.   Push $R4
  33.   Push $R5
  34.  
  35.   ;------------------------
  36.   ;Unique number for labels
  37.  
  38.   !define UPGRADEDLL_UNIQUE ${__LINE__}
  39.  
  40.   ;------------------------
  41.   ;Copy the parameters used on run-time to a variable
  42.   ;This allows the usage of variables as paramter
  43.  
  44.   StrCpy $R4 "${DESTFILE}"
  45.   StrCpy $R5 "${TEMPBASEDIR}"
  46.  
  47.   ;------------------------
  48.   ;Check file and version
  49.  
  50.   IfFileExists $R4 0 upgradedll.copy_${UPGRADEDLL_UNIQUE}
  51.  
  52.   ClearErrors
  53.     GetDLLVersionLocal "${LOCALFILE}" $R0 $R1
  54.     GetDLLVersion $R4 $R2 $R3
  55.   IfErrors upgradedll.upgrade_${UPGRADEDLL_UNIQUE}
  56.  
  57.   IntCmpU $R0 $R2 0 upgradedll.done_${UPGRADEDLL_UNIQUE} upgradedll.upgrade_${UPGRADEDLL_UNIQUE}
  58.   IntCmpU $R1 $R3 upgradedll.done_${UPGRADEDLL_UNIQUE} upgradedll.done_${UPGRADEDLL_UNIQUE} \
  59.     upgradedll.upgrade_${UPGRADEDLL_UNIQUE}
  60.  
  61.   ;------------------------
  62.   ;Let's upgrade the DLL!
  63.  
  64.   SetOverwrite try
  65.  
  66.   upgradedll.upgrade_${UPGRADEDLL_UNIQUE}:
  67.     !ifndef UPGRADEDLL_NOREGISTER
  68.       ;Unregister the DLL
  69.       UnRegDLL $R4
  70.     !endif
  71.  
  72.   ;------------------------
  73.   ;Try to copy the DLL directly
  74.  
  75.   ClearErrors
  76.     StrCpy $R0 $R4
  77.     Call :upgradedll.file_${UPGRADEDLL_UNIQUE}
  78.   IfErrors 0 upgradedll.noreboot_${UPGRADEDLL_UNIQUE}
  79.  
  80.   ;------------------------
  81.   ;DLL is in use. Copy it to a temp file and Rename it on reboot.
  82.  
  83.   GetTempFileName $R0 $R5
  84.     Call :upgradedll.file_${UPGRADEDLL_UNIQUE}
  85.   Rename /REBOOTOK $R0 $R4
  86.  
  87.   ;------------------------
  88.   ;Register the DLL on reboot
  89.  
  90.   !ifndef UPGRADEDLL_NOREGISTER
  91.     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
  92.       "Register $R4" '"$SYSDIR\rundll32.exe" "$R4",DllRegisterServer'
  93.   !endif
  94.  
  95.   Goto upgradedll.done_${UPGRADEDLL_UNIQUE}
  96.  
  97.   ;------------------------
  98.   ;DLL does not exist - just extract
  99.  
  100.   upgradedll.copy_${UPGRADEDLL_UNIQUE}:
  101.     StrCpy $R0 $R4
  102.     Call :upgradedll.file_${UPGRADEDLL_UNIQUE}
  103.  
  104.   ;------------------------
  105.   ;Register the DLL
  106.  
  107.   upgradedll.noreboot_${UPGRADEDLL_UNIQUE}:
  108.     !ifndef UPGRADEDLL_NOREGISTER
  109.       RegDLL $R4
  110.     !endif
  111.  
  112.   ;------------------------
  113.   ;Done
  114.  
  115.   upgradedll.done_${UPGRADEDLL_UNIQUE}:
  116.  
  117.   Pop $R5
  118.   Pop $R4
  119.   Pop $R3
  120.   Pop $R2
  121.   Pop $R1
  122.   Pop $R0
  123.  
  124.   ;------------------------
  125.   ;End
  126.  
  127.   Goto upgradedll.end_${UPGRADEDLL_UNIQUE}
  128.  
  129.   ;------------------------
  130.   ;Called to extract the DLL
  131.  
  132.   upgradedll.file_${UPGRADEDLL_UNIQUE}:
  133.     File /oname=$R0 "${LOCALFILE}"
  134.     Return
  135.  
  136.   upgradedll.end_${UPGRADEDLL_UNIQUE}:
  137.  
  138.  ;------------------------
  139.  ;Restore settings
  140.  
  141.  SetOverwrite lastused
  142.  
  143.  !undef UPGRADEDLL_UNIQUE
  144.  
  145. !macroend
  146.  
  147. !endif