Debian Codegraph @

Include/UpgradeDLL.nsh

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