tests: Remove two tests that proved problematic cross-OS and cross-arch.
[pspp.git] / Windows / AdvUninstLog.nsh
blob84024e7d8f28a6fb8f58bb8f87565fe836bf84b1
1 # Advanced Uninstall Log NSIS header
2 # Version 1.0 2007-01-31
3 # By Red Wine (http://nsis.sf.net/User:Red_Wine)
5 # Usage: See included examples Uninstall_Log_Default_UI.nsi - Uninstall_Log_Modern_UI.nsi
7 !verbose push
8    !verbose 3
10 !ifndef ADVANCED_UNINSTALL.LOG_NSH
11    !define ADVANCED_UNINSTALL.LOG_NSH
13 !ifndef INSTDIR_REG_ROOT | INSTDIR_REG_KEY
14    !error "You must properly define both INSTDIR_REG_ROOT and INSTDIR_REG_KEY"
15 !endif
17 !ifndef UNINSTALL_LOG
18    !define UNINSTALL_LOG         "Uninstall"
19 !endif
21 !ifndef UNINST_LOG_VERBOSE
22    !define UNINST_LOG_VERBOSE    "3"
23 !endif
25 !verbose pop
27 !echo "Advanced Uninstall Log NSIS header v1.0 2007-01-31 by Red Wine (http://nsis.sf.net/User:Red_Wine)"
29 !verbose push
30    !verbose ${UNINST_LOG_VERBOSE}
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 ==========="
39  var unlog_tmp_0
40  var unlog_tmp_1
41  var unlog_tmp_2
42  var unlog_tmp_3
43  var unlog_error
45 !include FileFunc.nsh
46 !include TextFunc.nsh
48 !insertmacro Locate
49 !insertmacro un.Locate
50 !insertmacro DirState
51 !insertmacro un.DirState
52 !insertmacro FileJoin
53 !insertmacro TrimNewLines
54 !insertmacro un.TrimNewLines
56 ;.............................. Uninstaller Macros ..............................
58 !macro UNINSTALL.LOG_BEGIN_UNINSTALL
59   !verbose push
60      !verbose ${UNINST_LOG_VERBOSE}
62         IfFileExists "${UNINST_DAT}" +3
63         MessageBox MB_ICONSTOP|MB_OK "${UNINST_DAT} not found, unable to perform uninstall." /SD IDOK
64         Quit
66         StrCmp "$PLUGINSDIR" "" 0 +2
67            InitPluginsDir
69         CopyFiles "${UNINST_DAT}" "${UNLOG_TEMP}"
70         FileOpen $unlog_tmp_2 "${UNLOG_TEMP}" r
72   !verbose pop
73 !macroend
76 !macro UNINSTALL.LOG_END_UNINSTALL
77   !verbose push
78      !verbose ${UNINST_LOG_VERBOSE}
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"
84   !verbose pop
85 !macroend
88 !macro UNINSTALL.LOG_UNINSTALL TargetDir
89   !verbose push
90      !verbose ${UNINST_LOG_VERBOSE}
92      !ifndef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
93         !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
94      !endif
96      !ifdef INTERACTIVE_UNINSTALL
97         GetTempFileName $unlog_tmp_5 "$PLUGINSDIR"
98         FileOpen $unlog_tmp_4 "$unlog_tmp_5" a
99      !endif
101         ${PerfomUninstall} "${TargetDir}" "${UnLog_Uninstall_CallBackFunc}"
103      !ifdef INTERACTIVE_UNINSTALL
104         FileClose $unlog_tmp_4
105      !endif
107   !verbose pop
108 !macroend
111 !define PerfomUninstall "!insertmacro PERFORMUNINSTALL"
113 !macro PERFORMUNINSTALL TargetDir UninstCallBackFunc
114   !verbose push
115      !verbose ${UNINST_LOG_VERBOSE}
117    !define ID ${__LINE__}
119         ${un.Locate} "${TargetDir}" "/L=F" "${UninstCallBackFunc}"
121     loop_${ID}:
123         StrCpy $unlog_tmp_1 0
125         ${un.Locate} "${TargetDir}" "/L=DE" "${UninstCallBackFunc}"
126         StrCmp $unlog_tmp_1 "0" 0 loop_${ID}
128         ${un.DirState} "${TargetDir}" $unlog_tmp_0
129         StrCmp "$unlog_tmp_0" "0" 0 +2
130         RmDir "${TargetDir}"
132         IfErrors 0 +2
133         MessageBox MB_ICONEXCLAMATION|MB_OK "${UNINSTALL_LOG} Log error" /SD IDOK
135    !undef ID
137   !verbose pop
138 !macroend
141 !macro INTERACTIVE_UNINSTALL
142   !verbose push
143      !verbose ${UNINST_LOG_VERBOSE}
145      !ifdef INTERACTIVE_UNINSTALL
146         !error "INTERACTIVE_UNINSTALL is already defined"
147      !endif
149         var unlog_tmp_4
150         var unlog_tmp_5
152      !define INTERACTIVE_UNINSTALL
154      !ifdef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
155         !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
156      !endif
158      !ifdef UnLog_Uninstall_CallBackFunc
159         !undef UnLog_Uninstall_CallBackFunc
160      !endif
162      !ifndef UnLog_Uninstall_CallBackFunc
163         !insertmacro UNINSTALL.LOG_UNINSTALL_INTERACTIVE
164         !define UnLog_Uninstall_CallBackFunc "un._LocateCallBack_Function_Interactive"
165      !endif
167   !verbose pop
168 !macroend
171 !macro UNATTENDED_UNINSTALL
172   !verbose push
173      !verbose ${UNINST_LOG_VERBOSE}
175      !ifdef UNATTENDED_UNINSTALL
176         !error "UNATTENDED_UNINSTALL is already defined"
177      !endif
179      !define UNATTENDED_UNINSTALL
181      !ifdef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
182         !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
183      !endif
185      !ifdef UnLog_Uninstall_CallBackFunc
186         !undef UnLog_Uninstall_CallBackFunc
187      !endif
189      !ifndef UnLog_Uninstall_CallBackFunc
190         !insertmacro UNINSTALL.LOG_UNINSTALL_UNATTENDED
191         !define UnLog_Uninstall_CallBackFunc "un._LocateCallBack_Function_Unattended"
192      !endif
194   !verbose pop
195 !macroend
198 !macro UNINSTALL.LOG_UNINSTALL_UNATTENDED
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
208     islog:
209         IfFileExists "$R9\*.*" isdir
211     isfile:
212         Delete "$R9"
213         goto end
215     isdir:
216         RmDir "$R9"
217         IntOp $unlog_tmp_1 $unlog_tmp_1 + 1
218         goto end
220     nolog:
221         ClearErrors
222         StrCmp "$R9" "${UNINST_EXE}" isfile
223         StrCmp "$R9" "${UNINST_DAT}" isfile
225     end:
226         FileSeek $unlog_tmp_2 0 SET
227         Push $unlog_tmp_0
228   FunctionEnd
230 !macroend
233 !macro UNINSTALL.LOG_UNINSTALL_INTERACTIVE
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
243     islog:
244         IfFileExists "$R9\*.*" isdir
246     isfile:
247         Delete "$R9"
248         goto end
250     isdir:
251         RmDir "$R9"
252         IntOp $unlog_tmp_1 $unlog_tmp_1 + 1
253         goto end
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
269         MessageBox MB_ICONQUESTION|MB_YESNO \
270         'Delete File "$R9"?' /SD IDNO IDYES isfile IDNO nodel
272     msgdir:
273         MessageBox MB_ICONQUESTION|MB_YESNO \
274         'Delete Directory "$R9"?' /SD IDNO IDYES isdir IDNO nodel
276     nodel:
277         FileSeek $unlog_tmp_4 0 END
278         FileWrite $unlog_tmp_4 "$R9$\r$\n"
280     end:
281         FileSeek $unlog_tmp_2 0 SET
282         Push $unlog_tmp_0
283   FunctionEnd
285 !macroend
287 ;................................. Installer Macros .................................
289 !macro UNINSTALL.LOG_INSTALL_UNATTENDED
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
307 !macroend
310 !ifdef UnLog_Install_Func_CallBack
311     !undef UnLog_Install_Func_CallBack
312 !endif
314 !ifndef UnLog_Install_Func_CallBack
315     !insertmacro UNINSTALL.LOG_INSTALL_UNATTENDED
316     !define UnLog_Install_Func_CallBack "_LocateCallBack_Function_Install"
317 !endif
320 !macro UNINSTALL.LOG_PREPARE_INSTALL
321   !verbose push
322      !verbose ${UNINST_LOG_VERBOSE}
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"
339     next:
340         ClearErrors
341         StrCmp "$PLUGINSDIR" "" 0 +2
342            InitPluginsDir
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
352   !verbose pop
353 !macroend
356 !macro UNINSTALL.LOG_UPDATE_INSTALL
357   !verbose push
358      !verbose ${UNINST_LOG_VERBOSE}
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"
366   !verbose pop
367 !macroend
370 !define uninstall.log_install "!insertmacro UNINSTALL.LOG_INSTALL"
372 !macro UNINSTALL.LOG_INSTALL FileOpenWrite FileOpenRead TargetDir
373   !verbose push
374      !verbose ${UNINST_LOG_VERBOSE}
376         FileOpen $unlog_tmp_1 "${FileOpenWrite}" w
377         FileOpen $unlog_tmp_2 "${FileOpenRead}" r
379         ${Locate} "${TargetDir}" "/L=FD" "${UnLog_Install_Func_CallBack}"
381         StrCmp $unlog_error "error" 0 +2
382         ClearErrors
384         IfErrors 0 +2
385         MessageBox MB_ICONEXCLAMATION|MB_OK "Error creating ${UNINSTALL_LOG} Log." /SD IDOK
387         FileClose $unlog_tmp_1
388         FileClose $unlog_tmp_2
390   !verbose pop
391 !macroend
394 !define uninstall.log_mergeID "!insertmacro UNINSTALL.LOG_MERGE"
396 !macro UNINSTALL.LOG_MERGE UnlogPart
397   !verbose push
398      !verbose ${UNINST_LOG_VERBOSE}
400         ${FileJoin} "${UNLOG_TEMP}" "${UnlogPart}" "${UNLOG_TEMP}"
402   !verbose pop
403 !macroend
406 !macro UNINSTALL.LOG_OPEN_INSTALL
407   !verbose push
408      !verbose ${UNINST_LOG_VERBOSE}
410         StrCmp $unlog_error "error" +2
411         ${uninstall.log_install} "${EXCLU_LIST}" "${UNINST_DAT}" "$OUTDIR"
413   !verbose pop
414 !macroend
417 !macro UNINSTALL.LOG_CLOSE_INSTALL
418   !verbose push
419      !verbose ${UNINST_LOG_VERBOSE}
421    !define ID ${__LINE__}
423         ${uninstall.log_install} "${UNLOG_PART}${ID}" "${EXCLU_LIST}" "$OUTDIR"
424         ${uninstall.log_mergeID} "${UNLOG_PART}${ID}"
426    !undef ID
428   !verbose pop
429 !macroend
431 !endif
433 !verbose pop
434      ;_____________________________ HEADER FILE END ____________________________