windows-installer.nsi 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. # Add current directory to plugin path
  2. !addplugindir .\
  3. # Architecture detection
  4. !include x64.nsh
  5. # Include LogicLib (http://nsis.sourceforge.net/LogicLib)
  6. !include 'LogicLib.nsh'
  7. # Include ZipDLL plugin (http://nsis.sourceforge.net/ZipDLL_plug-in)
  8. !include 'ZipDLL.nsh'
  9. # Include Locate plugin (http://nsis.sourceforge.net/Locate_plugin)
  10. !include 'locate.nsh'
  11. # Include MoveFileFolder plugin (http://nsis.sourceforge.net/MoveFileFolder)
  12. !include 'FileFunc.nsh'
  13. !insertmacro Locate
  14. Var /GLOBAL switch_overwrite
  15. !include 'MoveFileFolder.nsh'
  16. # Enable CRC
  17. CRCCheck on
  18. # Require admin privledges when UAC is on
  19. RequestExecutionLevel admin
  20. !searchreplace APPNAMENOHYPEN ${APPNAME} "-" " "
  21. !define GROUPNAME "Ethereum"
  22. !define HELPURL "https://github.com/ethereum/mist/releases/issues"
  23. !define UPDATEURL "https://github.com/ethereum/mist/releases"
  24. !define ABOUTURL "https://ethereum.org"
  25. !define /date NOW "%Y%m%d"
  26. ## These must be integers and can be set on the command line by NSIS with "/DMAJORVERSION=0 /DMINORVERSION=8 /DBUILDVERSION=7"
  27. #!define VERSIONMAJOR 0
  28. #!define VERSIONMINOR 8
  29. #!define VERSIONBUILD 7
  30. # Define some script globals
  31. Name "${GROUPNAME} ${APPNAME}"
  32. Icon "..\dist_${TYPE}\build\icon.ico"
  33. OutFile "..\dist_${TYPE}\release\${APPNAME}-installer-${VERSIONMAJOR}-${VERSIONMINOR}-${VERSIONBUILD}.exe"
  34. var FILEDIR
  35. var DATADIR
  36. var NODEDATADIR
  37. var ARCHDIR
  38. var SHORTCUTDIR
  39. var DESKTOPDIR
  40. # Check for administrative rights
  41. !macro VerifyUserIsAdmin
  42. UserInfo::GetAccountType
  43. pop $0
  44. ${If} $0 != "admin"
  45. messageBox mb_iconstop "Administrator rights required!"
  46. setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
  47. quit
  48. ${EndIf}
  49. !macroend
  50. # Create a shared function function for setting environment variables
  51. !macro ENVFUNC un
  52. Function ${un}setenv
  53. SetShellVarContext current
  54. StrCpy $DATADIR "$APPDATA\${APPNAME}"
  55. StrCpy $NODEDATADIR "$APPDATA\Ethereum"
  56. StrCpy $SHORTCUTDIR "$SMPROGRAMS\${APPNAMENOHYPEN}"
  57. StrCpy $DESKTOPDIR "$DESKTOP"
  58. ${If} ${RunningX64}
  59. StrCpy $FILEDIR "$PROGRAMFILES64\${APPNAME}"
  60. StrCpy $ARCHDIR "win-unpacked"
  61. ${Else}
  62. StrCpy $FILEDIR "$PROGRAMFILES32\${APPNAME}"
  63. StrCpy $ARCHDIR "win-ia32-unpacked"
  64. ${Endif}
  65. SetShellVarContext all
  66. FunctionEnd
  67. !macroend
  68. !insertmacro ENVFUNC ""
  69. !insertmacro ENVFUNC "un."
  70. function .onInit
  71. !insertmacro VerifyUserIsAdmin
  72. call setenv
  73. functionEnd
  74. # The license page. Can use .txt or .rtf data
  75. PageEx license
  76. LicenseData ..\LICENSE
  77. PageExEnd
  78. # Components is a good place to allow the user to select optional software to install
  79. # For example, it could be used to allow the user to select which node they want installed and then download it
  80. #Page components
  81. # Select the location to install the main program files
  82. PageEx directory
  83. DirVar $FILEDIR
  84. PageExEnd
  85. ## Select the location for Mist's data directory
  86. #PageEx directory
  87. # DirText "Select a location for Mist's data files (watched contracts, etc.)"
  88. # DirVar $DATADIR
  89. #PageExEnd
  90. # Select the location for the node's data directory
  91. PageEx directory
  92. DirText "Select a location where blockchain data will be stored"
  93. DirVar $NODEDATADIR
  94. PageExEnd
  95. # Installation
  96. Page instfiles
  97. # Uninstaller confirmation page. Useful to remind the user what data (if any) will remain, for example chaindata or keystore
  98. UninstPage uninstConfirm
  99. # Uninstallation section
  100. UninstPage instfiles
  101. # Show details by default
  102. ShowInstDetails show
  103. ShowUninstDetails show
  104. # Mist installer instructions
  105. Section Mist MIST_IDX
  106. StrCpy $switch_overwrite 1
  107. # set the installation directory as the destination for the following actions
  108. SetOutPath $TEMP
  109. # include both architecture zip files
  110. file "..\dist_${TYPE}\release\${APPNAME}-win64-${VERSIONMAJOR}-${VERSIONMINOR}-${VERSIONBUILD}.zip"
  111. file "..\dist_${TYPE}\release\${APPNAME}-win32-${VERSIONMAJOR}-${VERSIONMINOR}-${VERSIONBUILD}.zip"
  112. file "..\dist_${TYPE}\build\icon.ico"
  113. # Extract the zip file from TEMP to the user's selected installation directory
  114. ${If} ${RunningX64}
  115. ZipDLL::extractALL "$TEMP\${APPNAME}-win64-${VERSIONMAJOR}-${VERSIONMINOR}-${VERSIONBUILD}.zip" "$FILEDIR"
  116. StrCpy $ARCHDIR "win-unpacked"
  117. ${Else}
  118. ZipDLL::extractALL "$TEMP\${APPNAME}-win32-${VERSIONMAJOR}-${VERSIONMINOR}-${VERSIONBUILD}.zip" "$FILEDIR"
  119. StrCpy $ARCHDIR "win-ia32-unpacked"
  120. ${Endif}
  121. # Move files out of subfolder
  122. !insertmacro MoveFolder "$FILEDIR\$ARCHDIR" "$FILEDIR" "*.*"
  123. # Copy icon from installer (not included in zip)
  124. !insertmacro MoveFile "$TEMP\icon.ico" "$FILEDIR\logo.ico"
  125. # create the uninstaller
  126. WriteUninstaller "$FILEDIR\uninstall.exe"
  127. # create shortcuts with flags in the start menu programs directory
  128. createDirectory "$SHORTCUTDIR"
  129. createShortCut "$SHORTCUTDIR\${APPNAMENOHYPEN}.lnk" "$FILEDIR\${APPNAMENOHYPEN}.exe" '--node-datadir="$NODEDATADIR"' "$FILEDIR\${APPNAMENOHYPEN}.exe" 0
  130. # create desktop shortcut
  131. createShortCut "$DESKTOPDIR\${APPNAMENOHYPEN}.lnk" "$FILEDIR\${APPNAMENOHYPEN}.exe" '--node-datadir="$NODEDATADIR"' "$FILEDIR\${APPNAMENOHYPEN}.exe" 0
  132. # create a shortcut for the program uninstaller
  133. CreateShortCut "$SHORTCUTDIR\Uninstall.lnk" "$FILEDIR\uninstall.exe"
  134. ## Firewall - add rules
  135. #SimpleFC::AdvAddRule "Geth incoming peers (TCP:30303)" "" 6 1 1 2147483647 1 "$DATADIR\binaries\Geth\unpacked\geth.exe" "" "" "Ethereum" 30303 "" "" ""
  136. #SimpleFC::AdvAddRule "Geth outgoing peers (TCP:30303)" "" 6 2 1 2147483647 1 "$DATADIR\binaries\Geth\unpacked\geth.exe" "" "" "Ethereum" "" 30303 "" ""
  137. #SimpleFC::AdvAddRule "Geth UDP discovery (UDP:30303)" "" 17 2 1 2147483647 1 "$DATADIR\binaries\Geth\unpacked\geth.exe" "" "" "Ethereum" "" 30303 "" ""
  138. # write registry strings for uninstallation
  139. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "DisplayName" "${GROUPNAME} ${APPNAME}"
  140. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "UninstallString" '"$FILEDIR\uninstall.exe"'
  141. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
  142. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "InstallLocation" '"$FILEDIR"'
  143. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "InstallDate" "${NOW}"
  144. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "DisplayIcon" '"$FILEDIR\logo.ico"'
  145. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "Publisher" "${GROUPNAME}"
  146. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "HelpLink" '"${HELPURL}"'
  147. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "URLUpdateInfo" '"${UPDATEURL}"'
  148. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "URLInfoAbout" '"${ABOUTURL}"'
  149. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "DisplayVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
  150. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
  151. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "VersionMinor" ${VERSIONMINOR}
  152. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "NoModify" 1
  153. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "NoRepair" 1
  154. # calculate and store installation size
  155. Call GetInstalledSize
  156. Pop $0
  157. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}" "EstimatedSize" "$0"
  158. # write registry strings for current user options
  159. WriteRegStr HKCU "Software\${GROUPNAME} ${APPNAME}" "DATADIR" "$DATADIR"
  160. WriteRegStr HKCU "Software\${GROUPNAME} ${APPNAME}" "NODEDATADIR" "$NODEDATADIR"
  161. WriteRegStr HKCU "Software\${GROUPNAME} ${APPNAME}" "DESKTOPDIR" "$DESKTOPDIR"
  162. # Clean up temporary files
  163. Delete "$TEMP\${APPNAME}-win32-${VERSIONMAJOR}-${VERSIONMINOR}-${VERSIONBUILD}.zip"
  164. Delete "$TEMP\${APPNAME}-win64-${VERSIONMAJOR}-${VERSIONMINOR}-${VERSIONBUILD}.zip"
  165. SectionEnd
  166. Function .onInstSuccess
  167. ExecShell "open" "$SHORTCUTDIR"
  168. FunctionEnd
  169. function un.onInit
  170. call un.setenv
  171. !insertmacro VerifyUserIsAdmin
  172. functionEnd
  173. # uninstaller section start
  174. Section "uninstall"
  175. # get user settings from registry
  176. ClearErrors
  177. ReadRegStr $0 HKCU "Software\${GROUPNAME} ${APPNAME}" 'DATADIR'
  178. ReadRegStr $1 HKCU "Software\${GROUPNAME} ${APPNAME}" 'NODEDATADIR'
  179. ReadRegStr $2 HKCU "Software\${GROUPNAME} ${APPNAME}" 'DESKTOPDIR'
  180. IfErrors 0 +2
  181. MessageBox MB_ICONEXCLAMATION|MB_OK "Unable to read from the registry. Not all shortcuts will be removed"
  182. StrCpy $DATADIR $0
  183. StrCpy $NODEDATADIR $1
  184. StrCpy $DESKTOPDIR $2
  185. # remove the link from the start menu
  186. rmDir /r "$SHORTCUTDIR"
  187. # remove desktop shortcut
  188. Delete "$DESKTOPDIR\${APPNAME}.lnk"
  189. # remove files from installation directory
  190. rmDir /r /REBOOTOK "$FILEDIR"
  191. ## Firewall - remove rules (if exists)
  192. #SimpleFC::AdvRemoveRule "Geth incoming peers (TCP:30303)"
  193. #SimpleFC::AdvRemoveRule "Geth outgoing peers (TCP:30303)"
  194. #SimpleFC::AdvRemoveRule "Geth UDP discovery (UDP:30303)"
  195. # delete registry strings
  196. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GROUPNAME} ${APPNAME}"
  197. DeleteRegKey HKCU "Software\${GROUPNAME} ${APPNAME}"
  198. SectionEnd
  199. Function un.onUnInstSuccess
  200. MessageBox MB_OK "Opening leftover data directories (backup before deleting!)"
  201. ExecShell "open" "$DATADIR"
  202. ExecShell "open" "$NODEDATADIR"
  203. FunctionEnd
  204. # Return on top of stack the total size (as DWORD) of the selected/installed sections.
  205. Var GetInstalledSize.total
  206. Function GetInstalledSize
  207. StrCpy $GetInstalledSize.total 0
  208. ${if} ${SectionIsSelected} ${MIST_IDX}
  209. ${locate::GetSize} "$FILEDIR" "/S=Kb" $0 $1 $2
  210. # TODO check for return of -1 for error
  211. IntOp $GetInstalledSize.total $GetInstalledSize.total + $0
  212. ${endif}
  213. IntFmt $GetInstalledSize.total "0x%08X" $GetInstalledSize.total
  214. Push $GetInstalledSize.total
  215. FunctionEnd