assistedInstaller.nsh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. !include UAC.nsh
  2. !ifndef INSTALL_MODE_PER_ALL_USERS
  3. !include multiUserUi.nsh
  4. !endif
  5. !ifndef BUILD_UNINSTALLER
  6. !ifmacrodef customWelcomePage
  7. !insertmacro customWelcomePage
  8. !endif
  9. !ifmacrodef licensePage
  10. !insertmacro skipPageIfUpdated
  11. !insertmacro licensePage
  12. !endif
  13. !ifndef INSTALL_MODE_PER_ALL_USERS
  14. !insertmacro PAGE_INSTALL_MODE
  15. !endif
  16. !ifdef allowToChangeInstallationDirectory
  17. !include StrContains.nsh
  18. !insertmacro skipPageIfUpdated
  19. !insertmacro MUI_PAGE_DIRECTORY
  20. # pageDirectory leave doesn't work (it seems because $INSTDIR is set after custom leave function)
  21. # so, we use instfiles pre
  22. !define MUI_PAGE_CUSTOMFUNCTION_PRE instFilesPre
  23. # sanitize the MUI_PAGE_DIRECTORY result to make sure it has a application name sub-folder
  24. Function instFilesPre
  25. ${StrContains} $0 "${APP_FILENAME}" $INSTDIR
  26. ${If} $0 == ""
  27. StrCpy $INSTDIR "$INSTDIR\${APP_FILENAME}"
  28. ${endIf}
  29. FunctionEnd
  30. !endif
  31. # after change installation directory and before install start, you can show custom page here.
  32. !ifmacrodef customPageAfterChangeDir
  33. !insertmacro customPageAfterChangeDir
  34. !endif
  35. !insertmacro MUI_PAGE_INSTFILES
  36. !ifmacrodef customFinishPage
  37. !insertmacro customFinishPage
  38. !else
  39. !ifndef HIDE_RUN_AFTER_FINISH
  40. Function StartApp
  41. ${if} ${isUpdated}
  42. StrCpy $1 "--updated"
  43. ${else}
  44. StrCpy $1 ""
  45. ${endif}
  46. ${StdUtils.ExecShellAsUser} $0 "$launchLink" "open" "$1"
  47. FunctionEnd
  48. !define MUI_FINISHPAGE_RUN
  49. !define MUI_FINISHPAGE_RUN_FUNCTION "StartApp"
  50. !endif
  51. !insertmacro MUI_PAGE_FINISH
  52. !endif
  53. !else
  54. !ifndef removeDefaultUninstallWelcomePage
  55. !insertmacro MUI_UNPAGE_WELCOME
  56. !endif
  57. !ifndef INSTALL_MODE_PER_ALL_USERS
  58. !insertmacro PAGE_INSTALL_MODE
  59. !endif
  60. !insertmacro MUI_UNPAGE_INSTFILES
  61. !ifmacrodef customUninstallPage
  62. !insertmacro customUninstallPage
  63. !endif
  64. !insertmacro MUI_UNPAGE_FINISH
  65. !endif
  66. !macro initMultiUser
  67. !ifdef INSTALL_MODE_PER_ALL_USERS
  68. !insertmacro setInstallModePerAllUsers
  69. !else
  70. ${If} ${UAC_IsInnerInstance}
  71. ${AndIfNot} ${UAC_IsAdmin}
  72. # special return value for outer instance so it knows we did not have admin rights
  73. SetErrorLevel 0x666666
  74. Quit
  75. ${endIf}
  76. !ifndef MULTIUSER_INIT_TEXT_ADMINREQUIRED
  77. !define MULTIUSER_INIT_TEXT_ADMINREQUIRED "$(^Caption) requires administrator privileges."
  78. !endif
  79. !ifndef MULTIUSER_INIT_TEXT_POWERREQUIRED
  80. !define MULTIUSER_INIT_TEXT_POWERREQUIRED "$(^Caption) requires at least Power User privileges."
  81. !endif
  82. !ifndef MULTIUSER_INIT_TEXT_ALLUSERSNOTPOSSIBLE
  83. !define MULTIUSER_INIT_TEXT_ALLUSERSNOTPOSSIBLE "Your user account does not have sufficient privileges to install $(^Name) for all users of this computer."
  84. !endif
  85. # checks registry for previous installation path (both for upgrading, reinstall, or uninstall)
  86. StrCpy $hasPerMachineInstallation "0"
  87. StrCpy $hasPerUserInstallation "0"
  88. # set installation mode to setting from a previous installation
  89. ReadRegStr $perMachineInstallationFolder HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation
  90. ${if} $perMachineInstallationFolder != ""
  91. StrCpy $hasPerMachineInstallation "1"
  92. ${endif}
  93. ReadRegStr $perUserInstallationFolder HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation
  94. ${if} $perUserInstallationFolder != ""
  95. StrCpy $hasPerUserInstallation "1"
  96. ${endif}
  97. ${GetParameters} $R0
  98. ${GetOptions} $R0 "/allusers" $R1
  99. ${IfNot} ${Errors}
  100. StrCpy $hasPerMachineInstallation "1"
  101. StrCpy $hasPerUserInstallation "0"
  102. ${EndIf}
  103. ${GetOptions} $R0 "/currentuser" $R1
  104. ${IfNot} ${Errors}
  105. StrCpy $hasPerMachineInstallation "0"
  106. StrCpy $hasPerUserInstallation "1"
  107. ${EndIf}
  108. ${if} $hasPerUserInstallation == "1"
  109. ${andif} $hasPerMachineInstallation == "0"
  110. !insertmacro setInstallModePerUser
  111. ${elseif} $hasPerUserInstallation == "0"
  112. ${andif} $hasPerMachineInstallation == "1"
  113. !insertmacro setInstallModePerAllUsers
  114. ${else}
  115. # if there is no installation, or there is both per-user and per-machine
  116. !ifdef INSTALL_MODE_PER_ALL_USERS
  117. !insertmacro setInstallModePerAllUsers
  118. !else
  119. !insertmacro setInstallModePerUser
  120. !endif
  121. ${endif}
  122. !endif
  123. !macroend