wails_tools.nsh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # DO NOT EDIT - Generated automatically by `wails build`
  2. !include "x64.nsh"
  3. !include "WinVer.nsh"
  4. !include "FileFunc.nsh"
  5. !ifndef INFO_PROJECTNAME
  6. !define INFO_PROJECTNAME "{{.Name}}"
  7. !endif
  8. !ifndef INFO_COMPANYNAME
  9. !define INFO_COMPANYNAME "{{.Info.CompanyName}}"
  10. !endif
  11. !ifndef INFO_PRODUCTNAME
  12. !define INFO_PRODUCTNAME "{{.Info.ProductName}}"
  13. !endif
  14. !ifndef INFO_PRODUCTVERSION
  15. !define INFO_PRODUCTVERSION "{{.Info.ProductVersion}}"
  16. !endif
  17. !ifndef INFO_COPYRIGHT
  18. !define INFO_COPYRIGHT "{{.Info.Copyright}}"
  19. !endif
  20. !ifndef PRODUCT_EXECUTABLE
  21. !define PRODUCT_EXECUTABLE "${INFO_PROJECTNAME}.exe"
  22. !endif
  23. !ifndef UNINST_KEY_NAME
  24. !define UNINST_KEY_NAME "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
  25. !endif
  26. !define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINST_KEY_NAME}"
  27. !ifndef REQUEST_EXECUTION_LEVEL
  28. !define REQUEST_EXECUTION_LEVEL "admin"
  29. !endif
  30. RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"
  31. !ifdef ARG_WAILS_AMD64_BINARY
  32. !define SUPPORTS_AMD64
  33. !endif
  34. !ifdef ARG_WAILS_ARM64_BINARY
  35. !define SUPPORTS_ARM64
  36. !endif
  37. !ifdef SUPPORTS_AMD64
  38. !ifdef SUPPORTS_ARM64
  39. !define ARCH "amd64_arm64"
  40. !else
  41. !define ARCH "amd64"
  42. !endif
  43. !else
  44. !ifdef SUPPORTS_ARM64
  45. !define ARCH "arm64"
  46. !else
  47. !error "Wails: Undefined ARCH, please provide at least one of ARG_WAILS_AMD64_BINARY or ARG_WAILS_ARM64_BINARY"
  48. !endif
  49. !endif
  50. !macro wails.checkArchitecture
  51. !ifndef WAILS_WIN10_REQUIRED
  52. !define WAILS_WIN10_REQUIRED "This product is only supported on Windows 10 (Server 2016) and later."
  53. !endif
  54. !ifndef WAILS_ARCHITECTURE_NOT_SUPPORTED
  55. !define WAILS_ARCHITECTURE_NOT_SUPPORTED "This product can't be installed on the current Windows architecture. Supports: ${ARCH}"
  56. !endif
  57. ${If} ${AtLeastWin10}
  58. !ifdef SUPPORTS_AMD64
  59. ${if} ${IsNativeAMD64}
  60. Goto ok
  61. ${EndIf}
  62. !endif
  63. !ifdef SUPPORTS_ARM64
  64. ${if} ${IsNativeARM64}
  65. Goto ok
  66. ${EndIf}
  67. !endif
  68. IfSilent silentArch notSilentArch
  69. silentArch:
  70. SetErrorLevel 65
  71. Abort
  72. notSilentArch:
  73. MessageBox MB_OK "${WAILS_ARCHITECTURE_NOT_SUPPORTED}"
  74. Quit
  75. ${else}
  76. IfSilent silentWin notSilentWin
  77. silentWin:
  78. SetErrorLevel 64
  79. Abort
  80. notSilentWin:
  81. MessageBox MB_OK "${WAILS_WIN10_REQUIRED}"
  82. Quit
  83. ${EndIf}
  84. ok:
  85. !macroend
  86. !macro wails.files
  87. !ifdef SUPPORTS_AMD64
  88. ${if} ${IsNativeAMD64}
  89. File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_AMD64_BINARY}"
  90. ${EndIf}
  91. !endif
  92. !ifdef SUPPORTS_ARM64
  93. ${if} ${IsNativeARM64}
  94. File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_ARM64_BINARY}"
  95. ${EndIf}
  96. !endif
  97. !macroend
  98. !macro wails.writeUninstaller
  99. WriteUninstaller "$INSTDIR\uninstall.exe"
  100. SetRegView 64
  101. WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "${INFO_COMPANYNAME}"
  102. WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "${INFO_PRODUCTNAME}"
  103. WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${INFO_PRODUCTVERSION}"
  104. WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PRODUCT_EXECUTABLE}"
  105. WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
  106. WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
  107. ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
  108. IntFmt $0 "0x%08X" $0
  109. WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" "$0"
  110. !macroend
  111. !macro wails.deleteUninstaller
  112. Delete "$INSTDIR\uninstall.exe"
  113. SetRegView 64
  114. DeleteRegKey HKLM "${UNINST_KEY}"
  115. !macroend
  116. !macro wails.setShellContext
  117. ${If} ${REQUEST_EXECUTION_LEVEL} == "admin"
  118. SetShellVarContext all
  119. ${else}
  120. SetShellVarContext current
  121. ${EndIf}
  122. !macroend
  123. # Install webview2 by launching the bootstrapper
  124. # See https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#online-only-deployment
  125. !macro wails.webview2runtime
  126. !ifndef WAILS_INSTALL_WEBVIEW_DETAILPRINT
  127. !define WAILS_INSTALL_WEBVIEW_DETAILPRINT "Installing: WebView2 Runtime"
  128. !endif
  129. SetRegView 64
  130. # If the admin key exists and is not empty then webview2 is already installed
  131. ReadRegStr $0 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
  132. ${If} $0 != ""
  133. Goto ok
  134. ${EndIf}
  135. ${If} ${REQUEST_EXECUTION_LEVEL} == "user"
  136. # If the installer is run in user level, check the user specific key exists and is not empty then webview2 is already installed
  137. ReadRegStr $0 HKCU "Software\Microsoft\EdgeUpdate\Clients{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
  138. ${If} $0 != ""
  139. Goto ok
  140. ${EndIf}
  141. ${EndIf}
  142. SetDetailsPrint both
  143. DetailPrint "${WAILS_INSTALL_WEBVIEW_DETAILPRINT}"
  144. SetDetailsPrint listonly
  145. InitPluginsDir
  146. CreateDirectory "$pluginsdir\webview2bootstrapper"
  147. SetOutPath "$pluginsdir\webview2bootstrapper"
  148. File "tmp\MicrosoftEdgeWebview2Setup.exe"
  149. ExecWait '"$pluginsdir\webview2bootstrapper\MicrosoftEdgeWebview2Setup.exe" /silent /install'
  150. SetDetailsPrint both
  151. ok:
  152. !macroend
  153. # Copy of APP_ASSOCIATE and APP_UNASSOCIATE macros from here https://gist.github.com/nikku/281d0ef126dbc215dd58bfd5b3a5cd5b
  154. !macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
  155. ; Backup the previously associated file class
  156. ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" ""
  157. WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "${FILECLASS}_backup" "$R0"
  158. WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "${FILECLASS}"
  159. WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}" "" `${DESCRIPTION}`
  160. WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\DefaultIcon" "" `${ICON}`
  161. WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell" "" "open"
  162. WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open" "" `${COMMANDTEXT}`
  163. WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open\command" "" `${COMMAND}`
  164. !macroend
  165. !macro APP_UNASSOCIATE EXT FILECLASS
  166. ; Backup the previously associated file class
  167. ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" `${FILECLASS}_backup`
  168. WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "$R0"
  169. DeleteRegKey SHELL_CONTEXT `Software\Classes\${FILECLASS}`
  170. !macroend
  171. !macro wails.associateFiles
  172. ; Create file associations
  173. {{range .Info.FileAssociations}}
  174. !insertmacro APP_ASSOCIATE "{{.Ext}}" "{{.Name}}" "{{.Description}}" "$INSTDIR\{{.IconName}}.ico" "Open with ${INFO_PRODUCTNAME}" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""
  175. File "..\{{.IconName}}.ico"
  176. {{end}}
  177. !macroend
  178. !macro wails.unassociateFiles
  179. ; Delete app associations
  180. {{range .Info.FileAssociations}}
  181. !insertmacro APP_UNASSOCIATE "{{.Ext}}" "{{.Name}}"
  182. Delete "$INSTDIR\{{.IconName}}.ico"
  183. {{end}}
  184. !macroend
  185. !macro CUSTOM_PROTOCOL_ASSOCIATE PROTOCOL DESCRIPTION ICON COMMAND
  186. DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
  187. WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "" "${DESCRIPTION}"
  188. WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "URL Protocol" ""
  189. WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\DefaultIcon" "" "${ICON}"
  190. WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell" "" ""
  191. WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open" "" ""
  192. WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open\command" "" "${COMMAND}"
  193. !macroend
  194. !macro CUSTOM_PROTOCOL_UNASSOCIATE PROTOCOL
  195. DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
  196. !macroend
  197. !macro wails.associateCustomProtocols
  198. ; Create custom protocols associations
  199. {{range .Info.Protocols}}
  200. !insertmacro CUSTOM_PROTOCOL_ASSOCIATE "{{.Scheme}}" "{{.Description}}" "$INSTDIR\${PRODUCT_EXECUTABLE},0" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""
  201. {{end}}
  202. !macroend
  203. !macro wails.unassociateCustomProtocols
  204. ; Delete app custom protocol associations
  205. {{range .Info.Protocols}}
  206. !insertmacro CUSTOM_PROTOCOL_UNASSOCIATE "{{.Scheme}}"
  207. {{end}}
  208. !macroend