anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
NSIS.template.in (22807B)
1 ; CPack install script designed for a nmake build 2 3 ;-------------------------------- 4 ; You must define these values 5 6 !define VERSION "@CPACK_PACKAGE_VERSION@" 7 !define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@" 8 9 ;-------------------------------- 10 ;Variables 11 12 Var MUI_TEMP 13 Var STARTMENU_FOLDER 14 Var SV_ALLUSERS 15 Var START_MENU 16 Var DO_NOT_ADD_TO_PATH 17 Var ADD_TO_PATH_ALL_USERS 18 Var ADD_TO_PATH_CURRENT_USER 19 Var INSTALL_DESKTOP 20 21 ;-------------------------------- 22 ;Include Modern UI 23 24 !include "MUI2.nsh" 25 26 ;Default installation folder 27 InstallDir "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 28 29 ;-------------------------------- 30 ;General 31 32 ;Name and file 33 Name "@CPACK_PACKAGE_NAME@ @CPACK_PACKAGE_VERSION@" 34 OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@" 35 36 ;Set compression 37 SetCompressor @CPACK_NSIS_COMPRESSOR@ 38 39 @CPACK_NSIS_DEFINES@ 40 41 !include Sections.nsh 42 43 ;--- Component support macros: --- 44 ; The code for the add/remove functionality is from: 45 ; http://nsis.sourceforge.net/Add/Remove_Functionality 46 ; It has been modified slightly and extended to provide 47 ; inter-component dependencies. 48 Var AR_SecFlags 49 Var AR_RegFlags 50 @CPACK_NSIS_SECTION_SELECTED_VARS@ 51 52 ; Loads the "selected" flag for the section named SecName into the 53 ; variable VarName. 54 !macro LoadSectionSelectedIntoVar SecName VarName 55 SectionGetFlags ${${SecName}} $${VarName} 56 IntOp $${VarName} $${VarName} & ${SF_SELECTED} ;Turn off all other bits 57 !macroend 58 59 ; Loads the value of a variable... can we get around this? 60 !macro LoadVar VarName 61 IntOp $R0 0 + $${VarName} 62 !macroend 63 64 ; Sets the value of a variable 65 !macro StoreVar VarName IntValue 66 IntOp $${VarName} 0 + ${IntValue} 67 !macroend 68 69 !macro InitSection SecName 70 ; This macro reads component installed flag from the registry and 71 ;changes checked state of the section on the components page. 72 ;Input: section index constant name specified in Section command. 73 74 ClearErrors 75 ;Reading component status from registry 76 ReadRegDWORD $AR_RegFlags HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@\Components\${SecName}" "Installed" 77 IfErrors "default_${SecName}" 78 ;Status will stay default if registry value not found 79 ;(component was never installed) 80 IntOp $AR_RegFlags $AR_RegFlags & ${SF_SELECTED} ;Turn off all other bits 81 SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading default section flags 82 IntOp $AR_SecFlags $AR_SecFlags & 0xFFFE ;Turn lowest (enabled) bit off 83 IntOp $AR_SecFlags $AR_RegFlags | $AR_SecFlags ;Change lowest bit 84 85 ; Note whether this component was installed before 86 !insertmacro StoreVar ${SecName}_was_installed $AR_RegFlags 87 IntOp $R0 $AR_RegFlags & $AR_RegFlags 88 89 ;Writing modified flags 90 SectionSetFlags ${${SecName}} $AR_SecFlags 91 92 "default_${SecName}:" 93 !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected 94 !macroend 95 96 !macro FinishSection SecName 97 ; This macro reads section flag set by user and removes the section 98 ;if it is not selected. 99 ;Then it writes component installed flag to registry 100 ;Input: section index constant name specified in Section command. 101 102 SectionGetFlags ${${SecName}} $AR_SecFlags ;Reading section flags 103 ;Checking lowest bit: 104 IntOp $AR_SecFlags $AR_SecFlags & ${SF_SELECTED} 105 IntCmp $AR_SecFlags 1 "leave_${SecName}" 106 ;Section is not selected: 107 ;Calling Section uninstall macro and writing zero installed flag 108 !insertmacro "Remove_${${SecName}}" 109 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@\Components\${SecName}" \ 110 "Installed" 0 111 Goto "exit_${SecName}" 112 113 "leave_${SecName}:" 114 ;Section is selected: 115 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@\Components\${SecName}" \ 116 "Installed" 1 117 118 "exit_${SecName}:" 119 !macroend 120 121 !macro RemoveSection_CPack SecName 122 ; This macro is used to call section's Remove_... macro 123 ;from the uninstaller. 124 ;Input: section index constant name specified in Section command. 125 126 !insertmacro "Remove_${${SecName}}" 127 !macroend 128 129 ; Determine whether the selection of SecName changed 130 !macro MaybeSelectionChanged SecName 131 !insertmacro LoadVar ${SecName}_selected 132 SectionGetFlags ${${SecName}} $R1 133 IntOp $R1 $R1 & ${SF_SELECTED} ;Turn off all other bits 134 135 ; See if the status has changed: 136 IntCmp $R0 $R1 "${SecName}_unchanged" 137 !insertmacro LoadSectionSelectedIntoVar ${SecName} ${SecName}_selected 138 139 IntCmp $R1 ${SF_SELECTED} "${SecName}_was_selected" 140 !insertmacro "Deselect_required_by_${SecName}" 141 goto "${SecName}_unchanged" 142 143 "${SecName}_was_selected:" 144 !insertmacro "Select_${SecName}_depends" 145 146 "${SecName}_unchanged:" 147 !macroend 148 ;--- End of Add/Remove macros --- 149 150 ;-------------------------------- 151 ;Interface Settings 152 153 !define MUI_ABORTWARNING 154 155 ;---------------------------------------- 156 ; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02" 157 ;---------------------------------------- 158 !verbose 3 159 !include "WinMessages.NSH" 160 !verbose 4 161 162 ;==================================================== 163 ; get_NT_environment 164 ; Returns: the selected environment 165 ; Output : head of the stack 166 ;==================================================== 167 !macro select_NT_profile UN 168 Function ${UN}select_NT_profile 169 StrCmp $ADD_TO_PATH_ALL_USERS "1" 0 environment_single 170 DetailPrint "Selected environment for all users" 171 Push "all" 172 Return 173 environment_single: 174 DetailPrint "Selected environment for current user only." 175 Push "current" 176 Return 177 FunctionEnd 178 !macroend 179 !insertmacro select_NT_profile "" 180 !insertmacro select_NT_profile "un." 181 ;---------------------------------------------------- 182 !define NT_current_env 'HKCU "Environment"' 183 !define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' 184 185 !ifndef WriteEnvStr_RegKey 186 !ifdef ALL_USERS 187 !define WriteEnvStr_RegKey \ 188 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' 189 !else 190 !define WriteEnvStr_RegKey 'HKCU "Environment"' 191 !endif 192 !endif 193 194 ; AddToPath - Adds the given dir to the search path. 195 ; Input - head of the stack 196 ; Note - Win9x systems requires reboot 197 198 Function AddToPath 199 Exch $0 200 Push $1 201 Push $2 202 Push $3 203 204 # don't add if the path doesn't exist 205 IfFileExists "$0\*.*" "" AddToPath_done 206 207 ReadEnvStr $1 PATH 208 Push "$1;" 209 Push "$0;" 210 Call StrStr 211 Pop $2 212 StrCmp $2 "" "" AddToPath_done 213 Push "$1;" 214 Push "$0\;" 215 Call StrStr 216 Pop $2 217 StrCmp $2 "" "" AddToPath_done 218 GetFullPathName /SHORT $3 $0 219 Push "$1;" 220 Push "$3;" 221 Call StrStr 222 Pop $2 223 StrCmp $2 "" "" AddToPath_done 224 Push "$1;" 225 Push "$3\;" 226 Call StrStr 227 Pop $2 228 StrCmp $2 "" "" AddToPath_done 229 230 Call IsNT 231 Pop $1 232 StrCmp $1 1 AddToPath_NT 233 ; Not on NT 234 StrCpy $1 $WINDIR 2 235 FileOpen $1 "$1\autoexec.bat" a 236 FileSeek $1 -1 END 237 FileReadByte $1 $2 238 IntCmp $2 26 0 +2 +2 # DOS EOF 239 FileSeek $1 -1 END # write over EOF 240 FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n" 241 FileClose $1 242 SetRebootFlag true 243 Goto AddToPath_done 244 245 AddToPath_NT: 246 ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH" 247 StrCmp $1 "" AddToPath_NTdoIt 248 Push $1 249 Call Trim 250 Pop $1 251 StrCpy $0 "$1;$0" 252 AddToPath_NTdoIt: 253 WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0 254 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 255 256 AddToPath_done: 257 Pop $3 258 Pop $2 259 Pop $1 260 Pop $0 261 FunctionEnd 262 263 264 ; RemoveFromPath - Remove a given dir from the path 265 ; Input: head of the stack 266 267 Function un.RemoveFromPath 268 Exch $0 269 Push $1 270 Push $2 271 Push $3 272 Push $4 273 Push $5 274 Push $6 275 276 IntFmt $6 "%c" 26 # DOS EOF 277 278 Call un.IsNT 279 Pop $1 280 StrCmp $1 1 unRemoveFromPath_NT 281 ; Not on NT 282 StrCpy $1 $WINDIR 2 283 FileOpen $1 "$1\autoexec.bat" r 284 GetTempFileName $4 285 FileOpen $2 $4 w 286 GetFullPathName /SHORT $0 $0 287 StrCpy $0 "SET PATH=%PATH%;$0" 288 Goto unRemoveFromPath_dosLoop 289 290 unRemoveFromPath_dosLoop: 291 FileRead $1 $3 292 StrCpy $5 $3 1 -1 # read last char 293 StrCmp $5 $6 0 +2 # if DOS EOF 294 StrCpy $3 $3 -1 # remove DOS EOF so we can compare 295 StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine 296 StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine 297 StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine 298 StrCmp $3 "" unRemoveFromPath_dosLoopEnd 299 FileWrite $2 $3 300 Goto unRemoveFromPath_dosLoop 301 unRemoveFromPath_dosLoopRemoveLine: 302 SetRebootFlag true 303 Goto unRemoveFromPath_dosLoop 304 305 unRemoveFromPath_dosLoopEnd: 306 FileClose $2 307 FileClose $1 308 StrCpy $1 $WINDIR 2 309 Delete "$1\autoexec.bat" 310 CopyFiles /SILENT $4 "$1\autoexec.bat" 311 Delete $4 312 Goto unRemoveFromPath_done 313 314 unRemoveFromPath_NT: 315 ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH" 316 StrCpy $5 $1 1 -1 # copy last char 317 StrCmp $5 ";" +2 # if last char != ; 318 StrCpy $1 "$1;" # append ; 319 Push $1 320 Push "$0;" 321 Call un.StrStr ; Find `$0;` in $1 322 Pop $2 ; pos of our dir 323 StrCmp $2 "" unRemoveFromPath_done 324 ; else, it is in path 325 # $0 - path to add 326 # $1 - path var 327 StrLen $3 "$0;" 328 StrLen $4 $2 329 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove 330 StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove 331 StrCpy $3 $5$6 332 333 StrCpy $5 $3 1 -1 # copy last char 334 StrCmp $5 ";" 0 +2 # if last char == ; 335 StrCpy $3 $3 -1 # remove last char 336 337 WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3 338 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 339 340 unRemoveFromPath_done: 341 Pop $6 342 Pop $5 343 Pop $4 344 Pop $3 345 Pop $2 346 Pop $1 347 Pop $0 348 FunctionEnd 349 350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 351 ; Uninstall stuff 352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 353 354 ########################################### 355 # Utility Functions # 356 ########################################### 357 358 ;==================================================== 359 ; IsNT - Returns 1 if the current system is NT, 0 360 ; otherwise. 361 ; Output: head of the stack 362 ;==================================================== 363 ; IsNT 364 ; no input 365 ; output, top of the stack = 1 if NT or 0 if not 366 ; 367 ; Usage: 368 ; Call IsNT 369 ; Pop $R0 370 ; ($R0 at this point is 1 or 0) 371 372 !macro IsNT un 373 Function ${un}IsNT 374 Push $0 375 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion 376 StrCmp $0 "" 0 IsNT_yes 377 ; we are not NT. 378 Pop $0 379 Push 0 380 Return 381 382 IsNT_yes: 383 ; NT!!! 384 Pop $0 385 Push 1 386 FunctionEnd 387 !macroend 388 !insertmacro IsNT "" 389 !insertmacro IsNT "un." 390 391 ; StrStr 392 ; input, top of stack = string to search for 393 ; top of stack-1 = string to search in 394 ; output, top of stack (replaces with the portion of the string remaining) 395 ; modifies no other variables. 396 ; 397 ; Usage: 398 ; Push "this is a long ass string" 399 ; Push "ass" 400 ; Call StrStr 401 ; Pop $R0 402 ; ($R0 at this point is "ass string") 403 404 !macro StrStr un 405 Function ${un}StrStr 406 Exch $R1 ; st=haystack,old$R1, $R1=needle 407 Exch ; st=old$R1,haystack 408 Exch $R2 ; st=old$R1,old$R2, $R2=haystack 409 Push $R3 410 Push $R4 411 Push $R5 412 StrLen $R3 $R1 413 StrCpy $R4 0 414 ; $R1=needle 415 ; $R2=haystack 416 ; $R3=len(needle) 417 ; $R4=cnt 418 ; $R5=tmp 419 loop: 420 StrCpy $R5 $R2 $R3 $R4 421 StrCmp $R5 $R1 done 422 StrCmp $R5 "" done 423 IntOp $R4 $R4 + 1 424 Goto loop 425 done: 426 StrCpy $R1 $R2 "" $R4 427 Pop $R5 428 Pop $R4 429 Pop $R3 430 Pop $R2 431 Exch $R1 432 FunctionEnd 433 !macroend 434 !insertmacro StrStr "" 435 !insertmacro StrStr "un." 436 437 Function Trim ; Added by Pelaca 438 Exch $R1 439 Push $R2 440 Loop: 441 StrCpy $R2 "$R1" 1 -1 442 StrCmp "$R2" " " RTrim 443 StrCmp "$R2" "$\n" RTrim 444 StrCmp "$R2" "$\r" RTrim 445 StrCmp "$R2" ";" RTrim 446 GoTo Done 447 RTrim: 448 StrCpy $R1 "$R1" -1 449 Goto Loop 450 Done: 451 Pop $R2 452 Exch $R1 453 FunctionEnd 454 455 Function ConditionalAddToRegistry 456 Pop $0 457 Pop $1 458 StrCmp "$0" "" ConditionalAddToRegistry_EmptyString 459 WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" \ 460 "$1" "$0" 461 ;MessageBox MB_OK "Set Registry: '$1' to '$0'" 462 DetailPrint "Set install registry entry: '$1' to '$0'" 463 ConditionalAddToRegistry_EmptyString: 464 FunctionEnd 465 466 ;-------------------------------- 467 468 !ifdef CPACK_USES_DOWNLOAD 469 Function DownloadFile 470 IfFileExists $INSTDIR\* +2 471 CreateDirectory $INSTDIR 472 Pop $0 473 474 ; Skip if already downloaded 475 IfFileExists $INSTDIR\$0 0 +2 476 Return 477 478 StrCpy $1 "@CPACK_DOWNLOAD_SITE@" 479 480 try_again: 481 NSISdl::download "$1/$0" "$INSTDIR\$0" 482 483 Pop $1 484 StrCmp $1 "success" success 485 StrCmp $1 "Cancelled" cancel 486 MessageBox MB_OK "Download failed: $1" 487 cancel: 488 Return 489 success: 490 FunctionEnd 491 !endif 492 493 ;-------------------------------- 494 ; Installation types 495 @CPACK_NSIS_INSTALLATION_TYPES@ 496 497 ;-------------------------------- 498 ; Component sections 499 @CPACK_NSIS_COMPONENT_SECTIONS@ 500 501 ;-------------------------------- 502 ; Define some macro setting for the gui 503 @CPACK_NSIS_INSTALLER_MUI_ICON_CODE@ 504 @CPACK_NSIS_INSTALLER_ICON_CODE@ 505 @CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC@ 506 507 ;-------------------------------- 508 ;Pages 509 !define MUI_LANGDLL_REGISTRY_ROOT "SHCTX" 510 !define MUI_LANGDLL_REGISTRY_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" 511 !define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language" 512 513 !insertmacro MUI_PAGE_WELCOME 514 515 !insertmacro MUI_PAGE_LICENSE "@CPACK_RESOURCE_FILE_LICENSE@" 516 !insertmacro MUI_PAGE_DIRECTORY 517 518 ;Start Menu Folder Page Configuration 519 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "SHCTX" 520 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" 521 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder" 522 !insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER 523 524 @CPACK_NSIS_PAGE_COMPONENTS@ 525 526 !insertmacro MUI_PAGE_INSTFILES 527 528 !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\doc\README.txt" 529 !insertmacro MUI_PAGE_FINISH 530 531 !insertmacro MUI_UNPAGE_CONFIRM 532 !insertmacro MUI_UNPAGE_INSTFILES 533 534 ;-------------------------------- 535 ;Languages 536 537 !insertmacro MUI_LANGUAGE "Dutch" 538 !insertmacro MUI_LANGUAGE "English" 539 !insertmacro MUI_LANGUAGE "French" 540 !insertmacro MUI_LANGUAGE "German" 541 !insertmacro MUI_LANGUAGE "Italian" 542 !insertmacro MUI_LANGUAGE "Portuguese" 543 !insertmacro MUI_LANGUAGE "Spanish" 544 545 ;-------------------------------- 546 ;Installer Sections 547 548 Section "-Core installation" 549 ;Use the entire tree produced by the INSTALL target. Keep the 550 ;list of directories here in sync with the RMDir commands below. 551 SetOutPath "$INSTDIR" 552 @CPACK_NSIS_FULL_INSTALL@ 553 554 ;Store installation folder 555 WriteRegStr SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" "" $INSTDIR 556 557 ;Create uninstaller 558 WriteUninstaller "$INSTDIR\Uninstall.exe" 559 Push "DisplayName" 560 Push "@CPACK_NSIS_DISPLAY_NAME@" 561 Call ConditionalAddToRegistry 562 Push "DisplayVersion" 563 Push "@CPACK_PACKAGE_VERSION@" 564 Call ConditionalAddToRegistry 565 Push "Publisher" 566 Push "@CPACK_PACKAGE_VENDOR@" 567 Call ConditionalAddToRegistry 568 Push "UninstallString" 569 Push "$INSTDIR\Uninstall.exe" 570 Call ConditionalAddToRegistry 571 Push "NoRepair" 572 Push "1" 573 Call ConditionalAddToRegistry 574 575 !ifdef CPACK_NSIS_ADD_REMOVE 576 ;Create add/remove functionality 577 Push "ModifyPath" 578 Push "$INSTDIR\AddRemove.exe" 579 Call ConditionalAddToRegistry 580 !else 581 Push "NoModify" 582 Push "1" 583 Call ConditionalAddToRegistry 584 !endif 585 586 ; Optional registration 587 Push "DisplayIcon" 588 Push "$INSTDIR\@CPACK_NSIS_INSTALLED_ICON_NAME@" 589 Call ConditionalAddToRegistry 590 Push "HelpLink" 591 Push "@CPACK_NSIS_HELP_LINK@" 592 Call ConditionalAddToRegistry 593 Push "URLInfoAbout" 594 Push "@CPACK_NSIS_URL_INFO_ABOUT@" 595 Call ConditionalAddToRegistry 596 Push "Contact" 597 Push "@CPACK_NSIS_CONTACT@" 598 Call ConditionalAddToRegistry 599 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application 600 601 ;Create shortcuts 602 CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER" 603 @CPACK_NSIS_CREATE_ICONS@ 604 @CPACK_NSIS_CREATE_ICONS_EXTRA@ 605 CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe" 606 607 ; Write special uninstall registry entries 608 Push "StartMenu" 609 Push "$STARTMENU_FOLDER" 610 Call ConditionalAddToRegistry 611 Push "DoNotAddToPath" 612 Push "$DO_NOT_ADD_TO_PATH" 613 Call ConditionalAddToRegistry 614 Push "AddToPathAllUsers" 615 Push "$ADD_TO_PATH_ALL_USERS" 616 Call ConditionalAddToRegistry 617 Push "AddToPathCurrentUser" 618 Push "$ADD_TO_PATH_CURRENT_USER" 619 Call ConditionalAddToRegistry 620 Push "InstallToDesktop" 621 Push "$INSTALL_DESKTOP" 622 Call ConditionalAddToRegistry 623 624 @CPACK_NSIS_EXTRA_INSTALL_COMMANDS@ 625 626 !insertmacro MUI_STARTMENU_WRITE_END 627 628 SectionEnd 629 630 ;-------------------------------- 631 ; determine admin versus local install 632 Function un.onInit 633 634 ClearErrors 635 UserInfo::GetName 636 IfErrors noLM 637 Pop $0 638 UserInfo::GetAccountType 639 Pop $1 640 StrCmp $1 "Admin" 0 +3 641 SetShellVarContext all 642 ;MessageBox MB_OK 'User "$0" is in the Admin group' 643 Goto done 644 StrCmp $1 "Power" 0 +3 645 SetShellVarContext all 646 ;MessageBox MB_OK 'User "$0" is in the Power Users group' 647 Goto done 648 649 noLM: 650 ;Get installation folder from registry if available 651 652 done: 653 654 !insertmacro MUI_UNGETLANGUAGE 655 FunctionEnd 656 657 ;--- Add/Remove callback functions: --- 658 !macro SectionList MacroName 659 ;This macro used to perform operation on multiple sections. 660 ;List all of your components in following manner here. 661 @CPACK_NSIS_COMPONENT_SECTION_LIST@ 662 !macroend 663 664 Section -FinishComponents 665 ;Removes unselected components and writes component status to registry 666 !insertmacro SectionList "FinishSection" 667 668 !ifdef CPACK_NSIS_ADD_REMOVE 669 ; Get the name of the installer executable 670 System::Call 'kernel32::GetModuleFileNameA(i 0, t .R0, i 1024) i r1' 671 StrCpy $R3 $R0 672 673 ; Strip off the last 13 characters, to see if we have AddRemove.exe 674 StrLen $R1 $R0 675 IntOp $R1 $R0 - 13 676 StrCpy $R2 $R0 13 $R1 677 StrCmp $R2 "AddRemove.exe" addremove_installed 678 679 ; We're not running AddRemove.exe, so install it 680 CopyFiles $R3 $INSTDIR\AddRemove.exe 681 682 addremove_installed: 683 !endif 684 SectionEnd 685 ;--- End of Add/Remove callback functions --- 686 687 ;-------------------------------- 688 ; Component dependencies 689 Function .onSelChange 690 !insertmacro SectionList MaybeSelectionChanged 691 FunctionEnd 692 693 ;-------------------------------- 694 ;Uninstaller Section 695 696 Section "Uninstall" 697 ReadRegStr $START_MENU SHCTX \ 698 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" "StartMenu" 699 ;MessageBox MB_OK "Start menu is in: $START_MENU" 700 ReadRegStr $DO_NOT_ADD_TO_PATH SHCTX \ 701 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" "DoNotAddToPath" 702 ReadRegStr $ADD_TO_PATH_ALL_USERS SHCTX \ 703 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" "AddToPathAllUsers" 704 ReadRegStr $ADD_TO_PATH_CURRENT_USER SHCTX \ 705 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" "AddToPathCurrentUser" 706 ;MessageBox MB_OK "Add to path: $DO_NOT_ADD_TO_PATH all users: $ADD_TO_PATH_ALL_USERS" 707 ReadRegStr $INSTALL_DESKTOP SHCTX \ 708 "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" "InstallToDesktop" 709 ;MessageBox MB_OK "Install to desktop: $INSTALL_DESKTOP " 710 711 @CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@ 712 713 ;Remove files we installed. 714 ;Keep the list of directories here in sync with the File commands above. 715 @CPACK_NSIS_DELETE_FILES@ 716 @CPACK_NSIS_DELETE_DIRECTORIES@ 717 718 !ifdef CPACK_NSIS_ADD_REMOVE 719 ;Remove the add/remove program 720 Delete "$INSTDIR\AddRemove.exe" 721 !endif 722 723 ;Remove the uninstaller itself. 724 Delete "$INSTDIR\Uninstall.exe" 725 DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\@CPACK_PACKAGE_NAME@" 726 727 ;Remove the installation directory if it is empty. 728 RMDir "$INSTDIR" 729 730 ; Remove the registry entries. 731 DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" 732 733 ; Removes all optional components 734 !insertmacro SectionList "RemoveSection_CPack" 735 736 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP 737 738 Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk" 739 @CPACK_NSIS_DELETE_ICONS@ 740 @CPACK_NSIS_DELETE_ICONS_EXTRA@ 741 742 ;Delete empty start menu parent directories 743 StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP" 744 745 startMenuDeleteLoop: 746 ClearErrors 747 RMDir $MUI_TEMP 748 GetFullPathName $MUI_TEMP "$MUI_TEMP\.." 749 750 IfErrors startMenuDeleteLoopDone 751 752 StrCmp "$MUI_TEMP" "$SMPROGRAMS" startMenuDeleteLoopDone startMenuDeleteLoop 753 startMenuDeleteLoopDone: 754 755 ; If the user changed the shortcut, then uninstall may not work. This should 756 ; try to fix it. 757 StrCpy $MUI_TEMP "$START_MENU" 758 Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk" 759 @CPACK_NSIS_DELETE_ICONS_EXTRA@ 760 761 ;Delete empty start menu parent directories 762 StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP" 763 764 secondStartMenuDeleteLoop: 765 ClearErrors 766 RMDir $MUI_TEMP 767 GetFullPathName $MUI_TEMP "$MUI_TEMP\.." 768 769 IfErrors secondStartMenuDeleteLoopDone 770 771 StrCmp "$MUI_TEMP" "$SMPROGRAMS" secondStartMenuDeleteLoopDone secondStartMenuDeleteLoop 772 secondStartMenuDeleteLoopDone: 773 774 DeleteRegKey /ifempty SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@" 775 776 Push $INSTDIR\bin 777 StrCmp $DO_NOT_ADD_TO_PATH_ "1" doNotRemoveFromPath 0 778 Call un.RemoveFromPath 779 doNotRemoveFromPath: 780 SectionEnd 781 782 ;-------------------------------- 783 ; determine admin versus local install 784 ; Is install for "AllUsers" or "JustMe"? 785 ; Default to "JustMe" - set to "AllUsers" if admin or on Win9x 786 ; This function is used for the very first "custom page" of the installer. 787 ; This custom page does not show up visibly, but it executes prior to the 788 ; first visible page and sets up $INSTDIR properly... 789 ; Choose different default installation folder based on SV_ALLUSERS... 790 ; "Program Files" for AllUsers, "My Documents" for JustMe... 791 792 Function .onInit 793 !insertmacro MUI_LANGDLL_DISPLAY 794 ; Reads components status for registry 795 !insertmacro SectionList "InitSection" 796 797 StrCpy $SV_ALLUSERS "JustMe" 798 StrCpy $INSTDIR "$DOCUMENTS\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 799 800 ClearErrors 801 UserInfo::GetName 802 IfErrors noLM 803 Pop $0 804 UserInfo::GetAccountType 805 Pop $1 806 StrCmp $1 "Admin" 0 +3 807 SetShellVarContext all 808 ;MessageBox MB_OK 'User "$0" is in the Admin group' 809 StrCpy $SV_ALLUSERS "AllUsers" 810 Goto done 811 StrCmp $1 "Power" 0 +3 812 SetShellVarContext all 813 ;MessageBox MB_OK 'User "$0" is in the Power Users group' 814 StrCpy $SV_ALLUSERS "AllUsers" 815 Goto done 816 817 noLM: 818 StrCpy $SV_ALLUSERS "AllUsers" 819 ;Get installation folder from registry if available 820 821 done: 822 StrCmp $SV_ALLUSERS "AllUsers" 0 +2 823 StrCpy $INSTDIR "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@" 824 825 FunctionEnd