Subversion Repositories DevTools

Rev

Rev 2340 | 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
4920 gchristi 116
; VIX_PACKAGING_ROOTKEY           - The Root key where VIX_PACKAGING_SUBKEY is rooted
2322 gchristi 117
; VIX_PACKAGING_SUBKEY            - The Registry key where the values are inserted
118
; VIX_PACKAGING_PARAMETERS_SUBKEY - A Subdir of VIX_PACKAGING_SUBKEY that can contain installer parameters 
119
;                                   Used by VIX_SAVE_PACKAGING_PARAMETER & VIX_GET_PACKAGING_PARAMETER macros
120
;                                   to save and retrieve installer parameters
121
; 
122
; Example
123
; Section "-Core"
124
;    DetailPrint "---- Install -Core section"
125
;
126
;    ${VIX_CREATE_UNINSTALLER_AND_REGISTRY}
127
;    IfErrors 0 +2
128
;        Abort "Error creating uninstaller information"
129
;    $VIX_CREATE_PACKAGING_REGISTRY
130
;    IfErrors 0 +2
131
;        Abort "Error creating Package Management registry information"
132
; SectionEnd
133
 
134
!define VIX_CREATE_PACKAGING_REGISTRY `!insertmacro VIX_CREATE_PACKAGING_REGISTRY`
135
!macro VIX_CREATE_PACKAGING_REGISTRY
136
 
4920 gchristi 137
    !ifdef VIX_PACKAGING_ROOTKEY
138
        !undef VIX_PACKAGING_ROOTKEY
139
    !endif
140
    !define VIX_PACKAGING_ROOTKEY "SOFTWARE\ERG\AFC"
2322 gchristi 141
    !ifdef VIX_PACKAGING_SUBKEY
142
        !undef VIX_PACKAGING_SUBKEY
143
    !endif
4920 gchristi 144
    !define VIX_PACKAGING_SUBKEY "${VIX_PACKAGING_ROOTKEY}\${GBE_PACKAGE}"
2322 gchristi 145
    !ifdef VIX_PACKAGING_PARAMETERS_SUBKEY
146
        !undef VIX_PACKAGING_PARAMETERS_SUBKEY
147
    !endif
4920 gchristi 148
    !define VIX_PACKAGING_PARAMETERS_SUBKEY "${VIX_PACKAGING_ROOTKEY}\${GBE_PACKAGE}\InstallParameters"
2322 gchristi 149
 
150
    ClearErrors
151
 
152
    ; Determine the install time in format MM-DD-YYYY HH:MM:SS
153
    ${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
154
        ; $0="01"      day
155
        ; $1="04"      month
156
        ; $2="2005"    year
157
        ; $3="Friday"  day of week name
158
        ; $4="16"      hour
159
        ; $5="05"      minute
160
        ; $6="50"      seconds
161
    StrCpy $0 "$1-$0-$2 $4:$5:$6"
162
 
163
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgVersion"            "${GBE_VERSION}"
164
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgBuildNum"           "1"
165
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgProjAcronym"        "${GBE_PROJECT}"
166
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgName"               "${GBE_PACKAGE}"
167
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgNameLong"           "${PACKAGE_LONGNAME}"
168
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgDesc"               "${PACKAGE_DESCRIPTION}"
169
    WriteRegExpandStr   HKLM ${VIX_PACKAGING_SUBKEY} "BaseInstallDir"        "$INSTDIR\"
170
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "PkgInstalled"          "$0"
171
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "LatestPatchID"         "0000000000000-00"
172
    WriteRegStr         HKLM ${VIX_PACKAGING_SUBKEY} "LatestPatchInstalled"  "00-00-0000 0:00:00"
173
 
174
!macroend
175
 
176
 
177
 
178
 
179
;---------------------------------------------------------------------------------------------------
180
; macro VIX_REMOVE_PACKAGING_REGISTRY
181
; Deletes the registry entries for pkgmnt and procmgr
182
; The macro should be inserted in an uninstall section and must be after the section that calls the 
183
; VIX_CREATE_PACKAGING_REGISTRY macro above, if not will abort with errors as defines create by 
184
; VIX_CREATE_PACKAGING_REGISTRY will not be available
185
; 
186
; Example, If using same section names as example, this section must appear after Section "-Core"
187
; Section "-un.Core"
188
;    DetailPrint "---- Install -Core section"
189
;    ${VIX_REMOVE_UNINSTALLER_AND_REGISTRY}
190
;    ${VIX_REMOVE_PACKAGING_REGISTRY}
191
; SectionEnd
192
 
193
!define VIX_REMOVE_PACKAGING_REGISTRY `!insertmacro VIX_REMOVE_PACKAGING_REGISTRY`
194
!macro VIX_REMOVE_PACKAGING_REGISTRY
195
 
196
    ClearErrors
197
 
198
    !ifndef VIX_PACKAGING_SUBKEY
199
        !error "The VIX_REMOVE_PACKAGING_REGISTRY macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"
200
    !endif
201
 
202
    DeleteRegKey HKLM ${VIX_PACKAGING_SUBKEY}
203
 
204
!macroend    
205
 
206
 
207
 
4920 gchristi 208
;---------------------------------------------------------------------------------------------------
209
; macro VIX_CHECK_VIXPKG_PREREQ
210
; Checks the VIX_PACKAGING_ROOTKEY for PKGNAME to see if package has been intalled.  
211
; This is for VIX packages that create the registry entries using VIX_CREATE_PACKAGING_REGISTRY in NSIS or in installshield
212
; It does not use the Uninstaller registry locations
213
; 
214
; Parameters
215
; PKGNAME  - The name of the VIX Package to look for
216
; KEYVALUE - A Variable that has PKGNAME appended to it if PkgName is not installed.
217
;
218
; Used in .onInit function
219
; Declare Global var first
220
; Var MISSING_PREREQ
221
; Then in .onInit 
222
; ${VIX_CHECK_VIXPKG_PREREQ} "ERGcots" $MISSING_PREREQ
223
; ${VIX_CHECK_VIXPKG_PREREQ} "ERGsnmpagt" $MISSING_PREREQ
224
;StrCmp $MISSING_PREREQ "" +2
225
;    MessageBox MB_OK|MB_ICONINFORMATION 'The following pre-requisite Package(s) are not installed. Please install to complete installation$\n$MISSING_PREREQ' /SD IDOK
2322 gchristi 226
 
4920 gchristi 227
!define VIX_CHECK_VIXPKG_PREREQ `!insertmacro VIX_CHECK_VIXPKG_PREREQ`
228
!macro VIX_CHECK_VIXPKG_PREREQ PKGNAME PKGSNOTFOUND
229
 
230
    ClearErrors
231
 
232
    !ifndef VIX_PACKAGING_ROOTKEY
233
        !error "The VIX_CHECK_VIXPKG_PREREQ macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"
234
    !endif
235
 
236
    push $0
237
    ReadRegStr $0 HKLM "${VIX_PACKAGING_ROOTKEY}\${PKGNAME}" "PkgName"
238
    IfErrors 0 +5
239
        StrCmp ${PKGSNOTFOUND} "" +3
240
            StrCpy ${PKGSNOTFOUND} "${PKGSNOTFOUND}, ${PKGNAME}"
241
            Goto +2
242
        StrCpy ${PKGSNOTFOUND} "${PKGNAME}"
243
 
244
    pop $0
245
!macroend    
246
 
247
 
248
 
2322 gchristi 249
;---------------------------------------------------------------------------------------------------
250
; macro VIX_SAVE_PACKAGING_PARAMETER
251
; Saves key values in VIX_PACKAGING_PARAMETERS_SUBKEY registry for recall on when installing new version
252
; Must be inserted in your script after the insertion of VIX_CREATE_PACKAGING_REGISTRY for required defines
253
; 
254
; Parameters
255
; KEYNAME  - The name of the key to save
256
; KEYVALUE - The value of the key to save (string only)
257
 
258
!define VIX_SAVE_PACKAGING_PARAMETER `!insertmacro VIX_SAVE_PACKAGING_PARAMETER`
259
!macro VIX_SAVE_PACKAGING_PARAMETER KEYNAME KEYVALUE
260
 
261
    ClearErrors
262
 
263
    !ifndef VIX_PACKAGING_PARAMETERS_SUBKEY
264
        !error "The VIX_SAVE_PACKAGING_PARAMETER macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"
265
    !endif
266
 
267
    WriteRegStr HKLM ${VIX_PACKAGING_PARAMETERS_SUBKEY} "${KEYNAME}" "${KEYVALUE}"
268
 
269
!macroend    
270
 
271
 
272
 
273
;---------------------------------------------------------------------------------------------------
274
; macro VIX_GET_PACKAGING_PARAMETER
275
; Retreives key values in VIX_PACKAGING_PARAMETERS_SUBKEY registry for recall on when installing new version
276
; Must be inserted in your script after the insertion of VIX_CREATE_PACKAGING_REGISTRY for required defines
277
; 
278
; Parameters
279
; KEYNAME - The name of the key to retrieve
280
; VAR     - The variable to save the entry to
281
; DEFAULT - The default to use if not in registry
282
 
283
!define VIX_GET_PACKAGING_PARAMETER `!insertmacro VIX_GET_PACKAGING_PARAMETER`
284
!macro VIX_GET_PACKAGING_PARAMETER KEYNAME VAR DEFAULT
285
 
286
    ClearErrors
287
 
288
    !ifndef VIX_PACKAGING_PARAMETERS_SUBKEY
289
        !error "The VIX_GET_PACKAGING_PARAMETER macro must be inserted in script after VIX_CREATE_PACKAGING_REGISTRY"
290
    !endif
291
 
292
    ReadRegStr ${VAR} HKLM ${VIX_PACKAGING_PARAMETERS_SUBKEY} "${KEYNAME}"
293
    IfErrors 0 +2
294
        StrCpy ${VAR} "${DEFAULT}"
295
 
296
    Nop
297
!macroend    
298
 
299
 
300
 
301
;---------------------------------------------------------------------------------------------------
302
; macro VIX_SETINSTDIR_IFINSTALLED
303
; This is to be inserted inside the .onInit function and sets the default installdir to the value used
304
; if the package has already been installed, otherwise leaves it as it is
305
; 
306
; Uses registers $0
307
;
308
!define VIX_SETINSTDIR_IFINSTALLED `!insertmacro VIX_SETINSTDIR_IFINSTALLED`
309
!macro VIX_SETINSTDIR_IFINSTALLED
310
 
311
    !ifndef VIX_UNINSTALL_KEY
312
        !error "The VIX_SETINSTDIR_IFINSTALLED macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"
313
    !endif
314
 
315
    ClearErrors
4920 gchristi 316
 
317
    push $0
2322 gchristi 318
    ReadRegStr $0 HKLM ${VIX_UNINSTALL_KEY} "InstallLocation"
319
    IfErrors +2 0
320
        ; set default installdir to what was previously used
321
        StrCpy $INSTDIR $0
322
 
4920 gchristi 323
    Pop $0
2322 gchristi 324
!macroend
325
 
326
 
327
;---------------------------------------------------------------------------------------------------
328
; macro VIX_ONINIT_UNINSTALL_EXISTING_VERSION
329
; This is to be inserted inside the .onInit function and checks for the existance of an already installed 
330
; version and prompts the user to uninstall.  If yes is selected it runs the uninstaller, otherwise it quits the installer
331
; If in silent mode then it automatically Uninstalls
332
;
333
; Parameter:
334
; OLDVERSION: Contains the version number of the uninstalled version (or ???? if old version is detected but cant get version number)
335
;             otherwise set to empty string to indicate no uninstall is done
336
; 
4920 gchristi 337
; Uses registers $0, $1, $2, $3 
2322 gchristi 338
;
339
!define VIX_ONINIT_UNINSTALL_EXISTING_VERSION `!insertmacro VIX_ONINIT_UNINSTALL_EXISTING_VERSION`
340
!macro VIX_ONINIT_UNINSTALL_EXISTING_VERSION OLDVERSION
341
 
342
    !ifndef VIX_UNINSTALL_KEY
343
        !error "The VIX_ONINIT_UNINSTALL_EXISTING_VERSION macro must be inserted in script after VIX_CREATE_UNINSTALLER_AND_REGISTRY"
344
    !endif
345
 
346
    ClearErrors
347
 
4920 gchristi 348
    push $0
349
    push $1
350
    push $2
351
    push $3
352
 
2322 gchristi 353
    StrCpy ${OLDVERSION} ""  ; Empty string indicates no uninstall done
354
 
355
    ; If these are not in registry then package is not installed so do nothing
356
    ReadRegStr $0 HKLM ${VIX_UNINSTALL_KEY} "UninstallString"
357
    IfErrors Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done
358
    ReadRegStr $1 HKLM ${VIX_UNINSTALL_KEY} "InstallLocation"
359
    IfErrors Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done
360
 
361
    # if we cant get version number (in case of legacy installs without version number) then jump to display non versioned message box
362
    ReadRegStr ${OLDVERSION} HKLM ${VIX_UNINSTALL_KEY} "Version"
363
    IfErrors 0 +2   ; If Error set OldVersion next otherwise jump to message box
364
        StrCpy ${OLDVERSION} "????"  ; Just so there is something in there to indicate we did do an uninstall
365
 
366
    MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
367
               "${GBE_PACKAGE} version ${OLDVERSION} is currently installed and will be uninstalled first before installing this (${GBE_VERSION}) version.$\n$\n\
368
               Click 'OK' to do so or 'Cancel' to abort installation" \
369
               /SD IDOK IDOK +2
370
        Quit
371
 
372
    ; We have to use $?=INSTDIR to stop uninstaller making a copy of itself before running, otherwise ExecWait cant wait for it
373
    ; The problem is that uninstalling this way is unable to remove the uninstaller.exe itself as it is running
374
    ; So to Solve it copy the uninstaller to a tmp dir and run it from there
375
    ${StrRep} $2 $0 '"' ''  ; remove quotes from $0 from registry otherwise copy wont work
376
    Strcpy $3 "$TEMP\${GBE_PACKAGE}_Uninstall-tmp.exe"
377
    CopyFiles /SILENT "$2" "$3"
378
    IfErrors 0 +3
379
        MessageBox MB_OK "Failed to copy uninstaller"
380
        Abort
381
 
382
    ExecWait '"$3" /S _?=$1'
383
    IfErrors 0 +3
384
        MessageBox MB_OK "Failed to uninstall current version" 
385
        Abort
386
    Delete $3
387
 
388
Label.VIX_ONINIT_UNINSTALL_EXISTING_VERSION.done:
4920 gchristi 389
    pop $3
390
    pop $2
391
    pop $1
392
    pop $0
2322 gchristi 393
 
394
!macroend