comparison nsis/AdvUninstLog2.nsh @ 0:1fd2201f5c36

Initial commit of parpg-core.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 14 May 2011 01:12:35 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1fd2201f5c36
1 ;_____________________________ HEADER FILE BEGIN ____________________________
2
3 # Advanced Uninstall Log NSIS header
4 # Version 1.0 2007-01-31
5 # By Red Wine (http://nsis.sf.net/User:Red_Wine)
6
7 # Usage: See included examples Uninstall_Log_Default_UI.nsi - Uninstall_Log_Modern_UI.nsi
8
9 !verbose push
10 !verbose 3
11
12 !ifndef ADVANCED_UNINSTALL.LOG_NSH
13 !define ADVANCED_UNINSTALL.LOG_NSH
14
15 !ifndef INSTDIR_REG_ROOT | INSTDIR_REG_KEY
16 !error "You must properly define both INSTDIR_REG_ROOT and INSTDIR_REG_KEY"
17 !endif
18
19 !ifndef UNINSTALL_LOG
20 !define UNINSTALL_LOG "Uninstall"
21 !endif
22
23 !ifndef UNINST_LOG_VERBOSE
24 !define UNINST_LOG_VERBOSE "3"
25 !endif
26
27 !verbose pop
28
29 !echo "Advanced Uninstall Log NSIS header v1.0 2007-01-31 by Red Wine (http://nsis.sf.net/User:Red_Wine)"
30
31 !verbose push
32 !verbose ${UNINST_LOG_VERBOSE}
33
34 !define UNINST_EXE "$INSTDIR\${UNINSTALL_LOG}.exe"
35 !define UNINST_DAT "$INSTDIR\${UNINSTALL_LOG}.dat"
36 !define UNLOG_PART "$PLUGINSDIR\part."
37 !define UNLOG_TEMP "$PLUGINSDIR\unlog.tmp"
38 !define EXCLU_LIST "$PLUGINSDIR\exclude.tmp"
39 !define UNLOG_HEAD "=========== Uninstaller Log please do not edit this file ==========="
40
41 Var TargetDir
42
43 var unlog_tmp_0
44 var unlog_tmp_1
45 var unlog_tmp_2
46 var unlog_tmp_3
47 var unlog_error
48
49 !include FileFunc.nsh
50 !include TextFunc.nsh
51
52 !insertmacro Locate
53 !insertmacro un.Locate
54 !insertmacro DirState
55 !insertmacro un.DirState
56 !insertmacro FileJoin
57 !insertmacro TrimNewLines
58 !insertmacro un.TrimNewLines
59
60 ;.............................. Uninstaller Macros ..............................
61
62 /* Used to get rid of pesky newline characters that prevent installations from happenning */
63 Function un.TrimNewlines
64 Exch $R0 ; removes whatever was stored into the stack with the file data
65 Push $R1
66 Push $R2
67 StrCpy $R1 0
68
69 loop:
70 IntOp $R1 $R1 - 1
71 StrCpy $R2 $R0 1 $R1
72 StrCmp $R2 "$\r" loop
73 StrCmp $R2 "$\n" loop
74 IntOp $R1 $R1 + 1
75 IntCmp $R1 0 no_trim_needed
76 StrCpy $R0 $R0 $R1
77
78 no_trim_needed:
79 Pop $R2
80 Pop $R1
81 Exch $R0
82 FunctionEnd
83
84 Function un.RemoveEmptyDirs
85 Pop $9
86
87 FindFirst $0 $1 "$TargetDir$9*"
88 StrCmp $0 "" End
89 Loop:
90 StrCmp $1 "" End
91 StrCmp $1 "." Next
92 StrCmp $1 ".." Next
93 Push $0
94 Push $1
95 Push $9
96 Push "$9$1\"
97 Call un.RemoveEmptyDirs
98 Pop $9
99 Pop $1
100 Pop $0
101 RMDir "$TargetDir$9$1"
102 Next:
103 FindNext $0 $1
104 Goto Loop
105 End:
106 FindClose $0
107 FunctionEnd
108
109 !macro UNINSTALL.NEW_UNINSTALL TempDir
110 StrCpy $TargetDir ${TempDir}
111 FileOpen $unlog_tmp_0 "$TargetDir\Uninstall.dat" r
112
113 UninstallLoop:
114 ClearErrors #ClearErrors from displaying
115 FileRead $unlog_tmp_0 $R0 #Reads string lines from a file and stores them in $R0
116 IfErrors UninstallEnd #If EOF has been reached
117 Push $R0 #throw contents of $R0 into stack
118 Call un.TrimNewLines
119 Pop $R0 #takes contents of stack and places into $R0
120 Delete "$R0" #delete file
121 Goto UninstallLoop
122 UninstallEnd:
123 FileClose $unlog_tmp_0
124
125 Delete "$TargetDir\Uninstall.dat"
126 Delete "$TargetDir\Uninstall.exe"
127
128 Push "\"
129 Call un.RemoveEmptyDirs
130 RMDir "$TargetDir"
131 !macroend
132
133 !macro INTERACTIVE_UNINSTALL
134 !verbose push
135 !verbose ${UNINST_LOG_VERBOSE}
136
137 !ifdef INTERACTIVE_UNINSTALL
138 !error "INTERACTIVE_UNINSTALL is already defined"
139 !endif
140
141 var unlog_tmp_4
142 var unlog_tmp_5
143
144 !define INTERACTIVE_UNINSTALL
145
146 !ifdef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
147 !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
148 !endif
149
150 !ifdef UnLog_Uninstall_CallBackFunc
151 !undef UnLog_Uninstall_CallBackFunc
152 !endif
153
154 !ifndef UnLog_Uninstall_CallBackFunc
155 !insertmacro UNINSTALL.LOG_UNINSTALL_INTERACTIVE
156 !define UnLog_Uninstall_CallBackFunc "un._LocateCallBack_Function_Interactive"
157 !endif
158
159 !verbose pop
160 !macroend
161
162
163 !macro UNATTENDED_UNINSTALL
164 !verbose push
165 !verbose ${UNINST_LOG_VERBOSE}
166
167 !ifdef UNATTENDED_UNINSTALL
168 !error "UNATTENDED_UNINSTALL is already defined"
169 !endif
170
171 !define UNATTENDED_UNINSTALL
172
173 !ifdef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
174 !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
175 !endif
176
177 !ifdef UnLog_Uninstall_CallBackFunc
178 !undef UnLog_Uninstall_CallBackFunc
179 !endif
180
181 !ifndef UnLog_Uninstall_CallBackFunc
182 !insertmacro UNINSTALL.LOG_UNINSTALL_UNATTENDED
183 !define UnLog_Uninstall_CallBackFunc "un._LocateCallBack_Function_Unattended"
184 !endif
185
186 !verbose pop
187 !macroend
188
189
190 !macro UNINSTALL.LOG_UNINSTALL_UNATTENDED
191
192 Function un._LocateCallBack_Function_Unattended
193 start:
194 FileRead $unlog_tmp_2 "$unlog_tmp_3" ${NSIS_MAX_STRLEN}
195 ${un.TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
196 StrCmp "$unlog_tmp_3" "$R9" islog
197 IfErrors nolog
198 goto start
199
200 islog:
201 IfFileExists "$R9\*.*" isdir
202
203 isfile:
204 Delete "$R9"
205 goto end
206
207 isdir:
208 RmDir "$R9"
209 IntOp $unlog_tmp_1 $unlog_tmp_1 + 1
210 goto end
211
212 nolog:
213 ClearErrors
214 StrCmp "$R9" "${UNINST_EXE}" isfile
215 StrCmp "$R9" "${UNINST_DAT}" isfile
216
217 end:
218 FileSeek $unlog_tmp_2 0 SET
219 Push $unlog_tmp_0
220 FunctionEnd
221
222 !macroend
223
224
225 !macro UNINSTALL.LOG_UNINSTALL_INTERACTIVE
226
227 Function un._LocateCallBack_Function_Interactive
228 start:
229 FileRead $unlog_tmp_2 "$unlog_tmp_3" ${NSIS_MAX_STRLEN}
230 ${un.TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
231 StrCmp "$unlog_tmp_3" "$R9" islog
232 IfErrors nolog
233 goto start
234
235 islog:
236 IfFileExists "$R9\*.*" isdir
237
238 isfile:
239 Delete "$R9"
240 goto end
241
242 isdir:
243 RmDir "$R9"
244 IntOp $unlog_tmp_1 $unlog_tmp_1 + 1
245 goto end
246
247 nolog:
248 ClearErrors
249 FileSeek $unlog_tmp_4 0 SET
250 read:
251 FileRead $unlog_tmp_4 "$unlog_tmp_3"
252 ${un.TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
253 StrCmp "$unlog_tmp_3" "$R9" end
254 IfErrors +2
255 goto read
256 ClearErrors
257 StrCmp "$R9" "${UNINST_EXE}" isfile
258 StrCmp "$R9" "${UNINST_DAT}" isfile
259 IfFileExists "$R9\*.*" msgdir
260
261 MessageBox MB_ICONQUESTION|MB_YESNO \
262 'Delete File "$R9"?' /SD IDNO IDYES isfile IDNO nodel
263
264 msgdir:
265 MessageBox MB_ICONQUESTION|MB_YESNO \
266 'Delete Directory "$R9"?' /SD IDNO IDYES isdir IDNO nodel
267
268 nodel:
269 FileSeek $unlog_tmp_4 0 END
270 FileWrite $unlog_tmp_4 "$R9$\r$\n"
271
272 end:
273 FileSeek $unlog_tmp_2 0 SET
274 Push $unlog_tmp_0
275 FunctionEnd
276
277 !macroend
278
279 ;................................. Installer Macros .................................
280
281 !macro UNINSTALL.LOG_INSTALL_UNATTENDED
282
283 Function _LocateCallBack_Function_Install
284 loop:
285 FileRead $unlog_tmp_2 "$unlog_tmp_3" ${NSIS_MAX_STRLEN}
286 ${TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
287 IfErrors 0 +4
288 ClearErrors
289 FileSeek $unlog_tmp_2 0 SET
290 goto next
291 StrCmp "$R9" "$unlog_tmp_3" end
292 goto loop
293 next:
294 FileWrite $unlog_tmp_1 "$R9$\r$\n"
295 end:
296 Push $unlog_tmp_0
297 FunctionEnd
298
299 !macroend
300
301
302 !ifdef UnLog_Install_Func_CallBack
303 !undef UnLog_Install_Func_CallBack
304 !endif
305
306 !ifndef UnLog_Install_Func_CallBack
307 !insertmacro UNINSTALL.LOG_INSTALL_UNATTENDED
308 !define UnLog_Install_Func_CallBack "_LocateCallBack_Function_Install"
309 !endif
310
311
312 !macro UNINSTALL.LOG_PREPARE_INSTALL
313 !verbose push
314 !verbose ${UNINST_LOG_VERBOSE}
315
316 Push $0
317 Push $1
318 ClearErrors
319 ReadRegStr "$0" ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}Directory"
320 IfErrors next
321 ${DirState} "$0" $1
322 StrCmp "$1" "-1" next
323 StrCmp "$1" "0" next
324 IfFileExists "$0\${UNINSTALL_LOG}.dat" next
325 MessageBox MB_ICONEXCLAMATION|MB_OK \
326 "Previous installation detected at $0.$\n\
327 Required file ${UNINSTALL_LOG}.dat is missing.$\n$\nIt is highly recommended \
328 to select an empty directory and perform a fresh installation." /SD IDOK
329 StrCpy $unlog_error "error"
330
331 next:
332 ClearErrors
333 StrCmp "$PLUGINSDIR" "" 0 +2
334 InitPluginsDir
335
336 GetTempFileName "$1"
337 FileOpen $0 "$1" w
338 FileWrite $0 "${UNLOG_HEAD}$\r$\n"
339 FileClose $0
340 Rename "$1" "${UNLOG_TEMP}"
341 Pop $1
342 Pop $0
343
344 !verbose pop
345 !macroend
346
347
348 !macro UNINSTALL.LOG_UPDATE_INSTALL
349 !verbose push
350 !verbose ${UNINST_LOG_VERBOSE}
351
352 Delete "${UNINST_DAT}"
353 Rename "${UNLOG_TEMP}" "${UNINST_DAT}"
354 WriteUninstaller "${UNINST_EXE}"
355 WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}.dat" "${UNINST_DAT}"
356 WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}Directory" "$INSTDIR"
357
358 !verbose pop
359 !macroend
360
361
362 !define uninstall.log_install "!insertmacro UNINSTALL.LOG_INSTALL"
363
364 !macro UNINSTALL.LOG_INSTALL FileOpenWrite FileOpenRead TargetDir
365 !verbose push
366 !verbose ${UNINST_LOG_VERBOSE}
367
368 FileOpen $unlog_tmp_1 "${FileOpenWrite}" w
369 FileOpen $unlog_tmp_2 "${FileOpenRead}" r
370
371 ${Locate} "${TargetDir}" "/L=FD" "${UnLog_Install_Func_CallBack}"
372
373 StrCmp $unlog_error "error" 0 +2
374 ClearErrors
375
376 IfErrors 0 +2
377 MessageBox MB_ICONEXCLAMATION|MB_OK "Error creating ${UNINSTALL_LOG} Log." /SD IDOK
378
379 FileClose $unlog_tmp_1
380 FileClose $unlog_tmp_2
381
382 !verbose pop
383 !macroend
384
385
386 !define uninstall.log_mergeID "!insertmacro UNINSTALL.LOG_MERGE"
387
388 !macro UNINSTALL.LOG_MERGE UnlogPart
389 !verbose push
390 !verbose ${UNINST_LOG_VERBOSE}
391
392 ${FileJoin} "${UNLOG_TEMP}" "${UnlogPart}" "${UNLOG_TEMP}"
393
394 !verbose pop
395 !macroend
396
397
398 !macro UNINSTALL.LOG_OPEN_INSTALL
399 !verbose push
400 !verbose ${UNINST_LOG_VERBOSE}
401
402 StrCmp $unlog_error "error" +2
403 ${uninstall.log_install} "${EXCLU_LIST}" "${UNINST_DAT}" "$OUTDIR"
404
405 !verbose pop
406 !macroend
407
408
409 !macro UNINSTALL.LOG_CLOSE_INSTALL
410 !verbose push
411 !verbose ${UNINST_LOG_VERBOSE}
412
413 !define ID ${__LINE__}
414
415 ${uninstall.log_install} "${UNLOG_PART}${ID}" "${EXCLU_LIST}" "$OUTDIR"
416 ${uninstall.log_mergeID} "${UNLOG_PART}${ID}"
417
418 !undef ID ${__LINE__}
419
420 !verbose pop
421 !macroend
422
423 !endif
424
425 !verbose pop
426 ;_____________________________ HEADER FILE END ____________________________
427