Subversion Repositories DevTools

Rev

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