-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.ps1
4045 lines (3294 loc) · 189 KB
/
run.ps1
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
# HstWB Installer Run
# -------------------
#
# Author: Henrik Noerfjand Stengaard
# Date: 2022-01-03
#
# A powershell script to run HstWB Installer automating installation of workbench, kickstart roms and packages to an Amiga HDF file.
Param(
[Parameter(Mandatory=$false)]
[string]$settingsDir
)
Import-Module (Resolve-Path('modules\version.psm1')) -Force
Import-Module (Resolve-Path('modules\config.psm1')) -Force
Import-Module (Resolve-Path('modules\dialog.psm1')) -Force
Import-Module (Resolve-Path('modules\data.psm1')) -Force
Add-Type -AssemblyName System.IO.Compression.FileSystem
Add-Type -AssemblyName System.Windows.Forms
# show folder browser dialog using WinForms
function FolderBrowserDialog($title, $directory, $showNewFolderButton)
{
$folderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog
$folderBrowserDialog.Description = $title
$folderBrowserDialog.SelectedPath = $directory
$folderBrowserDialog.ShowNewFolderButton = $showNewFolderButton
$result = $folderBrowserDialog.ShowDialog()
if($result -ne "OK")
{
return $null
}
return $folderBrowserDialog.SelectedPath
}
# confirm dialog
function ConfirmDialog($title, $message)
{
$result = [System.Windows.Forms.MessageBox]::Show($message, $title, [System.Windows.Forms.MessageBoxButtons]::OKCancel)
if($result -eq "OK")
{
return $true
}
return $false
}
# write text file encoded for Amiga
function WriteAmigaTextLines($path, $lines)
{
$iso88591 = [System.Text.Encoding]::GetEncoding("ISO-8859-1")
$utf8 = [System.Text.Encoding]::UTF8;
$amigaTextBytes = [System.Text.Encoding]::Convert($utf8, $iso88591, $utf8.GetBytes($lines -join "`n"))
[System.IO.File]::WriteAllText($path, $iso88591.GetString($amigaTextBytes), $iso88591)
}
# update version amiga text file
function UpdateVersionAmigaTextFile($amigaTextFile, $version)
{
$iso88591 = [System.Text.Encoding]::GetEncoding("ISO-8859-1")
$lines = @()
$lines += [System.IO.File]::ReadAllLines($amigaTextFile, $iso88591)
$updated = $false
for ($i = 0; $i -lt $lines.Count; $i++)
{
if ($lines[$i] -cmatch "[`$VersionText]")
{
$updated = $true
$lines[$i] = $lines[$i].Replace("[`$VersionText]", $version)
}
if ($lines[$i] -cmatch "[`$VersionDashes]")
{
$updated = $true
$lines[$i] = $lines[$i].Replace("[`$VersionDashes]", ("-" * $version.Length))
}
}
if ($updated)
{
WriteAmigaTextLines $amigaTextFile $lines
}
}
# start process
function StartProcess($fileName, $arguments, $workingDirectory)
{
# start process info
$processInfo = New-Object System.Diagnostics.ProcessStartInfo
$processInfo.FileName = $fileName
$processInfo.RedirectStandardError = $true
$processInfo.RedirectStandardOutput = $true
$processInfo.UseShellExecute = $false
$processInfo.Arguments = $arguments
$processInfo.WorkingDirectory = $workingDirectory
# run process
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $processInfo
$process.Start() | Out-Null
$process.BeginErrorReadLine()
$process.BeginOutputReadLine()
$process.WaitForExit()
if ($process.ExitCode -ne 0)
{
$standardOutput = $process.StandardOutput.ReadToEnd()
$standardError = $process.StandardError.ReadToEnd()
if ($standardOutput)
{
Write-Error ("StandardOutput: " + $standardOutput)
}
if ($standardError)
{
Write-Error ("StandardError: " + $standardError)
}
}
return $process.ExitCode
}
# find packages to install
function FindPackagesToInstall($hstwb)
{
# get install packages
$installPackageNames = @{}
foreach($installPackageKey in ($hstwb.Settings.Packages.Keys | Where-Object { $_ -match 'InstallPackage\d+' }))
{
$installPackageNames.Set_Item($hstwb.Settings.Packages.Get_Item($installPackageKey.ToLower()), $true)
}
$packageNames = SortPackageNames $hstwb
$installPackages = @()
$installPackages += $packageNames | Where-Object { $installPackageNames[$_] }
return $installPackages
}
# extract packages
function ExtractPackages($hstwb, $packageNames, $packagesDir)
{
foreach($packageName in $packageNames)
{
# get package
$package = $hstwb.Packages[$packageName]
if (!$package)
{
continue
}
# extract package file to package directory
$packageDir = [System.IO.Path]::Combine($packagesDir, $package.Id)
Write-Host ("Extracting '{0}' package to directory '{1}'" -f $package.Name, $packageDir)
# delete existing package directory, if it exists
if(test-path -path $packageDir)
{
remove-item -Path $packageDir -Recurse -Force
}
# create package directory
mkdir $packageDir | Out-Null
# extract package to package directory
[System.IO.Compression.ZipFile]::ExtractToDirectory($package.PackageFile, $packageDir)
}
}
# install hstwb installer fs-uae theme
function InstallHstwbInstallerFsUaeTheme($hstwb)
{
$hstwbInstallerFsUaeThemeDir = Join-Path $hstwb.Paths.FsUaePath -ChildPath "theme\\hstwb-installer"
# fail, if hstwb installer fs-uae theme directory doesn't exist
if (!(Test-Path -Path $hstwbInstallerFsUaeThemeDir))
{
throw ("HstWB Installer FS-UAE theme '{0}' doesn't exist" -f $hstwbInstallerFsUaeThemeDir)
}
# fs-uae theme directory
$fsuaeThemeDir = Join-Path ([System.Environment]::GetFolderPath('MyDocuments')) -ChildPath 'FS-UAE\\Themes\\hstwb-installer'
# return, if fs-uae themes directory exist
if (Test-Path -Path $fsuaeThemeDir)
{
return
}
# create fs-uae themes directory, if it doesn't exist
mkdir -Path $fsuaeThemeDir | Out-Null
# copy hstwb installer fs-uae theme directory to fs-uae theme directory
Copy-Item -Path "$hstwbInstallerFsUaeThemeDir\*" $fsuaeThemeDir -force
}
# build assign hstwb installer script lines
function BuildAssignHstwbInstallerScriptLines($hstwb, $createDirectories)
{
$globalAssigns = $hstwb.Assigns.Get_Item('Global')
$assignHstwbInstallerScriptLines = @()
foreach ($assignName in $globalAssigns.keys)
{
# skip, if assign name is 'HstWBInstallerDir' and installer mode is build package installation
if ($assignName -match 'HstWBInstallerDir' -and $hstwb.Settings.Installer.Mode -match "^(Install|BuildPackageInstallation)$")
{
continue
}
# get assign path and drive
$assignDir = $globalAssigns.Get_Item($assignName)
$assignDrive = $assignDir -replace '^([^:]+:).*', '$1'
# add package assign lines
$assignHstwbInstallerScriptLines += "; Add assign for '$assignName' to '$assignDir'"
$assignHstwbInstallerScriptLines += "Assign >NIL: EXISTS ""$assignDrive"""
$assignHstwbInstallerScriptLines += "IF WARN"
$assignHstwbInstallerScriptLines += " echo ""Error: Drive '$assignDrive' doesn't exist for assign '$assignDir'!"""
$assignHstwbInstallerScriptLines += " ask ""Press ENTER to exit"""
$assignHstwbInstallerScriptLines += " QUIT 5"
$assignHstwbInstallerScriptLines += "ELSE"
# create directory for assignpath or check if path exist
if ($createDirectories)
{
# add makedir dir each directory in assign path
$dirs = @()
$dirs += ($assignDir -replace '^[^:]+:(.*)', '$1') -split '/' | Where-Object { $_ }
$currentAssignPath = $assignDrive
foreach ($dir in $dirs)
{
if ($currentAssignPath -notmatch ':$')
{
$currentAssignPath += '/'
}
$currentAssignPath += $dir
$assignHstwbInstallerScriptLines += (" IF NOT EXISTS """ + $currentAssignPath + """")
$assignHstwbInstallerScriptLines += (" MakeDir >NIL: """ + $currentAssignPath + """")
$assignHstwbInstallerScriptLines += (" ENDIF")
}
$assignHstwbInstallerScriptLines += (" Assign " + $assignName + ": """ + $assignDir + """")
}
else
{
$assignHstwbInstallerScriptLines += (" IF EXISTS """ + $assignDir + """")
$assignHstwbInstallerScriptLines += (" Assign " + $assignName + ": """ + $assignDir + """")
$assignHstwbInstallerScriptLines += " ELSE"
$assignHstwbInstallerScriptLines += " echo ""Error: Path '$assignDir' doesn't exist for assign!"""
$assignHstwbInstallerScriptLines += " ask ""Press ENTER to exit"""
$assignHstwbInstallerScriptLines += " QUIT 5"
$assignHstwbInstallerScriptLines += " ENDIF"
}
$assignHstwbInstallerScriptLines += "ENDIF"
}
return $assignHstwbInstallerScriptLines
}
# build assign dir script lines
function BuildAssignDirScriptLines($assignId, $assignDir)
{
$assignDirScriptLines = @()
$assignDirScriptLines += ("IF EXISTS ""T:{0}""" -f $assignId)
$assignDirScriptLines += (" Set assigndir ""``type ""T:{0}""``""" -f $assignId)
$assignDirScriptLines += "ELSE"
$assignDirScriptLines += (" Set assigndir ""{0}""" -f $assignDir)
$assignDirScriptLines += "ENDIF"
return $assignDirScriptLines
}
# build add assign script lines
function BuildAddAssignScriptLines($assignId, $assignName, $assignDir)
{
$addAssignScriptLines = @()
$addAssignScriptLines += ("; Add assign and set variable for assign '{0}'" -f $assignName)
$addAssignScriptLines += BuildAssignDirScriptLines $assignId $assignDir
$addAssignScriptLines += "IF NOT EXISTS ""`$assigndir"""
$addAssignScriptLines += " MakePath ""`$assigndir"""
$addAssignScriptLines += "ENDIF"
$addAssignScriptLines += ("echo ""Add assign '`$assigndir' = '{0}'"" >>SYS:hstwb-installer.log" -f $assignName)
$addAssignScriptLines += ("SetEnv {0} ""`$assigndir""" -f $assignName)
$addAssignScriptLines += ("Assign {0}: ""`$assigndir""" -f $assignName)
return $addAssignScriptLines
}
# build remove assign script lines
function BuildRemoveAssignScriptLines($assignId, $assignName, $assignDir)
{
$removeAssignScriptLines = @()
$removeAssignScriptLines += ("; Remove assign and unset variable for assign '{0}'" -f $assignName)
$removeAssignScriptLines += BuildAssignDirScriptLines $assignId $assignDir
$removeAssignScriptLines += ("echo ""Remove assign '`$assigndir' = '{0}'"" >>SYS:hstwb-installer.log" -f $assignName)
$removeAssignScriptLines += ("Assign {0}: ""`$assigndir"" REMOVE" -f $assignName)
$removeAssignScriptLines += ("IF EXISTS ""ENV:{0}""" -f $assignName)
$removeAssignScriptLines += (" delete >NIL: ""ENV:{0}""" -f $assignName)
$removeAssignScriptLines += "ENDIF"
return $removeAssignScriptLines
}
# build install package script lines
function BuildInstallPackageScriptLines($hstwb, $packageNames)
{
$globalAssigns = $hstwb.Assigns.Get_Item('Global')
$installPackageScripts = @()
foreach ($packageName in $packageNames)
{
# get package
$package = $hstwb.Packages[$packageName.ToLower()]
# add package installation lines to install packages script
$installPackageLines = @()
$installPackageLines += ("; Install package '{0}'" -f $package.FullName)
$installPackageLines += "echo """""
$installPackageLines += ("echo ""*e[1mInstalling package '{0}'*e[0m""" -f $package.FullName)
$removePackageAssignLines = @()
# get package assign names
$packageAssignNames = @()
if ($package.Assigns)
{
$packageAssignNames += $package.Assigns | Where-Object { $_.Path } | ForEach-Object { $_.Name }
}
# package assigns
if ($hstwb.Assigns.ContainsKey($package.Name))
{
$packageAssigns = $hstwb.Assigns[$package.Name]
}
else
{
$packageAssigns = @{}
}
# build and and remove package assigns
foreach ($assignName in $packageAssignNames)
{
# get matching global and package assign name (case insensitive)
$matchingGlobalAssignName = $globalAssigns.Keys | Where-Object { $_ -like $assignName } | Select-Object -First 1
$matchingPackageAssignName = $packageAssigns.Keys | Where-Object { $_ -like $assignName } | Select-Object -First 1
# fail, if package assign name doesn't exist in either global or package assigns
if (!$matchingGlobalAssignName -and !$matchingPackageAssignName)
{
Fail $hstwb ("Error: Package '" + $package.Name + "' doesn't have assign defined for '$assignName' in either global or package assigns!")
}
# skip, if package assign name is global
if ($matchingGlobalAssignName)
{
continue
}
# get assign path and drive
$assignId = CalculateMd5FromText (("{0}.{1}" -f $package.Name, $assignName).ToLower())
$assignDir = $packageAssigns.Get_Item($matchingPackageAssignName)
# append add package assign
$installPackageLines += ""
$installPackageLines += BuildAddAssignScriptLines $assignId $assignName $assignDir
# append ini file set for package assign, if installer mode is build self install or build package installation
if ($hstwb.Settings.Installer.Mode -eq "BuildSelfInstall" -or $hstwb.Settings.Installer.Mode -eq "BuildPackageInstallation")
{
$installPackageLines += 'execute INSTALLDIR:S/IniFileSet "{0}" "{1}" "{2}" "$assigndir"' -f 'SYSTEMDIR:Prefs/HstWB-Installer/Packages/Assigns.ini', $package.Name, $assignName
}
# append remove package assign
$removePackageAssignLines += BuildRemoveAssignScriptLines $assignId $assignName $assignDir
}
# add package dir assign, execute package install script and remove package dir assign
$installPackageLines += ""
$installPackageLines += "; Add package dir assign"
$installPackageLines += ("Assign PACKAGEDIR: ""PACKAGESDIR:{0}""" -f $package.Id)
$installPackageLines += ""
$installPackageLines += "; Execute package install script"
$installPackageLines += ("echo ""Running package '{0}' install script"" >>SYS:hstwb-installer.log" -f $package.Name)
$installPackageLines += "execute ""PACKAGEDIR:Install"""
$installPackageLines += ""
$installPackageLines += "; Remove package dir assign"
$installPackageLines += ("Assign PACKAGEDIR: ""PACKAGESDIR:{0}"" REMOVE" -f $package.Id)
# add remove package assign lines, if there are any
if ($removePackageAssignLines.Count -gt 0)
{
$installPackageLines += ""
$installPackageLines += $removePackageAssignLines
}
$installPackageLines += "echo ""Done"""
$installPackageScripts += @{ "Lines" = $installPackageLines; "Package" = $package }
}
return $installPackageScripts
}
# build reset assigns script lines
function BuildResetAssignsScriptLines($hstwb)
{
$resetAssignsScriptLines = @()
# reset assigns settings and get existing assign value, if present in prefs assigns ini file
foreach ($assignSectionName in $hstwb.Assigns.keys)
{
$sectionAssigns = $hstwb.Assigns[$assignSectionName]
foreach ($assignName in ($sectionAssigns.keys | Sort-Object | Where-Object { $_ -notlike 'HstWBInstallerDir' }))
{
$assignId = CalculateMd5FromText (("{0}.{1}" -f $assignSectionName, $assignName).ToLower())
$resetAssignsScriptLines += ''
$resetAssignsScriptLines += ("; Reset assign path setting for package '{0}' and assign '{1}'" -f $assignSectionName, $assignName)
$resetAssignsScriptLines += '; Get assign path from ini'
$resetAssignsScriptLines += 'set assigndir ""'
$resetAssignsScriptLines += 'set assigndir "`execute INSTALLDIR:S/IniFileGet "{0}" "{1}" "{2}"`"' -f 'SYSTEMDIR:Prefs/HstWB-Installer/Packages/Assigns.ini', $assignSectionName, $assignName
$resetAssignsScriptLines += ''
$resetAssignsScriptLines += '; Create assign path setting, if assign path exists in ini. Otherwise delete assign path setting'
$resetAssignsScriptLines += 'IF NOT "$assigndir" eq ""'
$resetAssignsScriptLines += (' echo "$assigndir" >"T:{0}"' -f $assignId)
$resetAssignsScriptLines += 'ELSE'
$resetAssignsScriptLines += (' IF EXISTS "T:{0}"' -f $assignId)
$resetAssignsScriptLines += (' delete >NIL: "T:{0}"' -f $assignId)
$resetAssignsScriptLines += ' ENDIF'
$resetAssignsScriptLines += 'ENDIF'
}
}
return $resetAssignsScriptLines
}
# build default assigns script lines
function BuildDefaultAssignsScriptLines($hstwb)
{
$defaultAssignsScriptLines = @()
# default assigns settings
foreach ($assignSectionName in $hstwb.Assigns.keys)
{
$sectionAssigns = $hstwb.Assigns[$assignSectionName]
foreach ($assignName in ($sectionAssigns.keys | Sort-Object | Where-Object { $_ -notlike 'HstWBInstallerDir' }))
{
$assignId = CalculateMd5FromText (("{0}.{1}" -f $assignSectionName, $assignName).ToLower())
$defaultAssignsScriptLines += ''
$defaultAssignsScriptLines += ("; Default assign path setting for package '{0}' and assign '{1}'" -f $assignSectionName, $assignName)
$defaultAssignsScriptLines += ('IF EXISTS "T:{0}"' -f $assignId)
$defaultAssignsScriptLines += (' delete >NIL: "T:{0}"' -f $assignId)
$defaultAssignsScriptLines += 'ENDIF'
}
}
return $defaultAssignsScriptLines
}
function BuildPackagesMenuScriptLines($hstwb, $dependencyPackageNamesIndex, $installPackageScripts)
{
$packagesMenuScriptLines = @()
$contentIdPackages = @{}
foreach ($installPackageScript in $installPackageScripts)
{
if (!$installPackageScript.Package.ContentIds)
{
continue
}
foreach($contentId in ($installPackageScript.Package.ContentIds | ForEach-Object { $_.ToLower() }))
{
if (!$contentIdPackages.ContainsKey($contentId))
{
$contentIdPackages[$contentId] = @()
}
if (($contentIdPackages[$contentId] | Where-Object { $_.Id -eq $installPackageScript.Package.Id }).Count -gt 0)
{
continue
}
$contentIdPackages[$contentId] += $installPackageScript.Package
}
}
$identicalContentIdLegends = @{}
$packageIdenticalContentIds = @{}
foreach($contentId in ($contentIdPackages.keys | Sort-Object))
{
if ($contentIdPackages[$contentId].Count -lt 2)
{
continue
}
if (!$identicalContentIdLegends.ContainsKey($contentId))
{
$identicalContentIdLegends[$contentId] = $identicalContentIdLegends.keys.Count + 1
}
foreach($package in $contentIdPackages[$contentId])
{
if (!$packageIdenticalContentIds.ContainsKey($package.Id))
{
$packageIdenticalContentIds[$package.Id] = @()
}
if ($packageIdenticalContentIds[$package.Id] -contains $identicalContentIdLegends[$contentId])
{
continue
}
$packageIdenticalContentIds[$package.Id] += $identicalContentIdLegends[$contentId]
}
}
$packageDependenciesLegends = @{}
$packageDependenciesIndex = @{}
$packageMenuOption = 0
$packagesMenuOptionLines = @()
$installPackagesMenuOptionLines = @()
# build package dependencies
foreach ($installPackageScript in $installPackageScripts)
{
$installPackagesMenuOptionLines += ("IF EXISTS ""T:{0}""" -f $installPackageScript.Package.Id)
$installPackagesMenuOptionLines += " echo ""Install"" NOLINE >>T:packagesmenu"
$installPackagesMenuOptionLines += "ELSE"
$installPackagesMenuOptionLines += " echo ""Skip "" NOLINE >>T:packagesmenu"
$installPackagesMenuOptionLines += "ENDIF"
$legends = @()
if ($installPackageScript.Package.Dependencies.Count -gt 0)
{
$packageDependenciesIndex[$installPackageScript.Package.Id]
if (!$packageDependenciesLegends.ContainsKey($installPackageScript.Package.Id))
{
$packageDependenciesLegends[$installPackageScript.Package.Id] = $packageDependenciesLegends.keys.Count + 1
}
$legends += '!{0}' -f $packageDependenciesLegends[$installPackageScript.Package.Id]
$packageDependenciesIndex[$installPackageScript.Package.Id] = GetDependencyPackageNames $hstwb $installPackageScript.Package
}
if ($packageIdenticalContentIds.ContainsKey($installPackageScript.Package.Id))
{
$legends += $packageIdenticalContentIds[$installPackageScript.Package.Id] | ForEach-Object { '={0}' -f $_}
}
$legendsFormatted = if ($legends.Count -gt 0) { (' ({0})' -f ($legends -join ', ')) } else { '' }
$installPackagesMenuOptionLines += ("echo "" : {0}{1}"" >>T:packagesmenu" -f $installPackageScript.Package.FullName, $legendsFormatted)
}
# select package filtering option
$packageMenuOption++
$packagesMenuOptionLines += ''
$packagesMenuOptionLines += '; select package filtering option'
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " SKIP packagefilteringmenu"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo """" NOLINE >T:packagesmenu"
$packagesMenuScriptLines += 'IF "$amigaosversion" EQ "All"'
$packagesMenuScriptLines += ' set amigaostext "All Amiga OS versions"'
$packagesMenuScriptLines += 'ELSE'
$packagesMenuScriptLines += ' set amigaostext "Amiga OS $amigaosversion"'
$packagesMenuScriptLines += 'ENDIF'
$packagesMenuScriptLines += "echo ""Select package filtering: `$amigaostext"" >>T:packagesmenu"
# splitter
$packageMenuOption++
$packagesMenuScriptLines += "echo ""--------------------------------------------------"" >>T:packagesmenu"
# install packages option
$packageMenuOption++
$packagesMenuOptionLines += ''
$packagesMenuOptionLines += '; install packages option'
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " set selectedpackagescount 0"
foreach ($installPackageScript in $installPackageScripts)
{
$packagesMenuOptionLines += (" IF EXISTS ""T:{0}""" -f $installPackageScript.Package.Id)
$packagesMenuOptionLines += " set selectedpackagescount ``eval `$selectedpackagescount + 1``"
$packagesMenuOptionLines += " ENDIF"
}
$packagesMenuOptionLines += " set confirm ``RequestChoice ""Start package installation"" ""Do you want to install `$selectedpackagescount package(s)?"" ""Yes|No""``"
$packagesMenuOptionLines += " IF ""`$confirm"" EQ ""1"""
$packagesMenuOptionLines += " SKIP installpackages"
$packagesMenuOptionLines += " ENDIF"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo ""Start package installation"" >>T:packagesmenu"
# install all option
$packageMenuOption++
$packagesMenuOptionLines += ''
$packagesMenuOptionLines += '; install all packages option'
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " SKIP installallpackages"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo ""Install all packages"" >>T:packagesmenu"
# skip all option
$packageMenuOption++
$packagesMenuOptionLines += ''
$packagesMenuOptionLines += '; skip all packages option'
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " SKIP skipallpackages"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo ""Skip all packages"" >>T:packagesmenu"
# edit assigns option
$packageMenuOption++
$packagesMenuOptionLines += ''
$packagesMenuOptionLines += '; edit assigns option'
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " SKIP editassignsmenu"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo ""Edit assigns"" >>T:packagesmenu"
# view readme option
$packageMenuOption++
$packagesMenuOptionLines += ''
$packagesMenuOptionLines += '; view readme option'
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " SKIP viewreadmemenu"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo ""View readme"" >>T:packagesmenu"
# legends option
$packageMenuOption++
$packagesMenuOptionLines += '; legends option'
$packagesMenuOptionLines += ('IF "$packagesmenu" eq "{0}"' -f $packageMenuOption)
$packagesMenuOptionLines += ' echo "Legends" >T:packageinstallationlegends.txt'
$packagesMenuOptionLines += ' echo "-------" >>T:packageinstallationlegends.txt'
$packagesMenuOptionLines += ' echo "Description for legends this package installation." >>T:packageinstallationlegends.txt'
$packagesMenuOptionLines += ' echo "" >>T:packageinstallationlegends.txt'
if ($packageDependenciesLegends.Count -gt 0)
{
$packagesMenuOptionLines += ('echo "{0} package dependencies legends:" >>T:packageinstallationlegends.txt' -f $packageDependenciesLegends.Count)
foreach($packageDependenciesLegend in ($packageDependenciesLegends.GetEnumerator() | Sort-Object Value))
{
$packagesMenuOptionLines += ('echo "!{0}: Package has package dependencies ''{1}''" >>T:packageinstallationlegends.txt' -f $packageDependenciesLegend.Value, ($packageDependenciesIndex[$packageDependenciesLegend.Name] -join ', '))
}
}
else
{
$packagesMenuOptionLines += 'echo "No package dependencies legends" >>T:packageinstallationlegends.txt'
}
$packagesMenuOptionLines += ' echo "" >>T:packageinstallationlegends.txt'
if ($identicalContentIdLegends.Count -gt 0)
{
$packagesMenuOptionLines += ('echo "{0} identical content legends:" >>T:packageinstallationlegends.txt' -f $identicalContentIdLegends.Count)
foreach($identicalContentIdLegend in ($identicalContentIdLegends.GetEnumerator() | Sort-Object Value))
{
$packagesMenuOptionLines += ('echo "={0}: Packages has identical content id ''{1}''" >>T:packageinstallationlegends.txt' -f $identicalContentIdLegend.Value, $identicalContentIdLegend.Name)
}
}
else
{
$packagesMenuOptionLines += 'echo "No identical content legends" >>T:packageinstallationlegends.txt'
}
$packagesMenuOptionLines += ' Lister "T:packageinstallationlegends.txt" >NIL:'
$packagesMenuOptionLines += ' delete >NIL: "T:packageinstallationlegends.txt"'
$packagesMenuOptionLines += " SKIP BACK installpackagesmenu"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo ""Legends (!), (=)"" >>T:packagesmenu"
# help option
$packageMenuOption++
$packagesMenuOptionLines += ''
$packagesMenuOptionLines += '; help option'
$packagesMenuOptionLines += ('IF "$packagesmenu" eq "{0}"' -f $packageMenuOption)
$packagesMenuOptionLines += ' IF EXISTS "PACKAGESDIR:Help/Package-Installation.txt"'
$packagesMenuOptionLines += ' Lister "PACKAGESDIR:Help/Package-Installation.txt" >NIL:'
$packagesMenuOptionLines += ' ELSE'
$packagesMenuOptionLines += ' RequestChoice "Error" "ERROR: Help file ''PACKAGESDIR:Help/Package-Installation.txt'' doesn''t exist!"'
$packagesMenuOptionLines += ' ENDIF'
$packagesMenuOptionLines += " SKIP BACK installpackagesmenu"
$packagesMenuOptionLines += "ENDIF"
$packagesMenuScriptLines += "echo ""Help"" >>T:packagesmenu"
# quit/skip option
$packageMenuOption++
if ($hstwb.Settings.Installer.Mode -eq "BuildPackageInstallation")
{
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " SKIP end"
$packagesMenuOptionLines += "ENDIF"
}
else
{
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " set confirm ``RequestChoice ""Skip package installation"" ""Do you want to skip package installation?"" ""Yes|No""``"
$packagesMenuOptionLines += " IF ""`$confirm"" EQ ""1"""
$packagesMenuOptionLines += " SKIP end"
$packagesMenuOptionLines += " ENDIF"
$packagesMenuOptionLines += "ENDIF"
}
if ($hstwb.Settings.Installer.Mode -eq "BuildPackageInstallation")
{
$packagesMenuScriptLines += "echo ""Quit"" >>T:packagesmenu"
}
else
{
$packagesMenuScriptLines += "echo ""Skip package installation"" >>T:packagesmenu"
}
# splitter
$packageMenuOption++
$packagesMenuScriptLines += "echo ""--------------------------------------------------"" >>T:packagesmenu"
$packagesMenuScriptLines += ""
# install packages menu options
$packagesMenuScriptLines += $installPackagesMenuOptionLines
# install / skip package options
foreach($installPackageScript in $installPackageScripts)
{
$package = $installPackageScript.Package
$packageMenuOption++
$packagesMenuOptionLines += ""
$packagesMenuOptionLines += ("; install package menu '{0}' option" -f $package.FullName)
$packagesMenuOptionLines += ("IF ""`$packagesmenu"" eq ""{0}""" -f $packageMenuOption)
$packagesMenuOptionLines += " ; skip package, if set to install. otherwise set package to install"
$packagesMenuOptionLines += (" IF EXISTS ""T:{0}""" -f $installPackageScript.Package.Id)
$packageName = $installPackageScript.Package.Name.ToLower()
# show package dependency warning, if package has dependencies
if ($dependencyPackageNamesIndex.ContainsKey($packageName))
{
$packagesMenuOptionLines += " set showdependencywarning ""0"""
$packagesMenuOptionLines += " set dependencypackagenames """""
# list selected package names that has dependencies to package
$dependencyPackageNames = @()
$dependencyPackageNames += $dependencyPackageNamesIndex.Get_Item($packageName)
foreach($dependencyPackageName in $dependencyPackageNames)
{
$dependencyPackage = $hstwb.Packages[$dependencyPackageName]
# add script lines to set show dependency warning, if dependency package is selected
$packagesMenuOptionLines += (" ; set show dependency warning, if package '{0}' is set to install" -f $dependencyPackage.FullName)
$packagesMenuOptionLines += (" IF EXISTS ""T:{0}""" -f $dependencyPackage.Id)
$packagesMenuOptionLines += " set showdependencywarning ""1"""
$packagesMenuOptionLines += " IF ""`$dependencypackagenames"" EQ """""
$packagesMenuOptionLines += (" set dependencypackagenames ""{0}""" -f $dependencyPackage.Name)
$packagesMenuOptionLines += " ELSE"
$packagesMenuOptionLines += (" set dependencypackagenames ""`$dependencypackagenames, {0}""" -f $dependencyPackage.Name)
$packagesMenuOptionLines += " ENDIF"
$packagesMenuOptionLines += " ENDIF"
}
# add script lines to show package dependency warning, if selected packages has dependencies to it
$packagesMenuOptionLines += " set skippackage ""1"""
$packagesMenuOptionLines += " IF `$showdependencywarning EQ 1 VAL"
$packagesMenuOptionLines += (" set skippackage ``RequestChoice ""Package dependency warning"" ""Warning! Package(s) '`$dependencypackagenames' has a*Ndependency to '{0}' and skipping it*Nmay cause issues when installing packages.*N*NAre you sure you want to skip*Npackage '{0}'?"" ""Yes|No""``" -f $installPackageScript.Package.Name)
$packagesMenuOptionLines += " ENDIF"
$packagesMenuOptionLines += " IF `$skippackage EQ 1 VAL"
$packagesMenuOptionLines += (" delete >NIL: ""T:{0}""" -f $installPackageScript.Package.Id)
$packagesMenuOptionLines += " ENDIF"
}
else
{
# deselect package, if no other packages has dependencies to it
$packagesMenuOptionLines += (" delete >NIL: ""T:{0}""" -f $installPackageScript.Package.Id)
}
$packagesMenuOptionLines += " ELSE"
$dependencyPackageNames = GetDependencyPackageNames $hstwb $installPackageScript.Package | ForEach-Object { $_.ToLower() }
foreach($dependencyPackageName in $dependencyPackageNames)
{
$dependencyPackage = $hstwb.Packages[$dependencyPackageName]
$packagesMenuOptionLines += (" ; Install dependency package '{0}'" -f $dependencyPackage.FullName)
$packagesMenuOptionLines += (" echo """" NOLINE >""T:{0}""" -f $dependencyPackage.Id)
}
$packagesMenuOptionLines += (" ; Install package '{0}'" -f $installPackageScript.Package.FullName)
$packagesMenuOptionLines += (" echo """" NOLINE >""T:{0}""" -f $installPackageScript.Package.Id)
$identicalContentIds = @()
if ($installPackageScript.Package.ContentIds)
{
$identicalContentIds += (Compare-Object -ReferenceObject ($contentIdPackages.keys | ForEach-Object { $_.ToString() }) -DifferenceObject $installPackageScript.Package.ContentIds -includeEqual -ExcludeDifferent).InputObject
}
# skip packages with identical content id's
if ($identicalContentIds.Count -gt 0)
{
$packages = $identicalContentIds | ForEach-Object { $contentIdPackages[$_] } | Where-Object { $_.Id -ne $installPackageScript.Package.Id -and $dependencyPackageNames -notcontains $_.Name } | Sort-Object -Property Id -Unique
foreach($package in $packages)
{
$packageIdenticalContentIds = @()
$packageIdenticalContentIds += (Compare-Object -ReferenceObject $installPackageScript.Package.ContentIds -DifferenceObject $package.ContentIds -includeEqual -ExcludeDifferent).InputObject | Sort-Object
$packagesMenuOptionLines += (" ; Skip package '{0}' with identical content id '{1}'" -f $package.FullName, ($packageIdenticalContentIds -join ', '))
$packagesMenuOptionLines += (" IF EXISTS ""T:{0}""" -f $package.Id)
$packagesMenuOptionLines += (" delete >NIL: ""T:{0}""" -f $package.Id)
$packagesMenuOptionLines += " ENDIF"
}
}
$packagesMenuOptionLines += " ENDIF"
$packagesMenuOptionLines += "ENDIF"
}
# show packages menu
$packagesMenuScriptLines += ""
$packagesMenuScriptLines += "set packagesmenu """""
$packagesMenuScriptLines += "set packagesmenu ""``RequestList TITLE=""Package installation"" LISTFILE=""T:packagesmenu"" WIDTH=640 LINES=24``"""
$packagesMenuScriptLines += "delete >NIL: T:packagesmenu"
$packagesMenuScriptLines += $packagesMenuOptionLines
$packagesMenuScriptLines += ""
$packagesMenuScriptLines += "SKIP BACK installpackagesmenu"
return $packagesMenuScriptLines
}
# build install packages script lines
function BuildInstallPackagesScriptLines($hstwb, $installPackages)
{
$installPackagesScriptLines = @()
$installPackagesScriptLines += ""
$installPackagesScriptLines += "echo """" >>SYS:hstwb-installer.log"
# append skip reset settings or install packages depending on installer mode
if (($hstwb.Settings.Installer.Mode -eq "BuildSelfInstall" -or $hstwb.Settings.Installer.Mode -eq "BuildPackageInstallation") -and $installPackages.Count -gt 0)
{
$installPackagesScriptLines += Get-Content (Join-Path $hstwb.Paths.AmigaPath -ChildPath "packages\S\Detect-AmigaOS")
$installPackagesScriptLines += ''
$installPackagesScriptLines += Get-Content (Join-Path $hstwb.Paths.AmigaPath -ChildPath "packages\S\SelectAssignDir")
$installPackagesScriptLines += ''
$installPackagesScriptLines += ''
}
# global assigns
$globalAssigns = $hstwb.Assigns.Get_Item('Global')
# build global package assigns
$addGlobalAssignScriptLines = @()
$removeGlobalAssignScriptLines = @()
foreach ($assignName in ($globalAssigns.keys | Sort-Object | Where-Object { $_ -notlike 'HstWBInstallerDir' }))
{
$assignId = CalculateMd5FromText (("{0}.{1}" -f 'Global', $assignName).ToLower())
$assignDir = $globalAssigns.Get_Item($assignName)
$addGlobalAssignScriptLines += BuildAddAssignScriptLines $assignId $assignName.ToUpper() $assignDir
# append ini file set for global assign, if installer mode is build self install or build package installation
if ($hstwb.Settings.Installer.Mode -eq "BuildSelfInstall" -or $hstwb.Settings.Installer.Mode -eq "BuildPackageInstallation")
{
$addGlobalAssignScriptLines += 'execute INSTALLDIR:S/IniFileSet "{0}" "{1}" "{2}" "$assigndir"' -f 'SYSTEMDIR:Prefs/HstWB-Installer/Packages/Assigns.ini', 'Global', $assignName
}
# skip removing systemdir assign
if ($assignName -like 'SystemDir')
{
continue
}
$removeGlobalAssignScriptLines += BuildRemoveAssignScriptLines $assignId $assignName.ToUpper() $assignDir
}
# build install package script lines
$installPackageScripts = @()
$installPackageScripts += BuildInstallPackageScriptLines $hstwb $installPackages
if (($hstwb.Settings.Installer.Mode -eq "BuildSelfInstall" -or $hstwb.Settings.Installer.Mode -eq "BuildPackageInstallation") -and $installPackages.Count -gt 0)
{
# build dependency package names index
$dependencyPackageNamesIndex = @{}
foreach ($packageName in $hstwb.Packages.Keys)
{
$package = $hstwb.Packages[$packageName]
if (!$package.Dependencies)
{
continue
}
foreach($dependencyPackageName in ($package.Dependencies | ForEach-Object { $_.Name.ToLower() }))
{
if ($dependencyPackageNamesIndex.ContainsKey($dependencyPackageName))
{
$dependencyPackageNames = $dependencyPackageNamesIndex.Get_Item($dependencyPackageName)
}
else
{
$dependencyPackageNames = @()
}
$dependencyPackageNames += $packageName
$dependencyPackageNamesIndex.Set_Item($dependencyPackageName, $dependencyPackageNames)
}
}
# amiga os versions
$amigaOsVersions = @('All')
$amigaOsVersions += GetSupportedAmigaOsVersions
$installPackagesScriptLines += ''
$installPackagesScriptLines += ''
$installPackagesScriptLines += '; verify amiga os'
$installPackagesScriptLines += '; ---------------'
$installPackagesScriptLines += 'LAB verifyamigaos'
$installPackagesScriptLines += ''
foreach ($amigaOsVersion in ($amigaOsVersions | Where-Object { $_ -notmatch 'All' }))
{
$installPackagesScriptLines += ('IF "$amigaosversion" EQ "{0}"' -f $amigaOsVersion)
$installPackagesScriptLines += ' SKIP resetpackages'
$installPackagesScriptLines += 'ENDIF'
}
$installPackagesScriptLines += ''
$installPackagesScriptLines += '; set amiga os version to ''All'''
$installPackagesScriptLines += 'set amigaosversion "All"'
$installPackagesScriptLines += ''
$installPackagesScriptLines += '; show auto-detect amiga os version warning'
$installPackagesScriptLines += 'RequestChoice "Auto-detect Amiga OS version" "WARNING: Package installation could not auto-detect*NAmiga OS version or the detected Amiga OS version*Ndoesn''t have any packages filtering.*NAmiga OS package filtering is therefore set*Nto all Amiga OS versions.*NThis means that not all packages may work*Ncorrectly with the Amiga OS installed.*NUse *"Select package filtering*" to*Nshow only packages that matches the*NAmiga OS installed." "OK"'
$installPackagesScriptLines += ''
$installPackagesScriptLines += 'SKIP resetpackages'
$packagesMenuScriptLines = @()
$resetPackagesLines = @()
foreach($installPackageScript in $installPackageScripts)
{
$resetPackagesLines += ("; Reset package '{0}'" -f $installPackageScript.Package.FullName)
$resetPackagesLines += ("IF EXISTS ""T:{0}""" -f $installPackageScript.Package.Id)
$resetPackagesLines += (" delete >NIL: ""T:{0}""" -f $installPackageScript.Package.Id)
$resetPackagesLines += "ENDIF"
}
$installPackagesScriptLines += ''
$installPackagesScriptLines += ''
$installPackagesScriptLines += '; Install packages menu'
$installPackagesScriptLines += '; ---------------------'