|
| 1 | +/* |
| 2 | +
|
| 3 | +NSIS Uninstaller Data |
| 4 | +Copyright 2014 Aleksandr Ivankiv |
| 5 | +
|
| 6 | +Modified by the Betaflight Team project to let it be used out of the uninstall section |
| 7 | +*/ |
| 8 | + |
| 9 | +;-------------------------------- |
| 10 | + |
| 11 | +!ifndef UNINST_INCLUDED |
| 12 | +!define UNINST_INCLUDED |
| 13 | + |
| 14 | +!verbose push |
| 15 | +!verbose 3 |
| 16 | + |
| 17 | +!ifndef UNINST_VERBOSE |
| 18 | + !define UNINST_VERBOSE 3 |
| 19 | +!endif |
| 20 | + |
| 21 | +!verbose ${UNINST_VERBOSE} |
| 22 | + |
| 23 | +;-------------------------------- |
| 24 | +;Header files required by Uninstaller Data |
| 25 | + |
| 26 | +!include "FileFunc.nsh" |
| 27 | +!include "TextFunc.nsh" |
| 28 | + |
| 29 | +;-------------------------------- |
| 30 | +;Variables |
| 31 | + |
| 32 | +Var List |
| 33 | +Var Log |
| 34 | +Var Tmp |
| 35 | +Var UNINST_DAT |
| 36 | +Var UNINST_EXE |
| 37 | +Var UNINST_DEL_FILE |
| 38 | + |
| 39 | +;-------------------------------- |
| 40 | +;Default language strings |
| 41 | + |
| 42 | +!define UNINST_EXCLUDE_ERROR_DEFAULT "Error creating an exclusion list." |
| 43 | +!define UNINST_DATA_ERROR_DEFAULT "Error creating the uninstaller data: $\r$\nCannot find an exclusion list." |
| 44 | +!define UNINST_DAT_NOT_FOUND_DEFAULT "$UNINST_DAT not found, unable to perform uninstall. Manually delete files." |
| 45 | +!define UNINST_DAT_MISSING_DEFAULT "$UNINST_DAT is missing, some elements could not be removed. These can be removed manually." |
| 46 | +!define UNINST_DEL_FILE_DEFAULT "Delete File" |
| 47 | + |
| 48 | +;-------------------------------- |
| 49 | +;Language strings macro |
| 50 | + |
| 51 | +!macro SETSTRING NAME |
| 52 | + |
| 53 | + !ifndef "${NAME}" |
| 54 | + !ifdef UNINST_LOCALIZE |
| 55 | + !define "${NAME}" "$(${NAME})" |
| 56 | + !else |
| 57 | + !define "${NAME}" "${${NAME}_DEFAULT}" |
| 58 | + !endif |
| 59 | + !endif |
| 60 | + |
| 61 | +!macroend |
| 62 | + |
| 63 | +;-------------------------------- |
| 64 | +;Initialization macro |
| 65 | + |
| 66 | +!macro UNINST_INIT |
| 67 | + |
| 68 | + ;Default settings |
| 69 | + !ifndef UninstName |
| 70 | + !define UninstName "Uninstall" |
| 71 | + !endif |
| 72 | + !ifndef UninstHeader |
| 73 | + !define UninstHeader "=========== Uninstaller Data please do not edit this file ===========" |
| 74 | + !endif |
| 75 | + !insertmacro SETSTRING "UNINST_EXCLUDE_ERROR" |
| 76 | + !insertmacro SETSTRING "UNINST_DATA_ERROR" |
| 77 | + !insertmacro SETSTRING "UNINST_DAT_NOT_FOUND" |
| 78 | + !insertmacro SETSTRING "UNINST_DAT_MISSING" |
| 79 | + !insertmacro SETSTRING "UNINST_DEL_FILE" |
| 80 | + StrCpy $UNINST_DEL_FILE "${UNINST_DEL_FILE}" |
| 81 | + StrCpy $UNINST_DAT "$OUTDIR\${UninstName}.dat" |
| 82 | + StrCpy $UNINST_EXE "$OUTDIR\${UninstName}.exe" |
| 83 | + |
| 84 | +!macroend |
| 85 | + |
| 86 | +;-------------------------------- |
| 87 | +;Change name of file |
| 88 | + |
| 89 | +!macro UNINST_NAME Name |
| 90 | + |
| 91 | + !ifdef UninstName |
| 92 | + !undef UninstName |
| 93 | + !define UninstName "${Name}" |
| 94 | + !else |
| 95 | + !define UninstName "${Name}" |
| 96 | + !endif |
| 97 | + !insertmacro UNINST_INIT |
| 98 | + |
| 99 | +!macroend |
| 100 | + |
| 101 | +;-------------------------------- |
| 102 | +;Create an exclusion list |
| 103 | + |
| 104 | +!macro UNINSTALLER_DATA_BEGIN |
| 105 | + |
| 106 | + !insertmacro UNINST_EXCLUDE |
| 107 | + |
| 108 | +!macroend |
| 109 | + |
| 110 | +!macro UNINST_EXCLUDE |
| 111 | + |
| 112 | + !verbose push |
| 113 | + !verbose ${UNINST_VERBOSE} |
| 114 | + |
| 115 | + !insertmacro UNINST_INIT |
| 116 | + |
| 117 | + StrCmp "$PLUGINSDIR" "" 0 +2 |
| 118 | + InitPluginsDir |
| 119 | + |
| 120 | + GetTempFileName $Tmp $PLUGINSDIR |
| 121 | + |
| 122 | + IfErrors 0 UninstExclude |
| 123 | + !ifndef UNINST_ERROR |
| 124 | + !define UNINST_ERROR |
| 125 | + MessageBox MB_OK|MB_ICONEXCLAMATION "${UNINST_EXCLUDE_ERROR}" /SD IDOK |
| 126 | + Goto +3 |
| 127 | + !endif |
| 128 | + |
| 129 | + UninstExclude: |
| 130 | + FileOpen $List "$Tmp" w |
| 131 | + ${Locate} "$OUTDIR" "/L=FD" "${ExcludeList_Func_CallBack}" |
| 132 | + FileClose $List |
| 133 | + |
| 134 | + !verbose pop |
| 135 | + |
| 136 | +!macroend |
| 137 | + |
| 138 | +!macro UNINST_FUNCTION_EXCLUDELIST |
| 139 | + |
| 140 | + Function ExcludeList |
| 141 | + |
| 142 | + FileWrite $List "$R9$\r$\n" |
| 143 | + Push $0 |
| 144 | + |
| 145 | + FunctionEnd |
| 146 | + |
| 147 | +!macroend |
| 148 | + |
| 149 | +!ifndef ExcludeList_Func_CallBack |
| 150 | + !insertmacro UNINST_FUNCTION_EXCLUDELIST |
| 151 | + !define ExcludeList_Func_CallBack "ExcludeList" |
| 152 | +!endif |
| 153 | + |
| 154 | +;---------------------------------------------------------------- |
| 155 | +;Write Uninstaller Data |
| 156 | + |
| 157 | +!macro UNINSTALLER_DATA_END |
| 158 | + |
| 159 | + !insertmacro UNINST_DATA |
| 160 | + |
| 161 | +!macroend |
| 162 | + |
| 163 | +!macro UNINST_DATA |
| 164 | + |
| 165 | + !verbose push |
| 166 | + !verbose ${UNINST_VERBOSE} |
| 167 | + |
| 168 | + !insertmacro UNINST_INIT |
| 169 | + |
| 170 | + IfFileExists "$Tmp" UninstData |
| 171 | + !ifndef UNINST_ERROR |
| 172 | + !define UNINST_ERROR |
| 173 | + ${GetFileName} "$UNINST_DAT" $R0 |
| 174 | + MessageBox MB_OK|MB_ICONEXCLAMATION "${UNINST_DATA_ERROR}" /SD IDOK |
| 175 | + !endif |
| 176 | + Goto DoneUninstData |
| 177 | + |
| 178 | + UninstData: |
| 179 | + FileOpen $Log "$UNINST_DAT" a |
| 180 | + FileOpen $List "$Tmp" r |
| 181 | + |
| 182 | + FileRead $Log $1 |
| 183 | + IfErrors 0 +2 |
| 184 | + FileWrite $Log "${UninstHeader}$\r$\n" |
| 185 | + |
| 186 | + ${Locate} "$OUTDIR" "/L=FD" "${UninstallData_Func_CallBack}" |
| 187 | + |
| 188 | + FileClose $List |
| 189 | + FileClose $Log |
| 190 | + |
| 191 | + DoneUninstData: |
| 192 | + StrCpy $Tmp "" |
| 193 | + |
| 194 | + !verbose pop |
| 195 | + |
| 196 | +!macroend |
| 197 | + |
| 198 | +!macro UNINST_FUNCTION_UNINSTDATA |
| 199 | + |
| 200 | + Function UninstallData |
| 201 | + |
| 202 | + StrCmp $R9 $UNINST_DAT Done |
| 203 | + |
| 204 | + FileSeek $List 0 SET |
| 205 | + |
| 206 | + LoopReadList: |
| 207 | + FileRead $List $1 ${NSIS_MAX_STRLEN} |
| 208 | + IfErrors DoneReadList |
| 209 | + |
| 210 | + ${TrimNewLines} $1 $R0 |
| 211 | + StrCmp $R0 $R9 Done |
| 212 | + |
| 213 | + Goto LoopReadList |
| 214 | + |
| 215 | + DoneReadList: |
| 216 | + FileSeek $Log 0 SET |
| 217 | + |
| 218 | + LoopReadLog: |
| 219 | + FileRead $Log $1 ${NSIS_MAX_STRLEN} |
| 220 | + IfErrors DoneReadLog |
| 221 | + |
| 222 | + ${TrimNewLines} $1 $R0 |
| 223 | + StrCmp $R0 $R9 Done |
| 224 | + |
| 225 | + Goto LoopReadLog |
| 226 | + |
| 227 | + DoneReadLog: |
| 228 | + FileSeek $Log 0 END |
| 229 | + FileWrite $Log "$R9$\r$\n" |
| 230 | + |
| 231 | + Done: |
| 232 | + Push $0 |
| 233 | + |
| 234 | + FunctionEnd |
| 235 | + |
| 236 | +!macroend |
| 237 | + |
| 238 | +!ifndef UninstallData_Func_CallBack |
| 239 | + !insertmacro UNINST_FUNCTION_UNINSTDATA |
| 240 | + !define UninstallData_Func_CallBack "UninstallData" |
| 241 | +!endif |
| 242 | + |
| 243 | +;---------------------------------------------------------------- |
| 244 | +;Uninstall Files |
| 245 | + |
| 246 | +!macro INST_DELETE Path Name |
| 247 | + !insertmacro UNINST_DELETE_MULTIPLE ${Path} ${Name} "" |
| 248 | +!macroend |
| 249 | + |
| 250 | +!macro UNINST_DELETE Path Name |
| 251 | + !insertmacro UNINST_DELETE_MULTIPLE ${Path} ${Name} "un." |
| 252 | +!macroend |
| 253 | + |
| 254 | +!macro UNINST_DELETE_MULTIPLE Path Name un |
| 255 | + |
| 256 | + !verbose push |
| 257 | + !verbose ${UNINST_VERBOSE} |
| 258 | + |
| 259 | + !if "${Path}" == "" |
| 260 | + StrCpy $OUTDIR "$INSTDIR" |
| 261 | + !else |
| 262 | + StrCpy $OUTDIR "${Path}" |
| 263 | + !endif |
| 264 | + !if "${Name}" == "" |
| 265 | + !insertmacro UNINST_NAME "Uninstall" |
| 266 | + !else |
| 267 | + !insertmacro UNINST_NAME "${Name}" |
| 268 | + !endif |
| 269 | + |
| 270 | + !insertmacro UNINST_INIT |
| 271 | + |
| 272 | + IfFileExists "$UNINST_DAT" +3 |
| 273 | + !ifdef UNINST_TERMINATE |
| 274 | + MessageBox MB_OK|MB_ICONSTOP "${UNINST_DAT_NOT_FOUND}" /SD IDOK |
| 275 | + Quit |
| 276 | + !else |
| 277 | + MessageBox MB_OK|MB_ICONEXCLAMATION "${UNINST_DAT_MISSING}" /SD IDOK |
| 278 | + StrCpy $0 "error" |
| 279 | + !endif |
| 280 | + |
| 281 | + ${If} $0 != "error" |
| 282 | + |
| 283 | + FileOpen $Log "$UNINST_DAT" r |
| 284 | + Call ${un}DeleteList |
| 285 | + FileClose $Log |
| 286 | + |
| 287 | + Delete "$UNINST_DAT" |
| 288 | + |
| 289 | + !ifdef UNINST_INTERACTIVE |
| 290 | + ${Locate} "$OUTDIR" "/L=F" "${un.InterActive_Func_CallBack}" |
| 291 | + ${Locate} "$OUTDIR" "/L=DE" "${un.InterActive_Func_CallBack}" |
| 292 | + !else |
| 293 | + Call ${un}InterActive |
| 294 | + !endif |
| 295 | + |
| 296 | + ${Else} |
| 297 | + StrCpy $0 "" |
| 298 | + ${EndIf} |
| 299 | + |
| 300 | + Delete "$UNINST_EXE" |
| 301 | + RMDir $OUTDIR |
| 302 | + ClearErrors |
| 303 | + |
| 304 | + !verbose pop |
| 305 | + |
| 306 | +!macroend |
| 307 | + |
| 308 | +!macro UNINST_FUNCTION_DELETE un |
| 309 | + |
| 310 | + Function ${un}DeleteList |
| 311 | + |
| 312 | + LoopReadFile: |
| 313 | + FileRead $Log $1 ${NSIS_MAX_STRLEN} |
| 314 | + IfErrors DoneReadFile |
| 315 | + |
| 316 | + ${TrimNewLines} $1 $R0 |
| 317 | + |
| 318 | + IfFileExists $R0\*.* +3 |
| 319 | + IfFileExists $R0 0 +2 |
| 320 | + Delete $R0 |
| 321 | + |
| 322 | + Goto LoopReadFile |
| 323 | + |
| 324 | + DoneReadFile: |
| 325 | + FileSeek $Log 0 SET |
| 326 | + |
| 327 | + LoopReadDIR: |
| 328 | + FileRead $Log $1 ${NSIS_MAX_STRLEN} |
| 329 | + IfErrors DoneReadDIR |
| 330 | + |
| 331 | + ${TrimNewLines} $1 $R0 |
| 332 | + |
| 333 | + IfFileExists $R0\*.* 0 +3 |
| 334 | + RMDir $R0 |
| 335 | + ClearErrors |
| 336 | + |
| 337 | + Goto LoopReadDIR |
| 338 | + |
| 339 | + DoneReadDIR: |
| 340 | + |
| 341 | + FunctionEnd |
| 342 | + |
| 343 | +!macroend |
| 344 | + |
| 345 | +!insertmacro UNINST_FUNCTION_DELETE "" |
| 346 | +!insertmacro UNINST_FUNCTION_DELETE "un." |
| 347 | + |
| 348 | +!macro UNINST_FUNCTION_INTERACTIVE un |
| 349 | + |
| 350 | + Function ${un}InterActive |
| 351 | + |
| 352 | + StrCmp $R9 "" +8 |
| 353 | + IfFileExists $R9\*.* 0 +3 |
| 354 | + RMDir $R9 |
| 355 | + Goto +4 |
| 356 | + StrCmp $R9 $UNINST_EXE +3 |
| 357 | + MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "$UNINST_DEL_FILE '$R9'?" /SD IDNO IDNO +2 |
| 358 | + Delete $R9 |
| 359 | + Push $0 |
| 360 | + |
| 361 | + FunctionEnd |
| 362 | + |
| 363 | +!macroend |
| 364 | + |
| 365 | +!ifndef un.InterActive_Func_CallBack |
| 366 | + !insertmacro UNINST_FUNCTION_INTERACTIVE "un." |
| 367 | + !define un.InterActive_Func_CallBack "un.InterActive" |
| 368 | +!endif |
| 369 | + |
| 370 | +!ifndef InterActive_Func_CallBack |
| 371 | + !insertmacro UNINST_FUNCTION_INTERACTIVE "" |
| 372 | + !define InterActive_Func_CallBack "InterActive" |
| 373 | +!endif |
| 374 | + |
| 375 | +!verbose pop |
| 376 | + |
| 377 | +!endif |
0 commit comments