wails_tools.nsh 8.4 KB

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