Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (4,88 ko)

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.v2\UpgradeDLLSession" "count"
64
  IntOp $R0 $R0 + 1
65
  WriteRegDWORD HKLM "Software\NSIS.Library.RegTool.v2\UpgradeDLLSession" "count" "$R0"
66

    
67
  ;------------------------
68
  ;Setup RegTool
69

    
70
  ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "NSIS.Library.RegTool.v2"
71
  StrCpy $R3 $R3 -4 1
72
  IfFileExists $R3 +3
73

    
74
    File /oname=$R2\NSIS.Library.RegTool.v2.$HWNDPARENT.exe "${NSISDIR}\Bin\RegTool.bin"
75
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
76
      "NSIS.Library.RegTool.v2" '"$R2\NSIS.Library.RegTool.v2.$HWNDPARENT.exe" /S'
77

    
78
  ;------------------------
79
  ;Add RegTool entry
80

    
81
  WriteRegStr HKLM "Software\NSIS.Library.RegTool.v2\UpgradeDLLSession" "$R0.file" "$R1"
82
  WriteRegStr HKLM "Software\NSIS.Library.RegTool.v2\UpgradeDLLSession" "$R0.mode" "${mode}"
83

    
84
  Pop $R3
85
  Pop $R2
86
  Pop $R1
87
  Pop $R0
88

    
89
!macroend
90

    
91
!macro UpgradeDLL LOCALFILE DESTFILE TEMPBASEDIR
92

    
93
  Push $R0
94
  Push $R1
95
  Push $R2
96
  Push $R3
97
  Push $R4
98
  Push $R5
99

    
100
  !define UPGRADEDLL_UNIQUE "${__FILE__}${__LINE__}"
101

    
102
  SetOverwrite try
103

    
104
  ;------------------------
105
  ;Copy the parameters used on run-time to a variable
106
  ;This allows the usage of variables as paramter
107

    
108
  StrCpy $R4 "${DESTFILE}"
109
  StrCpy $R5 "${TEMPBASEDIR}"
110

    
111
  ;------------------------
112
  ;Get version information
113

    
114
  IfFileExists $R4 0 "upgradedll.copy_${UPGRADEDLL_UNIQUE}"
115

    
116
  ClearErrors
117
    GetDLLVersionLocal "${LOCALFILE}" $R0 $R1
118
    GetDLLVersion $R4 $R2 $R3
119
  IfErrors "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
120

    
121
  IntCmpU $R0 $R2 0 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
122
  IntCmpU $R1 $R3 "upgradedll.done_${UPGRADEDLL_UNIQUE}" "upgradedll.done_${UPGRADEDLL_UNIQUE}" \
123
    "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}"
124

    
125
  ;------------------------
126
  ;Upgrade
127

    
128
  "upgradedll.upgrade_${UPGRADEDLL_UNIQUE}:"
129
    !ifndef UPGRADEDLL_NOREGISTER
130
      ;Unregister the DLL
131
      UnRegDLL $R4
132
    !endif
133

    
134
  ;------------------------
135
  ;Copy
136

    
137
  ClearErrors
138
    StrCpy $R0 $R4
139
    Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
140
  IfErrors 0 "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}"
141

    
142
  ;------------------------
143
  ;Copy on reboot
144

    
145
  GetTempFileName $R0 $R5
146
    Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
147
  Rename /REBOOTOK $R0 $R4
148

    
149
  ;------------------------
150
  ;Register on reboot
151

    
152
  !insertmacro __UpgradeDLL_Helper_AddRegToolEntry 'D' $R4 $R5
153

    
154
  Goto "upgradedll.done_${UPGRADEDLL_UNIQUE}"
155

    
156
  ;------------------------
157
  ;DLL does not exist
158

    
159
  "upgradedll.copy_${UPGRADEDLL_UNIQUE}:"
160
    StrCpy $R0 $R4
161
    Call ":upgradedll.file_${UPGRADEDLL_UNIQUE}"
162

    
163
  ;------------------------
164
  ;Register
165

    
166
  "upgradedll.noreboot_${UPGRADEDLL_UNIQUE}:"
167
    !ifndef UPGRADEDLL_NOREGISTER
168
      RegDLL $R4
169
    !endif
170

    
171
  ;------------------------
172
  ;Done
173

    
174
  "upgradedll.done_${UPGRADEDLL_UNIQUE}:"
175

    
176
  Pop $R5
177
  Pop $R4
178
  Pop $R3
179
  Pop $R2
180
  Pop $R1
181
  Pop $R0
182

    
183
  ;------------------------
184
  ;End
185

    
186
  Goto "upgradedll.end_${UPGRADEDLL_UNIQUE}"
187

    
188
  ;------------------------
189
  ;Extract
190

    
191
  "upgradedll.file_${UPGRADEDLL_UNIQUE}:"
192
    File /oname=$R0 "${LOCALFILE}"
193
    Return
194

    
195
  "upgradedll.end_${UPGRADEDLL_UNIQUE}:"
196

    
197
  SetOverwrite lastused
198
  
199
  !undef UPGRADEDLL_UNIQUE
200

    
201
!macroend
202

    
203
!endif