forked from hyperspy/hyperspyUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_bundle.nsi
436 lines (384 loc) · 11.6 KB
/
win_bundle.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "HyperSpyUI Bundle"
!define PRODUCT_PUBLISHER "HyperSpyUI"
!define PRODUCT_VERSION "0.7+dev"
!define WHEEL "hyperspyUI-${PRODUCT_VERSION}-py3-none-any.whl"
SetCompressor lzma
SetCompress off
;!include "UserManagement.nsh"
; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "Sections.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Driectory page
!insertmacro MUI_PAGE_DIRECTORY
; Components page
!insertmacro MUI_PAGE_COMPONENTS
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Language files
!insertmacro MUI_LANGUAGE "English"
; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; Architecture
!include x64.nsh
!ifdef CL64
!define BUNDLE "hspy_bundle64bit.exe"
!else
!define BUNDLE "hspy_bundle32bit.exe"
!endif
!define LVM_GETITEMCOUNT 0x1004
!define LVM_GETITEMTEXT 0x102D
!include 'LogicLib.nsh'
!include 'FileFunc.nsh'
!insertmacro Locate
Var /GLOBAL switch_overwrite
!include 'MoveFileFolder.nsh'
; ----------------------- Macro definitions ----------------------------------
!define AllFileTypes ""
!macro FileTypeSectionOn Name
Section '${Name}'
SectionIn 1 2 3
SectionEnd
!define TmpStore "${AllFileTypes} ${Name}"
!undef AllFileTypes
!define AllFileTypes "${TmpStore}"
!undef TmpStore
!macroend
!macro FileTypeSectionOff Name
Section '${Name}'
SectionIn 2
SectionEnd
!define TmpStore "${AllFileTypes} ${Name}"
!undef AllFileTypes
!define AllFileTypes "${TmpStore}"
!undef TmpStore
!macroend
; --------------------- Function definitions --------------------------------
Function DumpLog
Exch $5
Push $0
Push $1
Push $2
Push $3
Push $4
Push $6
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1016
StrCmp $0 0 exit
FileOpen $5 $5 "w"
StrCmp $5 "" exit
SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
System::Alloc ${NSIS_MAX_STRLEN}
Pop $3
StrCpy $2 0
System::Call "*(i, i, i, i, i, i, i, i, i) i \
(0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
FileWrite $5 "$\r$\n$\r$\n------- Begin detail view dump ----------$\r$\n"
loop: StrCmp $2 $6 done
System::Call "User32::SendMessageA(i, i, i, i) i \
($0, ${LVM_GETITEMTEXT}, $2, r1)"
System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
FileWrite $5 "$4$\r$\n"
IntOp $2 $2 + 1
Goto loop
done:
FileClose $5
System::Free $1
System::Free $3
exit:
Pop $6
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
Exch $5
FunctionEnd
!macro DumpLog LogFile
Push `${LogFile}`
Call DumpLog
!macroend
!define DumpLog "!insertmacro DumpLog"
Function DosLog
Exch $R0 ; Incoming command
ExecDos::exec /DETAILED $R0 "" ""
Pop $R0
FunctionEnd
!macro DosLog Cmd
Push `${Cmd}`
Call DosLog
!macroend
!define DosLog "!insertmacro DosLog"
Function ConsumeWord
Exch $R0 ; R0 has WordList (input)
Push $R1 ; Inspection character
Push $R2 ; Inspected position
Push $R3 ; WordList length
Push $R4 ; Word length
StrLen $R3 $R0
${If} $R3 > 1
;Start counter (word boundary position)
StrCpy $R2 1 ; Skip leading space
${Do}
StrCpy $R1 $R0 1 $R2
; Is current char space, ie. word boundary?
${IfThen} $R1 == ' ' ${|} ${ExitDo} ${|}
; Is current char last?
${IfThen} $R2 >= $R3 ${|} ${ExitDo} ${|}
IntOp $R2 $R2 + 1
${Loop}
; Let R0 store new WordList, and R1 store new word
IntOp $R4 $R2 - 1
StrCpy $R1 $R0 $R4 1
StrCpy $R0 $R0 `` $R2 ; Leave space behind
${Else}
StrCpy $R1 ""
StrCpy $R0 ""
${EndIf}
Pop $R4
Pop $R3
Pop $R2
Exch $R1
Exch
Exch $R0
FunctionEnd
!macro ConsumeWord Word WordList
Push `${WordList}`
Call ConsumeWord
Pop `${WordList}`
Pop `${Word}`
!macroend
!define ConsumeWord "!insertmacro ConsumeWord"
Function GetSelectedFileTypes
Exch $R0 ; WordList - input, output
Push $R1 ; Current word
Push $R2 ; Selected words - output
Push $R3 ; Section index
Push $R4 ; Section name
StrCpy $R3 0
StrCpy $R2 ""
StrCpy $R4 "something random"
ClearErrors
loop:
${ConsumeWord} $R1 $R0 ; Strip of first word into R1
StrCmp $R1 "" loop_end ; Empty word signifies complete
${Do}
SectionGetText $R3 $R4
IfErrors 0 +2
Goto loop_end
${If} $R3 == ''
${ElseIf} $R4 == $R1
${ExitDo}
${EndIf}
IntOp $R3 $R3 + 1
${Loop}
${If} ${SectionIsSelected} $R3 ; Is Section selected?
StrCpy $R2 "$R2 $R1" ; Yes, copy to list
${EndIf}
IntOp $R3 $R3 + 1
Goto loop
loop_end:
Pop $R4
Pop $R3
Exch 2
Pop $R0
Pop $R1
Exch $R2
FunctionEnd
!macro GetSelectedFileTypes WordList SelectedList
Push `${WordList}`
Call GetSelectedFileTypes
Pop `${SelectedList}`
!macroend
!define GetSelectedFileTypes "!insertmacro GetSelectedFileTypes"
Function GetPythonDir
Push $R1
Push $R0
FindFirst $R0 $R1 "$INSTDIR\python*"
loop:
StrCmp $R1 "" done
IfFileExists "$INSTDIR\$R1\*.*" done
FindNext $R0 $R1
Goto loop
done:
StrCpy $R1 "$INSTDIR\$R1"
FindClose $R0
FindClose $R0
Pop $R0
Exch $R1
FunctionEnd
!macro GetPythonDir PythonDir
Call GetPythonDir
Pop `${PythonDir}`
!macroend
!define GetPythonDir "!insertmacro GetPythonDir"
Function InstallInProgramFiles
Push $R0
Push $R1
StrLen $R1 $PROGRAMFILES64
StrCpy $R0 $InstDir $R1
StrCmp $R0 $PROGRAMFILES64 yes
StrLen $R1 $PROGRAMFILES32
StrCpy $R0 $InstDir $R1
StrCmp $R0 $PROGRAMFILES32 yes no
yes:
StrCpy $R0 1
Goto return
no:
StrCpy $R0 0
return:
Pop $R1
Exch $R0
FunctionEnd
!macro InstallInProgramFiles ReturnValue
Call InstallInProgramFiles
Pop `${ReturnValue}`
!macroend
!define InstallInProgramFiles "!insertmacro InstallInProgramFiles"
; ---------------------------- Start installer --------------------------------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
!ifdef CL64
OutFile "HyperSpyUI-${PRODUCT_VERSION}-Bundle-64bit.exe"
InstallDir "$PROGRAMFILES64\HyperSpyUI"
!else
OutFile "HyperSpyUI-${PRODUCT_VERSION}-Bundle-32bit.exe"
InstallDir "$PROGRAMFILES32\HyperSpyUI"
!endif
ShowInstDetails show
InstType "Default"
InstType "Full"
InstType "HyperspyUI only"
InstType "No OS intergation"
;Section -SETTINGS
; SetOutPath "$INSTDIR"
; SetOverwrite ifnewer
;SectionEnd
DirText "Choose the directory to install HyperSpyUI to."
Section "Python"
SectionIn 1 4
SetOutPath $TEMP
File ".\bundle_prerequisites\${BUNDLE}"
SetOutPath "$INSTDIR"
DetailPrint "Installing python. This might take a while..."
ExecWait "$TEMP\${BUNDLE} /S /D=$INSTDIR"
Delete "$TEMP\${BUNDLE}"
; If we install in Program files, prevent settings from being stored
; locally, as that will require admin rights to run scripts!
Push $R0
${InstallInProgramFiles} $R0
${If} $R0 == 1
StrCpy $switch_overwrite 2 ; Don't overwrite anything
!insertmacro MoveFolder "$INSTDIR\settings" "$PROFILE" *
RMDir /r "$INSTDIR\settings\.ipython"
RMDir /r "$INSTDIR\settings\.jupyter"
RMDir /r "$INSTDIR\settings\.matplotlib"
RMDir /r "$INSTDIR\settings\.hyperspy"
RMDir /r "$INSTDIR\settings\nbextensions"
RMDir /r "$INSTDIR\settings\runtime"
RMDir /r "$INSTDIR\settings\seaborn-data"
Delete "$INSTDIR\settings\winpython.ini"
Delete "$INSTDIR\settings\pydistutils.cfg"
RMDir "$INSTDIR\settings"
${EndIf}
Pop $R0
; Installer is precompressed, so we need to add roughly a Gig of space
AddSize 1000000
SectionEnd
Section "Register python"
SectionIn 1
; TODO: Check whether to reg for all
SetOutPath "$INSTDIR\scripts"
${DosLog} "$INSTDIR\scripts\register_python.bat"
DetailPrint "Checking the list twice."
${DosLog} "$INSTDIR\scripts\register_python.bat"
SectionEnd
Section "HyperSpyUI"
SectionIn 1 2 3 4 RO
SetOutPath $TEMP
File ".\dist\${WHEEL}"
File ".\bin\win_bundle_install.bat"
; If you want to include binary wheels for prerequisites, or just to enable
; offline innstallation, uncomment these lines (and delete line below)
; and add the wheels to the .\bundle_prerequisites\wheels\ folder:
SetOutPath "$TEMP\wheels"
File ".\bundle_prerequisites\wheels\*.whl"
SetOutPath $INSTDIR
${DosLog} '$TEMP\win_bundle_install.bat "$INSTDIR\scripts\env.bat" easy_install --upgrade pip'
${DosLog} '$TEMP\win_bundle_install.bat "$INSTDIR\scripts\env.bat" pip install --no-deps --compile -U "$TEMP\${WHEEL}"'
${DosLog} '$TEMP\win_bundle_install.bat "$INSTDIR\scripts\env.bat" pip install --use-wheel --find-links="$TEMP\wheels" --compile "$TEMP\${WHEEL}"'
Delete "$TEMP\${WHEEL}"
Delete "$TEMP\wheels\*.whl"
Delete "$TEMP\win_bundle_install.bat"
Push $R0
${GetPythonDir} $R0
CreateShortCut "$INSTDIR\${PRODUCT_NAME}.lnk" "$R0\python.exe" "-m hyperspyui"
Pop $R0
SectionEnd
SectionGroup /e "Register HyperSpyUI"
Section "Create shortcuts"
SectionIn 1 2 3
SetOutPath $INSTDIR
Push $R0
${GetPythonDir} $R0
SetOutPath "$R0"
${DosLog} '"$R0\python.exe" "$R0\Scripts\hyperspyui_install.py" -filetypes'
Pop $R0
SectionEnd
SectionGroup "Register filetypes"
SectionGroup 'DigitalMicrograph filetypes'
!insertmacro FileTypeSectionOff 'dm3'
!insertmacro FileTypeSectionOff 'dm4'
SectionGroupEnd
SectionGroup 'FEI filetypes'
!insertmacro FileTypeSectionOff 'emi'
!insertmacro FileTypeSectionOff 'ser'
SectionGroupEnd
SectionGroup 'HDF filetypes'
!insertmacro FileTypeSectionOn 'hdf'
!insertmacro FileTypeSectionOn 'hdf4'
!insertmacro FileTypeSectionOn 'hdf5'
!insertmacro FileTypeSectionOn 'h4'
!insertmacro FileTypeSectionOn 'h5'
!insertmacro FileTypeSectionOn 'he4'
!insertmacro FileTypeSectionOn 'he5'
SectionGroupEnd
SectionGroup 'MSA filetypes'
!insertmacro FileTypeSectionOn 'mas'
!insertmacro FileTypeSectionOn 'msa'
!insertmacro FileTypeSectionOn 'ems'
!insertmacro FileTypeSectionOn 'emsa'
SectionGroupEnd
SectionGroup 'Other'
!insertmacro FileTypeSectionOn 'ali'
!insertmacro FileTypeSectionOn 'mrc'
!insertmacro FileTypeSectionOn 'blo'
!insertmacro FileTypeSectionOn 'dens'
!insertmacro FileTypeSectionOn 'nc'
!insertmacro FileTypeSectionOn 'rpl'
!insertmacro FileTypeSectionOn 'unf'
SectionGroupEnd
Section -HiddenWorker
SectionIn 1 2 3
SetOutPath $INSTDIR
; Which file types are selected?
Push $R0
${GetSelectedFileTypes} "${AllFileTypes}" $R0
DetailPrint $R0
Push $R1
${GetPythonDir} $R1
SetOutPath "$R1"
${DosLog} '"$R1\python.exe" "$R1\Scripts\hyperspyui_install.py" -no-shortcuts -filetypes $R0'
Pop $R0
Pop $R1
${DumpLog} "$INSTDIR\install.log"
SectionEnd
SectionGroupEnd
SectionGroupEnd