github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/pkg/buildassets/build/windows/installer/wails_tools.nsh (about)

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