-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathinstaller.nsh
227 lines (200 loc) · 7.91 KB
/
installer.nsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# functions (nsis macro) for installer
!include "extractAppPackage.nsh"
!ifdef APP_PACKAGE_URL
!include webPackage.nsh
!endif
!macro installApplicationFiles
!ifdef APP_BUILD_DIR
File /r "${APP_BUILD_DIR}\*.*"
!else
!ifdef APP_PACKAGE_URL
Var /GLOBAL packageFile
Var /GLOBAL isPackageFileExplicitlySpecified
${StdUtils.GetParameter} $packageFile "package-file" ""
${if} $packageFile == ""
!ifdef APP_64_NAME
!ifdef APP_32_NAME
!ifdef APP_ARM64_NAME
${if} ${IsNativeARM64}
StrCpy $packageFile "${APP_ARM64_NAME}"
StrCpy $1 "${APP_ARM64_HASH}"
${elseif} ${IsNativeAMD64}
StrCpy $packageFile "${APP_64_NAME}"
StrCpy $1 "${APP_64_HASH}"
${else}
StrCpy $packageFile "${APP_32_NAME}"
StrCpy $1 "${APP_32_HASH}"
${endif}
!else
${if} ${RunningX64}
StrCpy $packageFile "${APP_64_NAME}"
StrCpy $1 "${APP_64_HASH}"
${else}
StrCpy $packageFile "${APP_32_NAME}"
StrCpy $1 "${APP_32_HASH}"
${endif}
!endif
!else
StrCpy $packageFile "${APP_64_NAME}"
StrCpy $1 "${APP_64_HASH}"
!endif
!else
StrCpy $packageFile "${APP_32_NAME}"
StrCpy $1 "${APP_32_HASH}"
!endif
StrCpy $4 "$packageFile"
StrCpy $packageFile "$EXEDIR/$packageFile"
StrCpy $isPackageFileExplicitlySpecified "false"
${else}
StrCpy $isPackageFileExplicitlySpecified "true"
${endIf}
# we do not check file hash is specifed explicitly using --package-file because it is clear that user definitely want to use this file and it is user responsibility to check
# 1. auto-updater uses --package-file and validates checksum
# 2. user can user another package file (use case - one installer suitable for any app version (use latest version))
${if} ${FileExists} "$packageFile"
${if} $isPackageFileExplicitlySpecified == "true"
Goto fun_extract
${else}
${StdUtils.HashFile} $3 "SHA2-512" "$packageFile"
${if} $3 == $1
Goto fun_extract
${else}
MessageBox MB_OK "Package file $4 found locally, but checksum doesn't match — expected $1, actual $3.$\r$\nLocal file is ignored and package will be downloaded from Internet."
${endIf}
${endIf}
${endIf}
!insertmacro downloadApplicationFiles
fun_extract:
!insertmacro extractUsing7za "$packageFile"
# electron always uses per user app data
${if} $installMode == "all"
SetShellVarContext current
${endif}
!insertmacro moveFile "$packageFile" "$LOCALAPPDATA\${APP_PACKAGE_STORE_FILE}"
${if} $installMode == "all"
SetShellVarContext all
${endif}
!else
!insertmacro extractEmbeddedAppPackage
# electron always uses per user app data
${if} $installMode == "all"
SetShellVarContext current
${endif}
!insertmacro copyFile "$EXEPATH" "$LOCALAPPDATA\${APP_INSTALLER_STORE_FILE}"
${if} $installMode == "all"
SetShellVarContext all
${endif}
!endif
!endif
File "/oname=${UNINSTALL_FILENAME}" "${UNINSTALLER_OUT_FILE}"
!macroend
!macro registryAddInstallInfo
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" InstallLocation "$INSTDIR"
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" KeepShortcuts "true"
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" ShortcutName "${SHORTCUT_NAME}"
!ifdef MENU_FILENAME
WriteRegStr SHELL_CONTEXT "${INSTALL_REGISTRY_KEY}" MenuDirectory "${MENU_FILENAME}"
!endif
${if} $installMode == "all"
StrCpy $0 "/allusers"
StrCpy $1 ""
${else}
StrCpy $0 "/currentuser"
StrCpy $1 ""
${endIf}
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" DisplayName "${UNINSTALL_DISPLAY_NAME}$1"
# https://github.com/electron-userland/electron-builder/issues/750
StrCpy $2 "$INSTDIR\${UNINSTALL_FILENAME}"
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" UninstallString '"$2" $0'
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" QuietUninstallString '"$2" $0 /S'
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayVersion" "${VERSION}"
!ifdef UNINSTALLER_ICON
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$INSTDIR\uninstallerIcon.ico"
!else
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "DisplayIcon" "$appExe,0"
!endif
!ifdef COMPANY_NAME
WriteRegStr SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "Publisher" "${COMPANY_NAME}"
!endif
WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" NoModify 1
WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" NoRepair 1
# allow user to define ESTIMATED_SIZE to avoid GetSize call
!ifdef ESTIMATED_SIZE
IntFmt $0 "0x%08X" ${ESTIMATED_SIZE}
!else
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
!endif
WriteRegDWORD SHELL_CONTEXT "${UNINSTALL_REGISTRY_KEY}" "EstimatedSize" "$0"
!macroend
!macro cleanupOldMenuDirectory
${if} $oldMenuDirectory != ""
!ifdef MENU_FILENAME
${if} $oldMenuDirectory != "${MENU_FILENAME}"
RMDir "$SMPROGRAMS\$oldMenuDirectory"
${endIf}
!else
RMDir "$SMPROGRAMS\$oldMenuDirectory"
!endif
${endIf}
!macroend
!macro createMenuDirectory
!ifdef MENU_FILENAME
CreateDirectory "$SMPROGRAMS\${MENU_FILENAME}"
ClearErrors
!endif
!macroend
!macro addStartMenuLink keepShortcuts
!ifndef DO_NOT_CREATE_START_MENU_SHORTCUT
# The keepShortcuts mechanism is NOT enabled.
# Menu shortcut will be recreated.
${if} $keepShortcuts == "false"
!insertmacro cleanupOldMenuDirectory
!insertmacro createMenuDirectory
CreateShortCut "$newStartMenuLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
# clear error (if shortcut already exists)
ClearErrors
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
# The keepShortcuts mechanism IS enabled.
# The menu shortcut could either not exist (it shouldn't be recreated) or exist in an obsolete location.
${elseif} $oldStartMenuLink != $newStartMenuLink
${andIf} ${FileExists} "$oldStartMenuLink"
!insertmacro createMenuDirectory
Rename $oldStartMenuLink $newStartMenuLink
WinShell::UninstShortcut "$oldStartMenuLink"
WinShell::SetLnkAUMI "$newStartMenuLink" "${APP_ID}"
!insertmacro cleanupOldMenuDirectory
${endIf}
!endif
!macroend
!macro addDesktopLink keepShortcuts
!ifndef DO_NOT_CREATE_DESKTOP_SHORTCUT
# https://github.com/electron-userland/electron-builder/pull/1432
${ifNot} ${isNoDesktopShortcut}
# The keepShortcuts mechanism is NOT enabled.
# Shortcuts will be recreated.
${if} $keepShortcuts == "false"
CreateShortCut "$newDesktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
# The keepShortcuts mechanism IS enabled.
# The desktop shortcut could exist in an obsolete location (due to name change).
${elseif} $oldDesktopLink != $newDesktopLink
${andIf} ${FileExists} "$oldDesktopLink"
Rename $oldDesktopLink $newDesktopLink
WinShell::UninstShortcut "$oldDesktopLink"
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
!ifdef RECREATE_DESKTOP_SHORTCUT
${elseif} $oldDesktopLink != $newDesktopLink
${orIfNot} ${FileExists} "$oldDesktopLink"
${ifNot} ${isUpdated}
CreateShortCut "$newDesktopLink" "$appExe" "" "$appExe" 0 "" "" "${APP_DESCRIPTION}"
ClearErrors
WinShell::SetLnkAUMI "$newDesktopLink" "${APP_ID}"
${endIf}
!endif
${endIf}
System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
${endIf}
!endif
!macroend