Subversion Repositories DevTools

Rev

Rev 2322 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2322 gchristi 1
!include "FileFunc.nsh"
2
 
3
;---------------------------------------------------------------------------------------------------
4
; macro VIX_CREATE_UNINSTALLER_AND_REGISTRY
5
; Creates the uninstaller and creates the registry entries for the uninstaller in the control panel
6
; The macro should be inserted in an install section 
7
; 
8
; Uninstaller defaults to "$INSTDIR\${GBE_PACKAGE}_Uninstall.exe"
9
; Can be changed by defining VIX_UNISTALL_EXE before inserting macro
10
;
11
; Install registry keys are in HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\${GBE_PACKAGE}
12
; by default but GBE_PACKAGE can be overridden by defining VIX_UNINSTALL_UNIQUE_KEY before inserting macro
13
; If Overriding then the key must be unique to this package
14
;
15
; The following defines are available after this macro is inserted
16
; VIX_UNISTALL_EXE          - The uninstaller location, use to remove itself during uninstall
17
; VIX_UNINSTALL_KEY_BASE    - The base uninstall registry key in HKLM, this is constant
18
; VIX_UNINSTALL_KEY         - The uninstall registry key where all the uninstall values are written
19
; 
20
; Example
21
; Section "-Core"
22
;    DetailPrint "---- Install -Core section"
23
;
24
;    ${VIX_CREATE_UNINSTALLER_AND_REGISTRY}
25
;    IfErrors 0 +2
26
;        Abort "Error creating uninstaller information"
27
; SectionEnd
28
 
29
!define VIX_CREATE_UNINSTALLER_AND_REGISTRY `!insertmacro VIX_CREATE_UNINSTALLER_AND_REGISTRY`
30
!macro VIX_CREATE_UNINSTALLER_AND_REGISTRY
31
 
32
    ClearErrors
33
 
34
    ; Default uninstaller exe to "$INSTDIR\${GBE_PACKAGE}_Uninstall.exe"
35
    ; Can be overridden by defining VIX_UNISTALL_EXE before macro
36
    !ifndef VIX_UNISTALL_EXE
37
        !define VIX_UNISTALL_EXE "$INSTDIR\${GBE_PACKAGE}_Uninstall.exe"
38
    !endif
39
 
40
    WriteUninstaller ${VIX_UNISTALL_EXE}
41
 
42
    ; This is constant
43
    !ifdef VIX_UNINSTALL_KEY_BASE
44
        !undef VIX_UNINSTALL_KEY_BASE
45
    !endif
46
    !define VIX_UNINSTALL_KEY_BASE "Software\Microsoft\Windows\CurrentVersion\Uninstall"
47
 
48
    ; Write the uninstall keys for Windows so that the package is seen in the
49
    ; Add/Remove Program section of the Control Panel.
50
    ; Create a 'unique' key in the windows registry
51
    ; Default to package name ${GBE_PACKAGE}, Could use a GUID but it MUST NOT be copied if this file is copied
52
    ; Can be overridden by defining VIX_UNINSTALL_UNIQUE_KEY before macro
53
    !ifndef VIX_UNINSTALL_UNIQUE_KEY
54
        !define VIX_UNINSTALL_UNIQUE_KEY ${GBE_PACKAGE}
55
    !endif
56
 
57
    !define VIX_UNINSTALL_KEY "${VIX_UNINSTALL_KEY_BASE}\${VIX_UNINSTALL_UNIQUE_KEY}"
58
 
59
    WriteRegStr   HKLM ${VIX_UNINSTALL_KEY} "DisplayName"        "${GBE_PACKAGE}, ${GBE_VERSION}"
2340 gchristi 60
    WriteRegStr   HKLM ${VIX_UNINSTALL_KEY} "DisplayIcon"        "${VIX_UNISTALL_EXE}"
2322 gchristi 61
    WriteRegStr   HKLM ${VIX_UNINSTALL_KEY} "Version"            "${GBE_VERSION}"
62
    WriteRegStr   HKLM ${VIX_UNINSTALL_KEY} "DisplayVersion"     "${GBE_VERSION_FULL}"
63
    WriteRegStr   HKLM ${VIX_UNINSTALL_KEY} "Publisher"          "${GBE_COMPANY}"
64
    WriteRegStr   HKLM ${VIX_UNINSTALL_KEY} "InstallLocation"    "$INSTDIR"
65
    WriteRegStr   HKLM ${VIX_UNINSTALL_KEY} "UninstallString"    '"${VIX_UNISTALL_EXE}"'
66
    WriteRegDWORD HKLM ${VIX_UNINSTALL_KEY} "NoModify" 1
67
    WriteRegDWORD HKLM ${VIX_UNINSTALL_KEY} "NoRepair" 1
68
 
69
    !undef VIX_UNINSTALL_UNIQUE_KEY
70
 
71
!macroend
72
 
73
 
74
 
75
 
76
;---------------------------------------------------------------------------------------------------
77
; macro VIX_REMOVE_UNINSTALLER_AND_REGISTRY
78
; Deletes the uninstaller and  registry entries for the uninstaller in the control panel
79
; The macro should be inserted in an uninstall section and must be after the section that calls the 
80
; VIX_CREATE_UNINSTALLER_AND_REGISTRY macro above, if not will abort with errors as defines create by 
81
; VIX_CREATE_UNINSTALLER_AND_REGISTRY will not be available
82
; 
83
; Example, If using same section names as example, this section must appear after Section "-Core"
84
; Section "-un.Core"
85
;    DetailPrint "---- Install -Core section"
86
;    ${VIX_REMOVE_UNINSTALLER_AND_REGISTRY}
87
; SectionEnd
88
 
89
!define VIX_REMOVE_UNINSTALLER_AND_REGISTRY `!insertmacro VIX_REMOVE_UNINSTALLER_AND_REGISTRY`
90
!macro VIX_REMOVE_UNINSTALLER_AND_REGISTRY
91
 
92
    ClearErrors
93
 
94
    !ifndef VIX_UNISTALL_EXE | VIX_UNINSTALL_KEY
95
        !error "The VIX_REMOVE_UNINSTALLER_AND_REGISTRY macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"
96
    !endif
97
 
98
    Delete "${VIX_UNISTALL_EXE}"
99
 
100
    ; Remove Uninstaller registry keys
101
    DeleteRegKey HKLM ${VIX_UNINSTALL_KEY}
102
 
103
!macroend    
104
 
105
 
106
 
107
 
108
;---------------------------------------------------------------------------------------------------
109
; macro VIX_CREATE_PACKAGING_REGISTRY
110
; Creates registry entries required by PkgMnt and procmgr in HKLM\SOFTWARE\ERG\AFC\${GBE_PACKAGE}
111
; The macro should be inserted in an install section, usually the same one that calls VIX_CREATE_UNINSTALLER_AND_REGISTRY
112
; 
113
; Uses registers $0, $1, $2, $3, $4, $5, $6 without saving them
114
;
115
; The following defines are available after this macro is inserted
116
; VIX_PACKAGING_SUBKEY            - The Registry key where the values are inserted
117
; VIX_PACKAGING_PARAMETERS_SUBKEY - A Subdir of VIX_PACKAGING_SUBKEY that can contain installer parameters 
118
;                                   Used by VIX_SAVE_PACKAGING_PARAMETER & VIX_GET_PACKAGING_PARAMETER macros
119
;                                   to save and retrieve installer parameters
120
; 
121
; Example
122
; Section "-Core"
123
;    DetailPrint "---- Install -Core section"
124
;
125
;    ${VIX_CREATE_UNINSTALLER_AND_REGISTRY}
126
;    IfErrors 0 +2
127
;        Abort "Error creating uninstaller information"
128
;    $VIX_CREATE_PACKAGING_REGISTRY
129
;    IfErrors 0 +2
130
;        Abort "Error creating Package Management registry information"
131
; SectionEnd
132
 
133
!define VIX_CREATE_PACKAGING_REGISTRY `!insertmacro VIX_CREATE_PACKAGING_REGISTRY`
134
!macro VIX_CREATE_PACKAGING_REGISTRY
135
 
136
    !ifdef VIX_PACKAGING_SUBKEY
137
        !undef VIX_PACKAGING_SUBKEY
138
    !endif
139
    !define VIX_PACKAGING_SUBKEY "SOFTWARE\ERG\AFC\${GBE_PACKAGE}"
140
    !ifdef VIX_PACKAGING_PARAMETERS_SUBKEY
141
        !undef VIX_PACKAGING_PARAMETERS_SUBKEY
142
    !endif
143
    !define VIX_PACKAGING_PARAMETERS_SUBKEY "SOFTWARE\ERG\AFC\${GBE_PACKAGE}\InstallParameters"
144
 
145
    ClearErrors
146
 
147
    ; Determine the install time in format MM-DD-YYYY HH:MM:SS
148
    ${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
149
        ; $0="01"      day
150
        ; $1="04"      month
151
        ; $2="2005"    year
152
        ; $3="Friday"  day of week name
153
        ; $4="16"      hour
154
        ; $5="05"      minute
155
        ; $6="50"      seconds
156
    StrCpy $0 "$1-$0-$2 $4:$5:$6"
157
 
158
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgVersion"            "${GBE_VERSION}"
159
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgBuildNum"           "1"
160
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgProjAcronym"        "${GBE_PROJECT}"
161
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgName"               "${GBE_PACKAGE}"
162
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgNameLong"           "${PACKAGE_LONGNAME}"
163
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgDesc"               "${PACKAGE_DESCRIPTION}"
164
    WriteRegExpandStr   HKLM ${VIX_PACKAGING_SUBKEY} "BaseInstallDir"        "$INSTDIR\"
165
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgInstalled"          "$0"
166
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "LatestPatchID"         "0000000000000-00"
167
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "LatestPatchInstalled"  "00-00-0000 0:00:00"
168
 
169
!macroend
170
 
171
 
172
 
173
 
174
;---------------------------------------------------------------------------------------------------
175
; macro VIX_REMOVE_PACKAGING_REGISTRY
176
; Deletes the registry entries for pkgmnt and procmgr
177
; The macro should be inserted in an uninstall section and must be after the section that calls the 
178
; VIX_CREATE_PACKAGING_REGISTRY macro above, if not will abort with errors as defines create by 
179
; VIX_CREATE_PACKAGING_REGISTRY will not be available
180
; 
181
; Example, If using same section names as example, this section must appear after Section "-Core"
182
; Section "-un.Core"
183
;    DetailPrint "---- Install -Core section"
184
;    ${VIX_REMOVE_UNINSTALLER_AND_REGISTRY}
185
;    ${VIX_REMOVE_PACKAGING_REGISTRY}
186
; SectionEnd
187
 
188
!define VIX_REMOVE_PACKAGING_REGISTRY `!insertmacro VIX_REMOVE_PACKAGING_REGISTRY`
189
!macro VIX_REMOVE_PACKAGING_REGISTRY
190
 
191
    ClearErrors
192
 
193
    !ifndef VIX_PACKAGING_SUBKEY
194
        !error "The VIX_REMOVE_PACKAGING_REGISTRY macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"
195
    !endif
196
 
197
    DeleteRegKey HKLM ${VIX_PACKAGING_SUBKEY}
198
 
199
!macroend    
200
 
201
 
202
 
203
 
204
;---------------------------------------------------------------------------------------------------
205
; macro VIX_SAVE_PACKAGING_PARAMETER
206
; Saves key values in VIX_PACKAGING_PARAMETERS_SUBKEY registry for recall on when installing new version
207
; Must be inserted in your script after the insertion of VIX_CREATE_PACKAGING_REGISTRY for required defines
208
; 
209
; Parameters
210
; KEYNAME  - The name of the key to save
211
; KEYVALUE - The value of the key to save (string only)
212
 
213
!define VIX_SAVE_PACKAGING_PARAMETER `!insertmacro VIX_SAVE_PACKAGING_PARAMETER`
214
!macro VIX_SAVE_PACKAGING_PARAMETER KEYNAME KEYVALUE
215
 
216
    ClearErrors
217
 
218
    !ifndef VIX_PACKAGING_PARAMETERS_SUBKEY
219
        !error "The VIX_SAVE_PACKAGING_PARAMETER macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"
220
    !endif
221
 
222
    WriteRegStr HKLM ${VIX_PACKAGING_PARAMETERS_SUBKEY} "${KEYNAME}" "${KEYVALUE}"
223
 
224
!macroend    
225
 
226
 
227
 
228
;---------------------------------------------------------------------------------------------------
229
; macro VIX_GET_PACKAGING_PARAMETER
230
; Retreives key values in VIX_PACKAGING_PARAMETERS_SUBKEY registry for recall on when installing new version
231
; Must be inserted in your script after the insertion of VIX_CREATE_PACKAGING_REGISTRY for required defines
232
; 
233
; Parameters
234
; KEYNAME - The name of the key to retrieve
235
; VAR     - The variable to save the entry to
236
; DEFAULT - The default to use if not in registry
237
 
238
!define VIX_GET_PACKAGING_PARAMETER `!insertmacro VIX_GET_PACKAGING_PARAMETER`
239
!macro VIX_GET_PACKAGING_PARAMETER KEYNAME VAR DEFAULT
240
 
241
    ClearErrors
242
 
243
    !ifndef VIX_PACKAGING_PARAMETERS_SUBKEY
244
        !error "The VIX_GET_PACKAGING_PARAMETER macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"
245
    !endif
246
 
247
    ReadRegStr ${VAR} HKLM ${VIX_PACKAGING_PARAMETERS_SUBKEY} "${KEYNAME}"
248
    IfErrors 0 +2
249
        StrCpy ${VAR} "${DEFAULT}"
250
 
251
    Nop
252
!macroend    
253
 
254
 
255
 
256
;---------------------------------------------------------------------------------------------------
257
; macro VIX_SETINSTDIR_IFINSTALLED
258
; This is to be inserted inside the .onInit function and sets the default installdir to the value used
259
; if the package has already been installed, otherwise leaves it as it is
260
; 
261
; Uses registers $0
262
;
263
!define VIX_SETINSTDIR_IFINSTALLED `!insertmacro VIX_SETINSTDIR_IFINSTALLED`
264
!macro VIX_SETINSTDIR_IFINSTALLED
265
 
266
    !ifndef VIX_UNINSTALL_KEY
267
        !error "The VIX_SETINSTDIR_IFINSTALLED macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"
268
    !endif
269
 
270
    ClearErrors
271
 
272
    ReadRegStr $0 HKLM ${VIX_UNINSTALL_KEY} "InstallLocation"
273
    IfErrors +2 0
274
        ; set default installdir to what was previously used
275
        StrCpy $INSTDIR $0
276
 
277
    Nop
278
!macroend
279
 
280
 
281
;---------------------------------------------------------------------------------------------------
282
; macro VIX_ONINIT_UNINSTALL_EXISTING_VERSION
283
; This is to be inserted inside the .onInit function and checks for the existance of an already installed 
284
; version and prompts the user to uninstall.  If yes is selected it runs the uninstaller, otherwise it quits the installer
285
; If in silent mode then it automatically Uninstalls
286
;
287
; Parameter:
288
; OLDVERSION: Contains the version number of the uninstalled version (or ???? if old version is detected but cant get version number)
289
;             otherwise set to empty string to indicate no uninstall is done
290
; 
291
; Uses registers $0, $1, $2, $3 without saving
292
;
293
!define VIX_ONINIT_UNINSTALL_EXISTING_VERSION `!insertmacro VIX_ONINIT_UNINSTALL_EXISTING_VERSION`
294
!macro VIX_ONINIT_UNINSTALL_EXISTING_VERSION OLDVERSION
295
 
296
    !ifndef VIX_UNINSTALL_KEY
297
        !error "The VIX_ONINIT_UNINSTALL_EXISTING_VERSION macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"
298
    !endif
299
 
300
    ClearErrors
301
 
302
    StrCpy ${OLDVERSION} ""  ; Empty string indicates no uninstall done
303
 
304
    ; If these are not in registry then package is not installed so do nothing
305
    ReadRegStr $0 HKLM ${VIX_UNINSTALL_KEY} "UninstallString"
306
    IfErrors Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done
307
    ReadRegStr $1 HKLM ${VIX_UNINSTALL_KEY} "InstallLocation"
308
    IfErrors Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done
309
 
310
    # if we cant get version number (in case of legacy installs without version number) then jump to display non versioned message box
311
    ReadRegStr ${OLDVERSION} HKLM ${VIX_UNINSTALL_KEY} "Version"
312
    IfErrors 0 +2   ; If Error set OldVersion next otherwise jump to message box
313
        StrCpy ${OLDVERSION} "????"  ; Just so there is something in there to indicate we did do an uninstall
314
 
315
    MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
316
               "${GBE_PACKAGE} version ${OLDVERSION} is currently installed and will be uninstalled first before installing this (${GBE_VERSION}) version.$\n$\n\
317
               Click 'OK' to do so or 'Cancel' to abort installation" \
318
               /SD IDOK IDOK +2
319
        Quit
320
 
321
    ; We have to use $?=INSTDIR to stop uninstaller making a copy of itself before running, otherwise ExecWait cant wait for it
322
    ; The problem is that uninstalling this way is unable to remove the uninstaller.exe itself as it is running
323
    ; So to Solve it copy the uninstaller to a tmp dir and run it from there
324
    ${StrRep} $2 $0 '"' ''  ; remove quotes from $0 from registry otherwise copy wont work
325
    Strcpy $3 "$TEMP\${GBE_PACKAGE}_Uninstall-tmp.exe"
326
    CopyFiles /SILENT "$2" "$3"
327
    IfErrors 0 +3
328
        MessageBox MB_OK "Failed to copy uninstaller"
329
        Abort
330
 
331
    ExecWait '"$3" /S _?=$1'
332
    IfErrors 0 +3
333
        MessageBox MB_OK "Failed to uninstall current version" 
334
        Abort
335
    Delete $3
336
 
337
Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done:
338
 
339
!macroend