-
Notifications
You must be signed in to change notification settings - Fork 248
/
windows_installer.nsi
executable file
·289 lines (211 loc) · 6.5 KB
/
windows_installer.nsi
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
!define NAME "icestudio"
!ifndef VERSION
!define VERSION "dev"
!endif
!ifndef ARCH
!define ARCH "win64"
!endif
!define DIST "..\dist"
!define CACHE "..\cache"
!define APP "${DIST}\icestudio\${ARCH}"
!ifndef PYTHON
!define PYTHON "python-3.12.1-amd64.exe"
!endif
!define PYPATH "${CACHE}\python\${PYTHON}"
!define ICON "${APP}\resources\images\icestudio-logo.ico"
# define name of installer
Name "${NAME} ${VERSION}"
# define output file
OutFile "${DIST}\${NAME}-${VERSION}-${ARCH}.exe"
# request application privileges
RequestExecutionLevel admin
# SetCompressor lzma
!include "x64.nsh"
!include "MUI2.nsh"
!include "FileFunc.nsh"
!include "FileAssociation.nsh"
!define MUI_ICON "${ICON}"
!define MUI_BGCOLOR FFFFFF
# directory page defines
!define MUI_DIRECTORYPAGE_VERIFYONLEAVE
# run after installing
#!define MUI_FINISHPAGE_RUN
#!define MUI_FINISHPAGE_RUN_TEXT "Start ${NAME} ${VERSION}"
#!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
# installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
# uninstaller pages
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_COMPONENTS
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
# languages
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "TradChinese"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "Galician"
!insertmacro MUI_LANGUAGE "Basque"
!insertmacro MUI_LANGUAGE "Catalan"
Function ".onInit"
# check system architecture
${If} ${RunningX64}
${If} "${ARCH}" == "win64"
SetRegView 64
StrCpy $INSTDIR "$PROGRAMFILES64\${NAME}"
${Else}
MessageBox MB_OK|MB_ICONSTOP \
"This installer does not match your current architecture. \
$\n$\nPlease, run the 64-bit installer."
Abort
${EndIf}
${Else}
${If} "${ARCH}" == "win32"
SetRegView 32
StrCpy $INSTDIR "$PROGRAMFILES32\${NAME}"
${Else}
MessageBox MB_OK|MB_ICONSTOP \
"This installer does not match your current architecture. \
$\n$\nPlease, run the 32-bit installer."
Abort
${EndIf}
${EndIf}
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" \
"UninstallString"
StrCmp $R0 "" done
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"${NAME} is already installed.$\n$\nClick `OK` to remove the \
previous version or `Cancel` to cancel this upgrade." \
IDOK uninst
Abort
# run uninstaller
uninst:
ExecWait '$R0 /S'
done:
FunctionEnd
Section "Install Python"
Call ValidatePythonVersion
Pop $R0
${If} $R0 != "0"
MessageBox MB_YESNO \
"Python 3.12.1 will be installed. Do you want to continue?" \
IDYES continue
Quit
continue:
# define output path
SetOutPath "$INSTDIR\python"
# copy Python msi
File ${PYPATH}
# execute Python msi
# now there isn't MSI ExecWait '"msiexec" /i "$INSTDIR\python\${PYTHON}" /passive /norestart ADDLOCAL=ALL'
# https://docs.python.org/3/using/windows.html#customization-via-ini-files
ExecWait '"$INSTDIR\python\${PYTHON}" /passive /norestart PrependPath=1'
${EndIf}
SectionEnd
Function "ValidatePythonVersion"
nsExec::ExecToStack '"python" "-c" "import sys; ver=sys.version_info[:2]; exit({True:0,False:1}[ver==(3,8)])"'
FunctionEnd
Section "${NAME} ${VERSION}"
SetShellVarContext all
# define output path
SetOutPath "$INSTDIR"
# install app files
#File "${APP}\icestudio.exe"
#File "${APP}\icudtl.dat"
#File "${APP}\resources.pak"
#File /r "${APP}\toolchain"
# File "${APP}\index.html"
# File "${APP}\package.json"
# File /r "${APP}\fonts"
# File /r "${APP}\node_modules"
# File /r "${APP}\resources"
# File /r "${APP}\scripts"
# File /r "${APP}\styles"
# File /r "${APP}\views"
File /r "${APP}\"
# define uninstaller name
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "DisplayName" "${NAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "DisplayIcon" "$INSTDIR\icestudio.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "UninstallString" '"$INSTDIR\uninstaller.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" "NoRepair" 1
# write uninstaller
WriteUninstaller "$INSTDIR\uninstaller.exe"
# define shortcut
CreateDirectory "$SMPROGRAMS\${NAME}"
CreateShortCut "$SMPROGRAMS\${NAME}\${NAME}.lnk" "$INSTDIR\icestudio.exe" "" "$INSTDIR\resources\images\icestudio-logo.ico" 0
# register .ice files
${registerExtension} "$INSTDIR\icestudio.exe" ".ice" "Icestudio project"
${RefreshShellIcons}
SectionEnd
Function "LaunchLink"
ReadEnvStr $R0 "PATH"
# SetEnv::SetEnvVar "PATH" $R0
System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PATH", R0).r0'
Exec "$INSTDIR\icestudio.exe"
FunctionEnd
Function "un.onInit"
# check system architecture
${If} ${RunningX64}
SetRegView 64
StrCpy $INSTDIR "$PROGRAMFILES64\${NAME}"
${Else}
SetRegView 32
StrCpy $INSTDIR "$PROGRAMFILES32\${NAME}"
${EndIf}
FunctionEnd
Section "un.Uninstall Icestudio"
SetShellVarContext all
# delete shortcut
Delete "$SMPROGRAMS\${NAME}\${NAME}.lnk"
RMDir "$SMPROGRAMS\${NAME}"
# remove app files
RMDir /r "$INSTDIR"
# delete uninstaller
Delete "$INSTDIR\uninstaller.exe"
RMDir "$INSTDIR"
# remove uninstaller information from the registry
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}"
# unregister .ice files
${unregisterExtension} ".ice" "Icestudio project"
${RefreshShellIcons}
SectionEnd
Function "un.GetIcestudioDir"
${If} ${FileExists} "$PROFILE\.icestudio\*.*"
StrCpy $0 "$PROFILE\.icestudio"
${ElseIf} ${FileExists} "C:\.icestudio\*.*"
StrCpy $0 "C:\.icestudio"
${EndIf}
FunctionEnd
Section /o "un.Remove toolchain"
Call un.GetIcestudioDir
Pop $0
${If} $0 != ""
RMDir /r "$0\.build"
RMDir /r "$0\.cache"
RMDir /r "$0\apio"
RMDir /r "$0\venv"
RMDir "$0"
${EndIf}
SectionEnd
Section /o "un.Remove profile"
Call un.GetIcestudioDir
Pop $0
${If} $0 != ""
Delete "$0\profile.json"
RMDir "$0"
${EndIf}
SectionEnd
Section /o "un.Remove collections"
Call un.GetIcestudioDir
Pop $0
${If} $0 != ""
RMDir /r "$0\collections"
RMDir "$0"
${EndIf}
SectionEnd