-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopenSUSE_installer.nsi
1638 lines (1417 loc) · 55.3 KB
/
openSUSE_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
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; openSUSE installer instlux-ng NSIS script
; -----------------------------------------------------------------------------
Unicode false
!include "MUI.nsh"
!include "x64.nsh"
!include "LogicLib.nsh"
!include "WinVer.nsh"
; -----------------------------------------------------------------------------
; variables
Var hwnd
Var systemDrive
Var distribution
Var architecture
Var environment
Var bcdedit
Var bcdStore
Var instsource
Var mediaVer
Var mediaI386
Var mediaX86_64
Var dirVirt
Var dirVM
Var nameVM
Var memoryVM
Var diskVM
Var switchVM
Var buildNum
; -----------------------------------------------------------------------------
; definitions
!define DISTSELECT_INI "$PLUGINSDIR\DistributionSelection.ini"
!define VIRTSET_INI "$PLUGINSDIR\VirtualMachineSettings.ini"
; -----------------------------------------------------------------------------
; General settings
Name "openSUSE installer"
Caption "openSUSE installer"
BrandingText "openSUSE installer / NSIS version ${NSIS_VERSION}"
OutFile "openSUSE_installer.exe"
ShowInstDetails "nevershow"
ShowUninstDetails "nevershow"
AllowRootDirInstall true
InstallDir "C:\openSUSE"
XPStyle on
SetCompressor /SOLID lzma
!define MUI_ICON "opensuse.ico"
!define MUI_UNICON "opensuse.ico"
!define MUI_WELCOMEPAGE_TITLE_3LINES
!define MUI_FINISHPAGE_TITLE_3LINES
; -----------------------------------------------------------------------------
; pages
!insertmacro MUI_PAGE_WELCOME
Page custom "ShowDistributionSelection" "LeaveDistributionSelection"
Page custom "ShowVirtualMachineSettings" "LeaveVirtualMachineSettings"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
; -----------------------------------------------------------------------------
; languages and translation macros
; see: http://nsis.sourceforge.net/Creating_language_files_and_integrating_with_MUI
!macro LANG_LOAD LANGLOAD
!insertmacro MUI_LANGUAGE "${LANGLOAD}"
!verbose 1
!include "lang\${LANGLOAD}.nsh"
!verbose 4
# BrandingText "$(STRING_BRANDING)" ; example usage
!undef LANG
!macroend
!macro LANG_STRING NAME VALUE
LangString "${NAME}" "${LANG_${LANG}}" "${VALUE}"
!macroend
!macro LANG_UNSTRING NAME VALUE
!insertmacro LANG_STRING "un.${NAME}" "${VALUE}"
!macroend
; first language is the default language
!insertmacro LANG_LOAD "English"
!insertmacro LANG_LOAD "French"
!insertmacro LANG_LOAD "German"
!insertmacro LANG_LOAD "Spanish"
!insertmacro LANG_LOAD "SpanishInternational"
!insertmacro LANG_LOAD "SimpChinese"
!insertmacro LANG_LOAD "TradChinese"
!insertmacro LANG_LOAD "Japanese"
!insertmacro LANG_LOAD "Korean"
!insertmacro LANG_LOAD "Lithuanian"
!insertmacro LANG_LOAD "Italian"
!insertmacro LANG_LOAD "Dutch"
!insertmacro LANG_LOAD "Danish"
!insertmacro LANG_LOAD "Swedish"
!insertmacro LANG_LOAD "Norwegian"
!insertmacro LANG_LOAD "NorwegianNynorsk"
!insertmacro LANG_LOAD "Finnish"
!insertmacro LANG_LOAD "Greek"
!insertmacro LANG_LOAD "Russian"
!insertmacro LANG_LOAD "Portuguese"
!insertmacro LANG_LOAD "PortugueseBR"
!insertmacro LANG_LOAD "Polish"
; -----------------------------------------------------------------------------
; get system memory function
Function "GetSystemMemoryInfo"
; check RAM (see http://nsis.sourceforge.net/Docs/System/System.html)
System::Call "*(i 64,i,l,l,l,l,l,l,l)p.r1"
System::Call "Kernel32::GlobalMemoryStatusEx(p r1)"
System::Call "*$1(i.r2, i.r3, l.r4)"
System::Free $1
System::Int64Op $4 >> 20 ; (to [MB])
Pop $4
StrCpy $R0 1
${If} $4 L< $R0
; if no memory is detected, try again with "GlobalMemoryStatus"
System::Call "*(i,i,p,p,p,p,p,p)p.r1"
System::Call "Kernel32::GlobalMemoryStatus(p r1)"
System::Call "*$1(i.r2, i.r3, p.r4)"
System::Free $1
IntOp $4 $4 >> 20 ; (to [MB])
${EndIf}
FunctionEnd ; "GetSystemMemoryInfo"
; -----------------------------------------------------------------------------
; run PowerShell script
!macro RunPowerShellCmdOptions Show CommandLine
!define execID ${__LINE__}
InitPluginsDir
Push $R1
FileOpen $R1 "$PLUGINSDIR\runpowershell.ps1" w
FileWrite $R1 "${CommandLine}"
FileClose $R1
Pop $R1
Push $R0
${If} ${Show} == 0
Banner::show /set 76 $(STRING_BANNER_WAITINGTITLE) $(STRING_BANNER_WAITING_TEXT)
; if running in X64, powershell(X64) is in $WINDIR\Sysnative.
${If} ${RunningX64}
nsExec::ExecToStack "$\"$WINDIR\Sysnative\WindowsPowerShell\v1.0\PowerShell.exe$\" -InputFormat none -ExecutionPolicy RemoteSigned -File $\"$PLUGINSDIR\runpowershell.ps1$\""
${Else}
nsExec::ExecToStack "$\"$SYSDIR\WindowsPowerShell\v1.0\PowerShell.exe$\" -InputFormat none -ExecutionPolicy RemoteSigned -File $\"$PLUGINSDIR\runpowershell.ps1$\""
${EndIf}
Banner::destroy
Pop $R0 ; return value
${Else}
Banner::show /set 76 $(STRING_BANNER_WAITINGTITLE) $(STRING_BANNER_WAITING_TEXT)
; if running in X64, powershell(X64) is in $WINDIR\Sysnative.
${If} ${RunningX64}
ExecWait "$\"$WINDIR\Sysnative\WindowsPowerShell\v1.0\PowerShell.exe$\" -InputFormat none -ExecutionPolicy RemoteSigned -File $\"$PLUGINSDIR\runpowershell.ps1$\"" $R0
${Else}
ExecWait "$\"$SYSDIR\WindowsPowerShell\v1.0\PowerShell.exe$\" -InputFormat none -ExecutionPolicy RemoteSigned -File $\"$PLUGINSDIR\runpowershell.ps1$\"" $R0
${EndIf}
Banner::destroy
${EndIf}
IntCmp $R0 0 lbl_success_${execID}
SetErrorLevel 2
lbl_success_${execID}:
Delete "$PLUGINSDIR\runpowershell.ps1"
!undef execID
!macroend
!define RunPowerShellCmd `!insertmacro RunPowerShellCmdOptions "0"`
!define RunPowerShellCmdShow `!insertmacro RunPowerShellCmdOptions "1"`
; -----------------------------------------------------------------------------
; initialize function
Function .onInit
InitPluginsDir
File /oname=${DISTSELECT_INI} "DistributionSelection.ini"
File /oname=${VIRTSET_INI} "VirtualMachineSettings.ini"
${If} ${IsWinMe}
MessageBox MB_OK|MB_ICONSTOP $(STRING_WINDOWSME_NOTSUPPORTED)
Quit
${EndIf}
ExpandEnvStrings $systemDrive "%SYSTEMDRIVE%"
${If} $systemDrive == "%SYSTEMDRIVE%"
; If Windows 9x, SYSTEMDRIVE environment variable is not set..
StrCpy $systemDrive "C:"
${EndIf}
; SetOutPath should be executed before any CMD.exe execution;
; CMD.exe may cause error if openSUSE_installer.exe is run in UNC path.
SetOutPath $INSTDIR
Call GetSystemMemoryInfo
StrCpy $R0 768
${If} $4 L< $R0
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION $(STRING_INSUFFICIENT_MEMORY) \
IDOK lbl_lowmemoryok
Quit
lbl_lowmemoryok:
ExecShell "open" "$(STRING_URL_INSUFFICIENT_MEMORY)"
${EndIf}
; if running in X64, bcdedit is in %windir%\Sysnative.
${If} ${RunningX64}
ExpandEnvStrings $bcdedit "%windir%\Sysnative\bcdedit"
${Else}
StrCpy $bcdedit "bcdedit"
${EndIf}
; check bootloader
Call CheckBootloader
Pop $R0
${If} $R0 == 'vista'
${OrIf} $R0 == 'nt'
# check administrator privilege
userInfo::getAccountType
pop $0
${If} $0 != "Admin"
MessageBox MB_OK $(STRING_NOTADMIN)
Quit
${Endif}
${EndIf}
; check media
ClearErrors
FileOpen $R0 "$EXEDIR\media.1\products" r
IfErrors lbl_noproduct 0
FileRead $R0 $R1
FileClose $R0
StrCpy $R2 $R1 255 2 ; remove "/ "
; remove after LF
StrCpy $R3 0
lbl_loopLF:
IntOp $R3 $R3 + 1
StrCpy $R4 $R2 1 $R3
StrCmp $R4 "$\n" lbl_loopexit
StrCmp $R4 "" lbl_loopexit
Goto lbl_loopLF
lbl_loopexit:
StrCpy $mediaVer $R2 $R3
; check if i386 exists
ClearErrors
FileOpen $R0 "$EXEDIR\boot\i386\loader\linux" r
IfErrors lbl_noi386 0
FileClose $R0
StrCpy $mediaI386 1
Goto lbl_i386exit
lbl_noi386:
StrCpy $mediaI386 0
lbl_i386exit:
; check if x86_64 exists
ClearErrors
FileOpen $R0 "$EXEDIR\boot\x86_64\loader\linux" r
IfErrors lbl_nox86_64 0
FileClose $R0
StrCpy $mediaX86_64 1
Goto lbl_x86_64exit
lbl_nox86_64:
StrCpy $mediaX86_64 0
lbl_x86_64exit:
Goto lbl_productdone
lbl_noproduct:
StrCpy $mediaVer ""
lbl_productdone:
!define MUI_LANGDLL_WINDOWTITLE $(STRING_LANGDLL_WINDOWTITLE)
!define MUI_LANGDLL_INFO $(STRING_LANGDLL_INFO)
!insertmacro MUI_LANGDLL_DISPLAY
!undef MUI_LANGDLL_WINDOWTITLE
!undef MUI_LANGDLL_INFO
FunctionEnd ; ".onInit"
Function un.onInit
ExpandEnvStrings $systemDrive "%SYSTEMDRIVE%"
${If} $systemDrive == "%SYSTEMDRIVE%"
; If Windows 9x, SYSTEMDRIVE environment variable is not set..
StrCpy $systemDrive "C:"
${EndIf}
FunctionEnd ; "un.onInit"
; -----------------------------------------------------------------------------
; display distribution
Section "Display distribution selection"
SectionIn RO ; always show
SectionEnd
Function "ShowDistributionSelection"
; test 64bit
test64::get_arch
WriteIniStr ${DISTSELECT_INI} "Field 1" "Text" $(STRING_VERSION)
WriteIniStr ${DISTSELECT_INI} "Field 3" "Text" $(STRING_ARCHITECTURE)
WriteIniStr ${DISTSELECT_INI} "Field 5" "Text" $(STRING_ENVIRONMENT)
WriteIniStr ${DISTSELECT_INI} "Field 6" "ListItems" \
"$(STRING_ENVIRONMENTSELECTITEM_DUALBOOT)|$(STRING_ENVIRONMENTSELECTITEM_VIRTUALBOX)|$(STRING_ENVIRONMENTSELECTITEM_HYPERV)|$(STRING_ENVIRONMENTSELECTITEM_LINUXONWINDOWS)"
WriteIniStr ${DISTSELECT_INI} "Field 7" "State" $(STRING_DISTSELECTIONDESCRIPTION)
${If} $0 == "x86_64"
; when x86_64 is supported..
${If} $mediaVer == ""
${OrIf} $mediaX86_64 == "0"
; set the latest stable version
WriteIniStr ${DISTSELECT_INI} "Field 2" "State" "openSUSE Leap 15.6"
StrCpy $R1 ""
${Else}
; set the version of this media
WriteIniStr ${DISTSELECT_INI} \
"Field 2" "State" "$(STRING_VERSIONOFTHISMEDIA) ($mediaVer)"
StrCpy $R1 "$(STRING_VERSIONOFTHISMEDIA) ($mediaVer)|"
${EndIf}
; set currently supported versions
WriteIniStr ${DISTSELECT_INI} "Field 2" "ListItems" \
"$R1openSUSE Leap 15.6|openSUSE Leap 15.5|openSUSE Leap 15.4|openSUSE Leap 15.3|openSUSE Leap 15.2|openSUSE Leap 15.1|openSUSE Leap 15.0|openSUSE Tumbleweed|openSUSE Leap 42.3"
${Else}
; when x86_64 is not supported..
${If} $mediaVer == ""
${OrIf} $mediaI386 == "0"
; set latest stable version
WriteIniStr ${DISTSELECT_INI} "Field 2" "State" "openSUSE Tumbleweed"
StrCpy $R1 ""
${Else}
; set the version of this media
WriteIniStr ${DISTSELECT_INI} "Field 2" "State" \
"$(STRING_VERSIONOFTHISMEDIA) ($mediaVer)"
StrCpy $R1 "$(STRING_VERSIONOFTHISMEDIA) ($mediaVer)|"
${EndIf}
; set currently supported versions
WriteIniStr ${DISTSELECT_INI} "Field 2" "ListItems" \
"$R1openSUSE Tumbleweed"
; remove x86_64
WriteIniStr ${DISTSELECT_INI} "Field 4" "State" "i386"
WriteIniStr ${DISTSELECT_INI} "Field 4" "ListItems" "i386"
${EndIf}
${If} $distribution != ""
WriteIniStr ${DISTSELECT_INI} "Field 2" "State" $distribution
${EndIf}
${If} $architecture != ""
WriteIniStr ${DISTSELECT_INI} "Field 4" "State" $architecture
${EndIf}
${If} $environment != ""
WriteIniStr ${DISTSELECT_INI} "Field 6" "State" $environment
${Else}
WriteIniStr ${DISTSELECT_INI} "Field 6" "State" \
"$(STRING_ENVIRONMENTSELECTITEM_DUALBOOT)"
${EndIf}
; show dialog
InstallOptions::initDialog /NOUNLOAD ${DISTSELECT_INI}
Pop $hwnd
!insertmacro MUI_HEADER_TEXT $(STRING_SELECTDIST_TITLE) $(STRING_SELECTDIST_TEXT)
InstallOptions::show
FunctionEnd ; "ShowDistributionSelection"
Function "LeaveDistributionSelection"
ReadIniStr $distribution ${DISTSELECT_INI} "Field 2" "State"
ReadIniStr $architecture ${DISTSELECT_INI} "Field 4" "State"
ReadIniStr $environment ${DISTSELECT_INI} "Field 6" "State"
StrCpy $0 $distribution 14
${If} $0 == "openSUSE Leap "
${If} $architecture != "x86_64"
MessageBox MB_OK|MB_ICONSTOP $(STRING_LEAP_64BITONLY)
Abort
${EndIf}
${EndIf}
${If} $mediaVer != ""
StrLen $1 $(STRING_VERSIONOFTHISMEDIA)
StrCpy $0 $distribution $1
${If} $0 == $(STRING_VERSIONOFTHISMEDIA)
; cannot use local media if virtualized install
${If} $environment != $(STRING_ENVIRONMENTSELECTITEM_DUALBOOT)
MessageBox MB_OK|MB_ICONSTOP $(STRING_CANNOTUSELOCALMEDIAIFVIRTUALIZED)
Abort
${EndIf}
${If} $architecture == "i386"
${AndIf} $mediaI386 == "0"
MessageBox MB_OK|MB_ICONSTOP $(STRING_NOTEXISTONMEDIA)
Abort
${EndIf}
${If} $architecture == "x86_64"
${AndIf} $mediaX86_64 == "0"
MessageBox MB_OK|MB_ICONSTOP $(STRING_NOTEXISTONMEDIA)
Abort
${EndIf}
${EndIf}
${EndIf}
${If} $environment == $(STRING_ENVIRONMENTSELECTITEM_VIRTUALBOX)
; check operating system (Windows XP or later required)
ClearErrors
${IfNot} ${IsNT}
MessageBox MB_OK|MB_ICONSTOP $(STRING_VIRTUALBOX_OSFAILED)
Abort
${EndIf}
${IfNot} ${AtLeastWinXP}
MessageBox MB_OK|MB_ICONSTOP $(STRING_VIRTUALBOX_OSFAILED)
Abort
${EndIf}
; check Internet connectivity
; ###TODO###
; check memory (2GB or more needed)
Call GetSystemMemoryInfo
StrCpy $R0 2048
${If} $4 L< $R0
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION $(STRING_INSUFFICIENT_MEMORY) \
IDOK lbl_lowmemoryokvbox
Abort
lbl_lowmemoryokvbox:
ExecShell "open" "$(STRING_URL_INSUFFICIENT_MEMORY)"
${EndIf}
; check GUI (VirtualBox cannot support Server Core)
IfFileExists "$WINDIR\explorer.exe" lbl_notservercore
MessageBox MB_OK|MB_ICONSTOP $(STRING_SERVERCOREVIRTUALBOX)
Abort
lbl_notservercore:
; check free storage (8GB or more needed)
; ###TODO###
; check powershell (required for later procedure)
IfFileExists "$SYSDIR\WindowsPowerShell\v1.0\PowerShell.exe" lbl_powershellvbox
MessageBox MB_OK|MB_ICONSTOP $(STRING_NOPOWERSHELLVIRTUALBOX)
Abort
lbl_powershellvbox:
; read registry whether VirtualBox is installed or not
ReadRegStr $0 HKCR "progId_VirtualBox.Shell.vbox\shell\open\command" ""
${If} $0 == ""
; VirtualBox is not installed; download and install.
MessageBox MB_OKCANCEL|MB_ICONQUESTION \
$(STRING_VIRTUALBOXINSTALLATIONCONFIRM) \
IDOK lbl_installvbox
Abort
lbl_installvbox:
; check the latest version
; (NSISdl cannot be used because it does not support HTTPS...)
StrCpy $R2 "https://update.virtualbox.org/query.php?platform=WINDOWS_64BITS_GENERIC&version=1.0.0"
${RunPowerShellCmd} "(new-object System.Net.WebClient).Downloadfile($\"$R2$\", $\"$TEMP\vbox-latest.txt$\")"
Pop $0
${IfNot} $0 == ""
StrCpy $R1 $R2
MessageBox MB_OK|MB_ICONSTOP "ver $(STRING_DOWNLOADERROR_R1)"
Abort
${EndIf}
FileOpen $R1 "$TEMP\vbox-latest.txt" r
FileRead $R1 $R2
FileClose $R1
StrCpy $1 0
lbl_loopinstallvboxspace:
StrCpy $2 $R2 1 $1
IntOp $1 $1 + 1
StrCmp $2 "" lbl_loopinstallvboxnotspace
StrCmp $2 " " 0 lbl_loopinstallvboxspace
lbl_loopinstallvboxnotspace:
StrCpy $2 $R2 1 $1
IntOp $1 $1 + 1
StrCmp $2 " " lbl_loopinstallvboxnotspace
IntOp $1 $1 - 1
StrCpy $R3 $R2 1024 $1
Delete "$TEMP\vbox-latest.txt"
${RunPowerShellCmdShow} 'Start-BitsTransfer -Source $\"$R3$\" -Destination $\"$TEMP\vbox.exe$\"'
ExecWait "$\"$TEMP\vbox.exe$\"" $0
${IfNot} $0 == "0"
MessageBox MB_OK|MB_ICONSTOP $(STRING_VIRTUALBOXINSTALLATIONFAILED)
Abort
${EndIf}
Delete "$\"$TEMP\vbox.exe$\""
${EndIf}
; read registry again
ReadRegStr $R2 HKCR "progId_VirtualBox.Shell.vbox\shell\open\command" ""
${If} $0 == ""
; VirtualBox installation failed; abort.
MessageBox MB_OK|MB_ICONSTOP $(STRING_VIRTUALBOXINSTALLATIONFAILED)
Abort
${EndIf}
; set $dirVirt
StrCpy $1 $R2 1
${If} $1 == "$\""
StrCpy $R3 1
lbl_loopquote:
IntOp $R3 $R3 + 1
StrCpy $R4 $R2 1 $R3
StrCmp $R4 "$\"" lbl_loopquoteexit
StrCmp $R4 "" lbl_loopquoteexit
Goto lbl_loopquote
lbl_loopquoteexit:
IntOp $R3 $R3 - 1
StrCpy $dirVirt $R2 $R3 1
${Else}
StrCpy $R3 0
lbl_loopspace:
IntOp $R3 $R3 + 1
StrCpy $R4 $R2 1 $R3
StrCmp $R4 " " lbl_loopspaceexit
StrCmp $R4 "" lbl_loopspaceexit
Goto lbl_loopspace
lbl_loopspaceexit:
StrCpy $dirVirt $R2 $R3 0
${EndIf}
; remove last "\" and followings
StrLen $R3 $dirVirt
lbl_loopremove:
IntOp $R3 $R3 - 1
StrCpy $R4 $dirVirt 1 $R3
StrCmp $R4 "\" lbl_loopremoveexit
StrCmp $R4 "" lbl_loopremoveexit
Goto lbl_loopremove
lbl_loopremoveexit:
StrCpy $dirVirt $dirVirt $R3
; set $dirVM
Banner::show /set 76 $(STRING_BANNER_WAITINGTITLE) $(STRING_BANNER_WAITING_TEXT)
nsExec::Exec "cmd /C $\"$dirVirt\VBoxManage.exe$\" list systemproperties > $TEMP\vbox_system_prop.txt"
FileOpen $R1 "$TEMP\vbox_system_prop.txt" r
Pop $0
lbl_loopreadvboxprop:
FileRead $R1 $R2
StrCmp $R2 "" lbl_loopreadvboxpropexit
StrCpy $R3 $R2 23 0
StrCmp $R3 "Default machine folder:" lbl_loopreadvboxpropexit
Goto lbl_loopreadvboxprop
lbl_loopreadvboxpropexit:
Banner::destroy
${If} $R3 == "Default machine folder:"
StrCpy $R4 23
lbl_loopvboxpropspace:
IntOp $R4 $R4 + 1
StrCpy $R5 $R2 1 $R4
StrCmp $R5 " " lbl_loopvboxpropspace
StrCmp $R5 "\t" lbl_loopvboxpropspace
StrCpy $dirVM $R2 1024 $R4
StrLen $R4 $dirVM
lbl_loopvboxpropcrlf:
IntOp $R4 $R4 - 1
StrCpy $R5 $dirVM 1 $R4
StrCmp $R5 "$\r" lbl_loopvboxpropcrlf
StrCmp $R5 "$\n" lbl_loopvboxpropcrlf
IntOp $R4 $R4 + 1
StrCpy $dirVM $dirVM $R4 0
${Else}
MessageBox MB_OK|MB_ICONSTOP $(STRING_VIRTUALBOXINSTALLATIONFAILED)
Abort
${EndIf}
FileClose $R1
Delete "$TEMP\vbox_system_prop.txt"
CreateDirectory $dirVM
${ElseIf} $environment == $(STRING_ENVIRONMENTSELECTITEM_HYPERV)
; check operating system (Windows 8/Server 2012 or later required)
ClearErrors
${IfNot} ${IsNT}
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERV_OSFAILED)
Abort
${EndIf}
${IfNot} ${AtLeastWin8}
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERV_OSFAILED)
Abort
${EndIf}
; check Internet connectivity
; ###TODO###
; check memory (2GB or more needed)
Call GetSystemMemoryInfo
StrCpy $R0 2048
${If} $4 L< $R0
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION $(STRING_INSUFFICIENT_MEMORY) \
IDOK lbl_lowmemoryokhyperv
Abort
lbl_lowmemoryokhyperv:
ExecShell "open" "$(STRING_URL_INSUFFICIENT_MEMORY)"
${EndIf}
; check free storage (8GB or more needed)
; ###TODO###
; check powershell (required for later procedure)
IfFileExists "$SYSDIR\WindowsPowerShell\v1.0\PowerShell.exe" lbl_powershellhyperv
MessageBox MB_OK|MB_ICONSTOP $(STRING_NOPOWERSHELLHYPERV)
Abort
lbl_powershellhyperv:
${If} ${IsServerOS}
; check whether Hyper-V (for server OS) is installed or not
${RunPowerShellCmd} "Import-Module ServerManager; (Get-WindowsFeature Hyper-V).Installed"
${Else}
; check whether Hyper-V (for client OS) is installed or not
${RunPowerShellCmd} "(Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All).State -and (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor).State -and (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Services).State"
${EndIf}
Pop $0
${If} $0 == "False$\r$\n"
${OrIf} $0 == "Disabled$\r$\n"
MessageBox MB_OKCANCEL|MB_ICONQUESTION \
$(STRING_HYPERVINSTALLATIONCONFIRM) \
IDOK lbl_installhyperv
Abort
lbl_installhyperv:
; check CPU support (Virtualization)
${RunPowerShellCmd} "(Get-WmiObject WIN32_Processor).VirtualizationFirmwareEnabled -notcontains $false"
Pop $0
${If} $0 == "False$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERV_VTDISABLED)
Abort
${ElseIf} $0 != "True$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERV_VTCHECKFAILED)
Abort
${EndIf}
; check CPU support (Second Level Address Translation)
${RunPowerShellCmd} "(Get-WmiObject WIN32_Processor).SecondLevelAddressTranslationExtensions -notcontains $false"
Pop $0
${If} $0 == "False$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERV_SLATDISABLED)
Abort
${ElseIf} $0 != "True$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERV_SLATCHECKFAILED)
Abort
${EndIf}
${If} ${IsServerOS}
${RunPowerShellCmd} "Import-Module ServerManager; (Add-WindowsFeature Hyper-V).Success"
${Else}
${RunPowerShellCmd} "(Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -NoRestart).Online -and (Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -NoRestart).Online -and (Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor -NoRestart).Online -and (Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Services -NoRestart).Online"
${EndIf}
Pop $0
StrLen $1 $0
IntOp $1 $1 - 6
StrCpy $2 $0 6 $1
${If} $2 != "True$\r$\n"
MessageBox MB_OK|MB_ICONSTOP "$(STRING_HYPERVINSTALLFAILED)"
Abort
${EndIf}
${ElseIf} $0 != "True$\r$\n"
${AndIf} $0 != "Enabled$\r$\n"
MessageBox MB_OK|MB_ICONSTOP "1: $(STRING_HYPERVCHECKFAILED)"
Abort
${EndIf}
${If} ${IsServerOS}
${RunPowerShellCmd} "Import-Module ServerManager; (Get-WindowsFeature RSAT-Hyper-V-Tools).Installed"
Pop $0
${If} $0 == "False$\r$\n"
${OrIf} $0 == "Disabled$\r$\n"
MessageBox MB_OKCANCEL|MB_ICONQUESTION $(STRING_HYPERVTOOLSINSTALLATIONCONFIRM) \
IDOK lbl_installhypervtools
Abort
lbl_installhypervtools:
${RunPowerShellCmd} "Import-Module ServerManager; (Add-WindowsFeature RSAT-Hyper-V-Tools).Success"
Pop $0
StrLen $1 $0
IntOp $1 $1 - 6
StrCpy $2 $0 6 $1
${If} $2 != "True$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERVTOOLSINSTALLFAILED)
Abort
${EndIf}
${ElseIf} $0 != "True$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERVTOOLSCHECKFAILED)
Abort
${EndIf}
${RunPowerShellCmd} "Import-Module ServerManager; (Add-WindowsFeature RSAT-Hyper-V-Tools).RestartNeeded"
Pop $0
${If} $0 == "Yes$\r$\n"
${OrIf} $0 == "True$\r$\n"
MessageBox MB_OK|MB_ICONINFORMATION $(STRING_HYPERVTOOLSREBOOTREQUIRED)
; installer should quit because reboot is needed
Quit
${ElseIf} $0 != "No$\r$\n"
${AndIf} $0 != "False$\r$\n"
MessageBox MB_OK|MB_ICONSTOP "2: $(STRING_HYPERVCHECKFAILED)"
Abort
${EndIf}
${EndIf}
${If} ${IsServerOS}
${RunPowerShellCmd} "Import-Module ServerManager; (Add-WindowsFeature Hyper-V).RestartNeeded"
${Else}
${RunPowerShellCmd} "(Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -NoRestart).RestartNeeded 3> $$null"
${EndIf}
Pop $0
${If} $0 == "Yes$\r$\n"
${OrIf} $0 == "True$\r$\n"
MessageBox MB_OK|MB_ICONINFORMATION $(STRING_HYPERVREBOOTREQUIRED)
; installer should quit because reboot is needed
Quit
${ElseIf} $0 != "No$\r$\n"
${AndIf} $0 != "False$\r$\n"
MessageBox MB_OK|MB_ICONSTOP "2: $(STRING_HYPERVCHECKFAILED)"
Abort
${EndIf}
${RunPowerShellCmd} "(Get-VmSwitch -SwitchType External).Name -join $\"|$\""
Pop $0
${If} $0 == "$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_HYPERV_NOEXTERNALSWITCH)
Abort
${EndIf}
${RunPowerShellCmd} "(Get-VMHost).VirtualHardDiskPath"
Pop $dirVM
StrLen $R4 $dirVM
lbl_loophypervpropcrlf:
IntOp $R4 $R4 - 1
StrCpy $R5 $dirVM 1 $R4
StrCmp $R5 "$\r" lbl_loophypervpropcrlf
StrCmp $R5 "$\n" lbl_loophypervpropcrlf
IntOp $R4 $R4 + 1
StrCpy $dirVM $dirVM $R4 0
${ElseIf} $environment == $(STRING_ENVIRONMENTSELECTITEM_LINUXONWINDOWS)
; check operating system (Windows 10 version 10.0.16226 or later required)
ClearErrors
${IfNot} ${IsNT}
MessageBox MB_OK|MB_ICONSTOP $(STRING_LINUXONWIN_OSFAILED)
Abort
${EndIf}
${IfNot} ${AtLeastWin10}
MessageBox MB_OK|MB_ICONSTOP $(STRING_LINUXONWIN_OSFAILED)
Abort
${EndIf}
; check whether it is server os or not (server os is not supported yet)
${If} ${IsServerOS}
MessageBox MB_OK|MB_ICONSTOP $(STRING_LINUXONWIN_SERVEROSFAILED)
Abort
${EndIf}
; check Internet connectivity
; ###TODO###
; check free storage (8GB or more needed)
; ###TODO###
; check powershell (required for later procedure)
IfFileExists "$SYSDIR\WindowsPowerShell\v1.0\PowerShell.exe" lbl_powershelllinuxonwin
MessageBox MB_OK|MB_ICONSTOP $(STRING_NOPOWERSHELLLINUXONWIN)
Abort
lbl_powershelllinuxonwin:
; check operating system (Windows 10 version 10.0.16226 or later required)
${RunPowerShellCmd} "[System.Environment]::OSVersion.Version.Build"
Pop $buildNum
${If} $buildNum < 16226
MessageBox MB_OK|MB_ICONSTOP $(STRING_LINUXONWIN_OSFAILED)
Abort
${EndIf}
; check whether Linux subsystem is installed or not
${If} $buildNum < 22000
${RunPowerShellCmd} "(Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State -and 1"
${Else}
; if Windows 11 (version 10.0.22000 or later) is installed,
; VirtualMachinePlatform is also required (i.e. only supports WSL2).
${RunPowerShellCmd} "(Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State -and (Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform).State"
${EndIf}
Pop $0
${If} $0 == "False$\r$\n"
MessageBox MB_OKCANCEL|MB_ICONQUESTION $(STRING_LINUXONWININSTALLATIONCONFIRM) \
IDOK lbl_installlinuxonwin
Abort
lbl_installlinuxonwin:
${If} $buildNum < 22000
${RunPowerShellCmd} "(Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart).Online 3> $$null"
${Else}
; if Windows 11 (version 10.0.22000 or later) is installed,
; VirtualMachinePlatform is also required (i.e. only supports WSL2).
${RunPowerShellCmd} "(Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart).Online -and (Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart).Online 3> $$null"
${EndIf}
Pop $0
${If} $0 != "True$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_LINUXONWININSTALLFAILED)
Abort
${EndIf}
${ElseIf} $0 != "True$\r$\n"
MessageBox MB_OK|MB_ICONSTOP "$(STRING_LINUXONWINCHECKFAILED)"
Abort
${EndIf}
; check reboot is needed or not
${If} $buildNum < 22000
${RunPowerShellCmd} "(Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart).RestartNeeded 3> $$null"
${Else}
; if Windows 11 (version 10.0.22000 or later) is installed,
; VirtualMachinePlatform is also required (i.e. only supports WSL2).
${RunPowerShellCmd} "(Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart).RestartNeeded -or (Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart).RestartNeeded 3> $$null"
${EndIf}
Pop $0
${If} $0 == "True$\r$\n"
MessageBox MB_OK|MB_ICONINFORMATION $(STRING_LINUXONWINREBOOTREQUIRED)
; installer should quit because reboot is needed
Quit
${EndIf}
MessageBox MB_OKCANCEL|MB_ICONQUESTION|MB_DEFBUTTON2 $(STRING_STARTCONFIRM) \
IDOK leavedist_ok_linuxonwin
Abort
leavedist_ok_linuxonwin:
${Else}
; check bootloader when install to real (i.e. not virtual) machine
Call CheckBootloader
Pop $R0
${If} $R0 == 'vista'
; check BCD store
nsExec::ExecToStack "cmd /c $\"wmic Volume where SystemVolume=true get DeviceID | findstr /B /L \$\""
Pop $1
Pop $1
StrCpy $2 0
lbl_loopvolumespaces:
IntOp $2 $2 + 1
StrCpy $3 $1 1 $2
StrCmp $3 " " lbl_loopexitvolumespaces
StrCmp $3 "$\r" lbl_loopexitvolumespaces
StrCmp $3 "$\n" lbl_loopexitvolumespaces
Goto lbl_loopvolumespaces
lbl_loopexitvolumespaces:
StrCpy $4 $1 $2
StrCpy $bcdStore "$4\boot\bcd"
; check whether UEFI boot mode is activated or not
ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$0" /C "$bcdedit /enum bootmgr | findstr /I ^path | findstr /I \.efi$$"'
Pop $1
Pop $1
StrLen $0 $1
${If} $0 > 0
MessageBox MB_OK|MB_ICONSTOP $(STRING_REFUSE_UEFI)
Abort
${EndIf}
; check BitLocker encryption
nsExec::ExecToStack "cmd /c $\"wmic /namespace:\\root\cimv2\Security\MicrosoftVolumeEncryption path Win32_EncryptableVolume where 'DriveLetter = '$systemDrive'' call GetConversionStatus | findstr /C:$\"ConversionStatus = $\"$\""
Pop $1
Pop $2
${If} $1 = 0
${If} $2 != "$\r$\n$\tConversionStatus = 0;$\r$\n"
MessageBox MB_OK|MB_ICONSTOP $(STRING_SYSTEMDRIVE_ENCRYPTED)
Abort
${EndIf}
${EndIf}
${EndIf}
MessageBox MB_OKCANCEL|MB_ICONQUESTION|MB_DEFBUTTON2 $(STRING_STARTCONFIRM) \
IDOK leavedist_ok
Abort
leavedist_ok:
${EndIf}
FunctionEnd ; "LeaveDistributionSelection"
; -----------------------------------------------------------------------------
; display virtual machine settings
Section "Display virtual machine settings"
SectionIn RO ; always show
SectionEnd
Function "UpdateVirtualSwitches"
${RunPowerShellCmd} "(Get-VmSwitch -SwitchType External).Name -join $\"|$\""
Pop $0
WriteIniStr ${VIRTSET_INI} "Field 8" "ListItems" "$0"
${RunPowerShellCmd} "(Get-VmSwitch -SwitchType External).Name | Select-Object -First 1"
Pop $0
WriteIniStr ${VIRTSET_INI} "Field 8" "State" "$0"
FunctionEnd ; "UpdateVirtualSwitches"
Function "ShowVirtualMachineSettings"
; If not virtual machine, skip it
${If} $environment == $(STRING_ENVIRONMENTSELECTITEM_DUALBOOT)
${OrIf} $environment == $(STRING_ENVIRONMENTSELECTITEM_LINUXONWINDOWS)
Abort
${EndIf}
WriteIniStr ${VIRTSET_INI} "Field 1" "Text" $(STRING_VMNAME)
WriteIniStr ${VIRTSET_INI} "Field 3" "Text" $(STRING_VMMEMORY)
WriteIniStr ${VIRTSET_INI} "Field 5" "Text" $(STRING_VMDISK)
WriteIniStr ${VIRTSET_INI} "Field 7" "Text" $(STRING_VMNETWORK)
${If} $nameVM != ""
WriteIniStr ${VIRTSET_INI} "Field 2" "State" "$nameVM"
${Else}
WriteIniStr ${VIRTSET_INI} "Field 2" "State" "$distribution $architecture"
${EndIf}
${If} $memoryVM != ""
WriteIniStr ${VIRTSET_INI} "Field 4" "State" "$memoryVM"
${Else}
WriteIniStr ${VIRTSET_INI} "Field 4" "State" "1024"
${EndIf}
${If} $diskVM != ""
WriteIniStr ${VIRTSET_INI} "Field 6" "State" "$diskVM"
${Else}
WriteIniStr ${VIRTSET_INI} "Field 6" "State" "8192"
; Increase to 10GB for Leap 15.0 or later
StrCpy $0 $distribution 14
${If} $0 == "openSUSE Leap "
StrCpy $R3 $distribution 255 14
${If} $R3 < 42
WriteIniStr ${VIRTSET_INI} "Field 6" "State" "10240"
${EndIf}
${EndIf}
${EndIf}
${If} $environment == $(STRING_ENVIRONMENTSELECTITEM_HYPERV)
${If} $switchVM != ""
WriteIniStr ${VIRTSET_INI} "Field 8" "State" "$switchVM"
${Else}
Call UpdateVirtualSwitches
${EndIf}
${Else}
WriteIniStr ${VIRTSET_INI} "Field 7" "Flags" "DISABLED"
WriteIniStr ${VIRTSET_INI} "Field 8" "Flags" "DISABLED"
WriteIniStr ${VIRTSET_INI} "Field 8" "ListItems" ""
WriteIniStr ${VIRTSET_INI} "Field 9" "Flags" "DISABLED"
${EndIf}
; show dialog
InstallOptions::initDialog /NOUNLOAD ${VIRTSET_INI}
Pop $hwnd
!insertmacro MUI_HEADER_TEXT $(STRING_VMSETTINGS_TITLE) $(STRING_VMSETTINGS_TEXT)
InstallOptions::show
FunctionEnd ; "ShowVirtualMachineSettings"
Function "LeaveVirtualMachineSettings"
ReadIniStr $nameVM ${VIRTSET_INI} "Field 2" "State"
ReadIniStr $memoryVM ${VIRTSET_INI} "Field 4" "State"