Statistiques
| Révision :

root / tmp / org.txm.setups / nsis / Include / UpgradeDLL.nsh @ 3117

Historique | Voir | Annoter | Télécharger (5,01 ko)

1 728 mdecorde
/*
2 728 mdecorde
3 728 mdecorde
NOTE:
4 728 mdecorde
-----
5 728 mdecorde
This macro is provided for backwards compatibility with NSIS 2.0 scripts.
6 728 mdecorde
It's recommended you update your scripts to use the new Library.nsh macros.
7 728 mdecorde
8 728 mdecorde
9 728 mdecorde
Macro - Upgrade DLL File
10 728 mdecorde
Written by Joost Verburg
11 728 mdecorde
------------------------
12 728 mdecorde
13 728 mdecorde
Parameters:
14 728 mdecorde
LOCALFILE		Location of the new DLL file (on the compiler system)
15 728 mdecorde
DESTFILE		Location of the DLL file that should be upgraded (on the user's system)
16 728 mdecorde
TEMPBASEDIR		Directory on the user's system to store a temporary file when the system has
17 728 mdecorde
				to be rebooted.
18 728 mdecorde
				For Win9x/ME support, this should be on the same volume as DESTFILE.
19 728 mdecorde
				The Windows temp directory could be located on any volume, so you cannot use
20 728 mdecorde
				this directory.
21 728 mdecorde
22 728 mdecorde
Define UPGRADEDLL_NOREGISTER if you want to upgrade a DLL that does not have to be registered.
23 728 mdecorde
24 728 mdecorde
Notes:
25 728 mdecorde
26 728 mdecorde
* If you want to support Windows 9x/ME, you can only use short filenames (8.3).
27 728 mdecorde
28 728 mdecorde
* This macro uses the GetDLLVersionLocal command to retrieve the version of local libraries.
29 728 mdecorde
  This command is only supported when compiling on a Windows system.
30 728 mdecorde
31 728 mdecorde
------------------------
32 728 mdecorde
33 728 mdecorde
Example:
34 728 mdecorde
35 728 mdecorde
!insertmacro UpgradeDLL "dllname.dll" "$SYSDIR\dllname.dll" "$SYSDIR"
36 728 mdecorde
37 728 mdecorde
*/
38 728 mdecorde
39 728 mdecorde
!ifndef UPGRADEDLL_INCLUDED
40 728 mdecorde
41 728 mdecorde
!define UPGRADEDLL_INCLUDED
42 728 mdecorde
43 728 mdecorde
!macro __UpgradeDLL_Helper_AddRegToolEntry mode filename tempdir
44 728 mdecorde
45 728 mdecorde
  Push $R0
46 728 mdecorde
  Push $R1
47 728 mdecorde
  Push $R2
48 728 mdecorde
  Push $R3
49 728 mdecorde
50 728 mdecorde
  ;------------------------
51 728 mdecorde
  ;Copy the parameters
52 728 mdecorde
53 728 mdecorde
  Push "${filename}"
54 728 mdecorde
  Push "${tempdir}"
55 728 mdecorde
56 728 mdecorde
  Pop $R2 ; temporary directory
57 728 mdecorde
  Pop $R1 ; file name to register
58 728 mdecorde
59 728 mdecorde
  ;------------------------
60 728 mdecorde
  ;Advance counter
61 728 mdecorde
62 728 mdecorde
  StrCpy $R0 0
63 2956 mdecorde
  ReadRegDWORD $R0 HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "count"
64 728 mdecorde
  IntOp $R0 $R0 + 1
65 2956 mdecorde
  WriteRegDWORD HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "count" "$R0"
66 728 mdecorde
67 728 mdecorde
  ;------------------------
68 728 mdecorde
  ;Setup RegTool
69 728 mdecorde
70 2956 mdecorde
  !if ! /FileExists "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin"
71 2956 mdecorde
    !error "Missing RegTool for ${NSIS_CPU}!"
72 2956 mdecorde
  !endif
73 2956 mdecorde
74 2956 mdecorde
  ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "NSIS.Library.RegTool.v3"
75 728 mdecorde
  StrCpy $R3 $R3 -4 1
76 728 mdecorde
  IfFileExists $R3 +3
77 728 mdecorde
78 2956 mdecorde
    File /oname=$R2\NSIS.Library.RegTool.v3.$HWNDPARENT.exe "${NSISDIR}\Bin\RegTool-${NSIS_CPU}.bin"
79 728 mdecorde
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
80 2956 mdecorde
      "NSIS.Library.RegTool.v3" '"$R2\NSIS.Library.RegTool.v3.$HWNDPARENT.exe" /S'
81 728 mdecorde
82 728 mdecorde
  ;------------------------
83 728 mdecorde
  ;Add RegTool entry
84 728 mdecorde
85 2956 mdecorde
  WriteRegStr HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "$R0.file" "$R1"
86 2956 mdecorde
  WriteRegStr HKLM "Software\NSIS.Library.RegTool.v3\UpgradeDLLSession" "$R0.mode" "${mode}"
87 728 mdecorde
88 728 mdecorde
  Pop $R3
89 728 mdecorde
  Pop $R2
90 728 mdecorde
  Pop $R1
91 728 mdecorde
  Pop $R0
92 728 mdecorde
93 728 mdecorde
!macroend
94 728 mdecorde
95 728 mdecorde
!macro UpgradeDLL LOCALFILE DESTFILE TEMPBASEDIR
96 728 mdecorde
97 728 mdecorde
  Push $R0
98 728 mdecorde
  Push $R1
99 728 mdecorde
  Push $R2
100 728 mdecorde
  Push $R3
101 728 mdecorde
  Push $R4
102 728 mdecorde
  Push $R5
103 728 mdecorde
104 728 mdecorde
  !define UPGRADEDLL_UNIQUE "${__FILE__}${__LINE__}"
105 728 mdecorde
106 728 mdecorde
  SetOverwrite try
107 728 mdecorde
108 728 mdecorde
  ;------------------------
109 2956 mdecorde
  ;Copy the macro parameters to a run-time to a variable,
110 2956 mdecorde
  ;this allows the usage of variables as parameter
111 728 mdecorde
112 728 mdecorde
  StrCpy $R4 "${DESTFILE}"
113 728 mdecorde
  StrCpy $R5 "${TEMPBASEDIR}"
114 728 mdecorde
115 728 mdecorde
  ;------------------------
116 728 mdecorde
  ;Get version information
117 728 mdecorde
118 728 mdecorde
  IfFileExists $R4 0 "upgradedll.copy_${UPGRADEDLL_UNIQUE}"
119 728 mdecorde
120 728 mdecorde
  ClearErrors
121 728 mdecorde
    GetDLLVersionLocal "${LOCALFILE}" $R0 $R1
122 728 mdecorde
    GetDLLVersion $R4 $R2 $R3
123 728 mdecorde
  IfErrors "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
124 728 mdecorde
125 728 mdecorde
  IntCmpU $R0 $R2 0 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
126 728 mdecorde
  IntCmpU $R1 $R3 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.done_${UPGRADEDLL_UNIQUE}" \
127 728 mdecorde
    "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
128 728 mdecorde
129 728 mdecorde
  ;------------------------
130 728 mdecorde
  ;Upgrade
131 728 mdecorde
132 728 mdecorde
  "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}:"
133 728 mdecorde
    !ifndef UPGRADEDLL_NOREGISTER
134 728 mdecorde
      ;Unregister the DLL
135 728 mdecorde
      UnRegDLL $R4
136 728 mdecorde
    !endif
137 728 mdecorde
138 728 mdecorde
  ;------------------------
139 728 mdecorde
  ;Copy
140 728 mdecorde
141 728 mdecorde
  ClearErrors
142 728 mdecorde
    StrCpy $R0 $R4
143 728 mdecorde
    Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
144 728 mdecorde
  IfErrors 0 "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}"
145 728 mdecorde
146 728 mdecorde
  ;------------------------
147 728 mdecorde
  ;Copy on reboot
148 728 mdecorde
149 728 mdecorde
  GetTempFileName $R0 $R5
150 728 mdecorde
    Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
151 728 mdecorde
  Rename /REBOOTOK $R0 $R4
152 728 mdecorde
153 728 mdecorde
  ;------------------------
154 728 mdecorde
  ;Register on reboot
155 728 mdecorde
156 728 mdecorde
  !insertmacro __UpgradeDLL_Helper_AddRegToolEntry 'D' $R4 $R5
157 728 mdecorde
158 728 mdecorde
  Goto "upgradedll.done_${UPGRADEDLL_UNIQUE}"
159 728 mdecorde
160 728 mdecorde
  ;------------------------
161 728 mdecorde
  ;DLL does not exist
162 728 mdecorde
163 728 mdecorde
  "upgradedll.copy_${UPGRADEDLL_UNIQUE}:"
164 728 mdecorde
    StrCpy $R0 $R4
165 728 mdecorde
    Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
166 728 mdecorde
167 728 mdecorde
  ;------------------------
168 728 mdecorde
  ;Register
169 728 mdecorde
170 728 mdecorde
  "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}:"
171 728 mdecorde
    !ifndef UPGRADEDLL_NOREGISTER
172 728 mdecorde
      RegDLL $R4
173 728 mdecorde
    !endif
174 728 mdecorde
175 728 mdecorde
  ;------------------------
176 728 mdecorde
  ;Done
177 728 mdecorde
178 728 mdecorde
  "upgradedll.done_${UPGRADEDLL_UNIQUE}:"
179 728 mdecorde
180 728 mdecorde
  Pop $R5
181 728 mdecorde
  Pop $R4
182 728 mdecorde
  Pop $R3
183 728 mdecorde
  Pop $R2
184 728 mdecorde
  Pop $R1
185 728 mdecorde
  Pop $R0
186 728 mdecorde
187 728 mdecorde
  ;------------------------
188 728 mdecorde
  ;End
189 728 mdecorde
190 728 mdecorde
  Goto "upgradedll.end_${UPGRADEDLL_UNIQUE}"
191 728 mdecorde
192 728 mdecorde
  ;------------------------
193 728 mdecorde
  ;Extract
194 728 mdecorde
195 728 mdecorde
  "upgradedll.file_${UPGRADEDLL_UNIQUE}:"
196 728 mdecorde
    File /oname=$R0 "${LOCALFILE}"
197 728 mdecorde
    Return
198 728 mdecorde
199 728 mdecorde
  "upgradedll.end_${UPGRADEDLL_UNIQUE}:"
200 728 mdecorde
201 728 mdecorde
  SetOverwrite lastused
202 728 mdecorde
203 728 mdecorde
  !undef UPGRADEDLL_UNIQUE
204 728 mdecorde
205 728 mdecorde
!macroend
206 728 mdecorde
207 728 mdecorde
!endif