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