Repository navigation
Expand file tree
/
Copy pathsetup-windows.ps1
More file actions
2482 lines (2184 loc) · 99.2 KB
/
Copy pathsetup-windows.ps1
File metadata and controls
2482 lines (2184 loc) · 99.2 KB
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
<#
c64-3d-toolkit Windows installer / configuration assistant
Installer revision: r26 (2026-09-14)
Target toolkit release: read from VERSION
Security model:
- Python, Git, VICE and optional Blender are checked against exact package IDs in Microsoft's
WinGet `winget` source before any new WinGet install is attempted.
- Existing WinGet packages are kept by default; the user may explicitly request
an upgrade or same-version force-reinstall/repair attempt through WinGet.
- A new VICE installation requires an explicit Y/YES response; declining
offers an existing executable path or explains how to install it later.
- If WinGet package-status lookup fails, setup treats the status as UNKNOWN and
does not assume the component is absent or install a duplicate solely on that basis.
- 64tass is NEVER downloaded or installed automatically by this script.
- No MSYS2, pacman, Scoop, Chocolatey or other third-party package manager is
installed or invoked automatically.
- No proactive Internet connectivity probes are made. Network access occurs
when WinGet installs tools, or pip installs Python requirements after confirmation.
- User-supplied/configured .exe paths are validated without execution: the expected
filename must exist and the file must have a recognizable Windows PE executable header. This
does not prove publisher identity, authenticity or runtime correctness.
- VICE and 64tass are not executed during setup.
- c643d.py doctor/build is not executed during setup.
- Existing config/c643d.ini content is preserved; only confirmed `tass` and
`vice` values in [windows] are merged/updated.
#>
[CmdletBinding()]
param(
[Alias('h')][switch]$Help,
[string]$VicePath,
[string]$TassPath,
[switch]$FindTass
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$InstallerRevision = 'r26'
$ToolkitRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$TargetRelease = (Get-Content -LiteralPath (Join-Path $ToolkitRoot 'VERSION') -Raw).Trim()
if ($TargetRelease -notmatch '^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][0-9A-Za-z.-]+)?$') {
throw 'VERSION contains an invalid toolkit version.'
}
$ConfigDir = Join-Path $ToolkitRoot 'config'
$ConfigPath = Join-Path $ConfigDir 'c643d.ini'
# Keep package IDs, executable names, official locations and other external
# trust/dependency metadata together so release review and future updates have
# one obvious place to inspect.
$KnownLocations = @{
WinGet = @{
Download = 'https://aka.ms/getwinget'
}
Python = @{
WingetId = 'Python.Python.3.13'
Download = 'https://www.python.org/downloads/windows/'
}
Git = @{
WingetId = 'Git.Git'
Download = 'https://git-scm.com/download/win'
}
Blender = @{
WingetId = 'BlenderFoundation.Blender'
Download = 'https://www.blender.org/download/'
ExeName = 'blender.exe'
}
VICE = @{
PreferredWingetId = 'VICE-Team.VICE.GTK3'
WingetIds = @(
'VICE-Team.VICE.GTK3',
'VICE-Team.VICE.SDL2'
)
Download = 'https://vice-emu.sourceforge.io/'
ExeName = 'x64sc.exe'
}
Tass = @{
Project = 'https://sourceforge.net/projects/tass64/'
Binaries = 'https://sourceforge.net/projects/tass64/files/binaries/'
Source = 'https://sourceforge.net/projects/tass64/files/source/'
Manual = 'https://tass64.sourceforge.net/'
KnownVersion = '1.60.3243'
ExeName = '64tass.exe'
# Reference hashes recorded during v0.5.1 preparation from the manually
# downloaded 64tass 1.60.3243 SourceForge Windows package. A hash match
# identifies identical bytes; it is not a general safety guarantee.
KnownExeSha256 = '46920377fde73464068556b1a60f6e3794707966f31d45936741e618f78384b5'
KnownZipSha256 = '04bf54b7e975c13485f991a59a54e3cb909f9c439aab8288c4927951bdcce781'
}
}
function Write-Section([string]$Name) {
Write-Host ''
Write-Host "== $Name =="
}
function Write-FallbackHeader([string]$Label) {
Write-Host ''
Write-Host "--- Manual fallback: $Label ---" -ForegroundColor Yellow
}
function Refresh-ProcessPath {
$machine = [Environment]::GetEnvironmentVariable('Path', 'Machine')
$user = [Environment]::GetEnvironmentVariable('Path', 'User')
$parts = @($machine, $user) | Where-Object { $_ }
$env:Path = $parts -join ';'
}
function Strip-PathQuotes([string]$Value) {
if ($null -eq $Value) { return $null }
$v = [Environment]::ExpandEnvironmentVariables($Value.Trim())
if ($v.Length -ge 2) {
if (($v.StartsWith('"') -and $v.EndsWith('"')) -or
($v.StartsWith("'") -and $v.EndsWith("'"))) {
$v = $v.Substring(1, $v.Length - 2).Trim()
}
}
return $v
}
function Find-Executable {
param(
[Parameter(Mandatory=$true)][string[]]$Names,
[string[]]$ExtraPaths = @()
)
foreach ($path in $ExtraPaths) {
if (-not $path) { continue }
$resolved = Resolve-ExecutableInput -InputPath $path -ExpectedNames $Names
if ($resolved) { return $resolved }
}
foreach ($name in $Names) {
$cmd = Get-Command $name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
if ($cmd) { return $cmd.Source }
}
return $null
}
function Test-WindowsExecutableHeader {
param([Parameter(Mandatory=$true)][string]$Path)
try {
$stream = [System.IO.File]::Open(
$Path,
[System.IO.FileMode]::Open,
[System.IO.FileAccess]::Read,
[System.IO.FileShare]::ReadWrite
)
try {
if ($stream.Length -lt 64) { return $false }
if (($stream.ReadByte() -ne 0x4D) -or ($stream.ReadByte() -ne 0x5A)) {
return $false
}
# DOS header e_lfanew at offset 0x3c points at the PE signature.
[void]$stream.Seek(0x3C, [System.IO.SeekOrigin]::Begin)
$offsetBytes = New-Object byte[] 4
if ($stream.Read($offsetBytes, 0, 4) -ne 4) { return $false }
$peOffset = [BitConverter]::ToInt32($offsetBytes, 0)
if (($peOffset -lt 64) -or (($peOffset + 4) -gt $stream.Length)) { return $false }
[void]$stream.Seek($peOffset, [System.IO.SeekOrigin]::Begin)
$p0 = $stream.ReadByte()
$p1 = $stream.ReadByte()
$p2 = $stream.ReadByte()
$p3 = $stream.ReadByte()
return (($p0 -eq 0x50) -and ($p1 -eq 0x45) -and ($p2 -eq 0x00) -and ($p3 -eq 0x00))
}
finally {
$stream.Dispose()
}
}
catch {
return $false
}
}
function Test-ExecutableCandidate {
param(
[Parameter(Mandatory=$true)][string]$Path,
[Parameter(Mandatory=$true)][string[]]$ExpectedNames
)
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
return $false
}
$leaf = [System.IO.Path]::GetFileName($Path)
$expected = $false
foreach ($name in $ExpectedNames) {
if ($leaf -ieq $name) {
$expected = $true
break
}
}
if (-not $expected) {
return $false
}
if ([System.IO.Path]::GetExtension($leaf) -ieq '.exe') {
return (Test-WindowsExecutableHeader -Path $Path)
}
return $true
}
function Resolve-ExecutableInput {
param(
[string]$InputPath,
[Parameter(Mandatory=$true)][string[]]$ExpectedNames,
[string[]]$DirectoryRelatives = @()
)
$value = Strip-PathQuotes $InputPath
if (-not $value) { return $null }
# Allow a command name such as `64tass.exe` or `x64sc.exe` when it is in PATH.
if (($value -notmatch '[\\/]') -and ($value -notmatch '^[A-Za-z]:')) {
$cmd = Get-Command $value -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
if ($cmd -and (Test-ExecutableCandidate -Path $cmd.Source -ExpectedNames $ExpectedNames)) {
return $cmd.Source
}
}
if (Test-Path -LiteralPath $value -PathType Leaf) {
$resolvedLeaf = (Resolve-Path -LiteralPath $value).Path
if (Test-ExecutableCandidate -Path $resolvedLeaf -ExpectedNames $ExpectedNames) {
return $resolvedLeaf
}
return $null
}
if (Test-Path -LiteralPath $value -PathType Container) {
$relatives = New-Object System.Collections.Generic.List[string]
foreach ($name in $ExpectedNames) { [void]$relatives.Add($name) }
foreach ($rel in $DirectoryRelatives) { [void]$relatives.Add($rel) }
foreach ($relative in $relatives) {
$candidate = Join-Path $value $relative
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$resolvedCandidate = (Resolve-Path -LiteralPath $candidate).Path
if (Test-ExecutableCandidate -Path $resolvedCandidate -ExpectedNames $ExpectedNames) {
return $resolvedCandidate
}
}
}
}
return $null
}
function Find-WinGet {
return Find-Executable -Names @('winget.exe')
}
function Get-WindowsConfigState {
$state = [PSCustomObject]@{
SectionFound = $false
tass = $null
vice = $null
}
if (-not (Test-Path -LiteralPath $ConfigPath -PathType Leaf)) {
return $state
}
$inWindows = $false
foreach ($line in Get-Content -LiteralPath $ConfigPath) {
if ($line -match '^\s*\[([^]]+)\]\s*$') {
$inWindows = ($Matches[1] -ieq 'windows')
if ($inWindows) { $state.SectionFound = $true }
continue
}
if (-not $inWindows) { continue }
if ($line -match '^\s*(tass|vice)\s*=\s*(.*?)\s*$') {
$key = $Matches[1].ToLowerInvariant()
$value = $Matches[2]
if ($value -and ($value -notmatch '^\s*[#;]')) {
if ($key -eq 'tass') { $state.tass = Strip-PathQuotes $value } else { $state.vice = Strip-PathQuotes $value }
}
}
}
return $state
}
function Get-ConfiguredExecutableStatus {
param(
[string]$ConfiguredPath,
[Parameter(Mandatory=$true)][string[]]$ExpectedNames,
[string[]]$DirectoryRelatives = @()
)
if (-not $ConfiguredPath) {
return [PSCustomObject]@{ Present = $false; Valid = $false; Path = $null }
}
$resolved = Resolve-ExecutableInput -InputPath $ConfiguredPath -ExpectedNames $ExpectedNames -DirectoryRelatives $DirectoryRelatives
return [PSCustomObject]@{
Present = $true
Valid = [bool]$resolved
Path = $resolved
}
}
function Request-ExistingWindowsConfigMode {
param(
[Parameter(Mandatory=$true)]$ConfigState,
[Parameter(Mandatory=$true)]$ViceStatus,
[Parameter(Mandatory=$true)]$TassStatus
)
Write-Host ''
Write-Host 'Existing [windows] configuration found:' -ForegroundColor Cyan
if ($ConfigState.vice) {
$status = if ($ViceStatus.Valid) { 'VALID' } else { 'NOT FOUND' }
Write-Host " vice = $($ConfigState.vice) [$status]"
}
else {
Write-Host ' vice = <not set>'
}
if ($ConfigState.tass) {
$status = if ($TassStatus.Valid) { 'VALID' } else { 'NOT FOUND' }
Write-Host " tass = $($ConfigState.tass) [$status]"
}
else {
Write-Host ' tass = <not set>'
}
while ($true) {
Write-Host ''
Write-Host 'How should setup handle the existing Windows configuration?'
Write-Host ' K / KEEP = keep valid existing paths; only repair/fill missing or invalid entries'
Write-Host ' M / MODIFY = allow setup to search/select replacement paths'
Write-Host ' Q / QUIT = show the session summary, then quit'
$answer = Read-Host 'Choice [K]'
if ($null -eq $answer) { $answer = '' }
$answer = $answer.Trim()
if (($answer -eq '') -or ($answer -ieq 'k') -or ($answer -ieq 'keep')) { return 'Keep' }
if (($answer -ieq 'm') -or ($answer -ieq 'modify') -or ($answer -ieq 'change')) { return 'Modify' }
if (($answer -ieq 'q') -or ($answer -ieq 'quit') -or ($answer -ieq 'cancel') -or ($answer -ieq 'exit')) { return 'Quit' }
Write-Host 'Please enter K, M or Q.' -ForegroundColor Yellow
}
}
function Get-ProposedWindowsConfigChanges {
param(
[Parameter(Mandatory=$true)]$ConfigState,
[string]$ViceExe,
[string]$TassExe
)
# Plain arrays avoid a Windows PowerShell 5.1 generic-list return edge case.
$changes = @()
foreach ($item in @(
@{ Key = 'tass'; NewValue = $TassExe },
@{ Key = 'vice'; NewValue = $ViceExe }
)) {
if (-not $item.NewValue) { continue }
$oldValue = if ($item.Key -eq 'tass') { $ConfigState.tass } else { $ConfigState.vice }
if ($oldValue -ne $item.NewValue) {
$changes += [PSCustomObject]@{
Key = $item.Key
OldValue = $oldValue
NewValue = $item.NewValue
}
}
}
return $changes
}
function Confirm-WindowsConfigChanges {
param([Parameter(Mandatory=$true)][object[]]$Changes)
if ($Changes.Count -eq 0) { return 'NoChanges' }
Write-Host ''
Write-Host 'Proposed changes to config\c643d.ini [windows]:' -ForegroundColor Cyan
foreach ($change in $Changes) {
$old = if ($change.OldValue) { $change.OldValue } else { '<not set>' }
Write-Host " $($change.Key):"
Write-Host " current: $old"
Write-Host " new: $($change.NewValue)"
}
while ($true) {
Write-Host ''
Write-Host 'Apply these [windows] configuration changes?'
Write-Host ' Y / YES = write the changes'
Write-Host ' N / NO = leave c643d.ini unchanged'
Write-Host ' Q / QUIT = show the session summary, then quit'
$answer = Read-Host 'Choice [Y]'
if ($null -eq $answer) { $answer = '' }
$answer = $answer.Trim()
if (($answer -eq '') -or ($answer -ieq 'y') -or ($answer -ieq 'yes')) { return 'Apply' }
if (($answer -ieq 'n') -or ($answer -ieq 'no')) { return 'Leave' }
if (($answer -ieq 'q') -or ($answer -ieq 'quit') -or ($answer -ieq 'cancel') -or ($answer -ieq 'exit')) { return 'Quit' }
Write-Host 'Please enter Y, N or Q.' -ForegroundColor Yellow
}
}
function Write-SetupSessionSummary {
param(
[string]$PythonExe,
[string]$GitExe,
[string]$ViceExe,
[string]$TassExe,
[string]$PythonAction = 'not processed',
[string]$GitAction = 'not processed',
[string]$ViceAction = 'not processed',
[string]$TassAction = 'not processed',
[Parameter(Mandatory=$true)]$OriginalConfig
)
Write-Section 'Setup changes so far'
Write-Host 'Python 3'
Write-Host " Action: $PythonAction"
if ($PythonExe) { Write-Host " Path: $PythonExe" } else { Write-Host ' Path: <not selected/found>' }
Write-Host ''
Write-Host 'Git'
Write-Host " Action: $GitAction"
if ($GitExe) { Write-Host " Path: $GitExe" } else { Write-Host ' Path: <not selected/found>' }
Write-Host ''
Write-Host 'Blender (optional, highly recommended)'
Write-Host " Action: $blenderAction"
if ($blender) { Write-Host " Path: $blender" } else { Write-Host ' Path: <not installed/found>' }
Write-Host ''
Write-Host 'VICE'
Write-Host " Action: $ViceAction"
if ($ViceExe) { Write-Host " Path: $ViceExe" } else { Write-Host ' Path: <not selected/found>' }
Write-Host ''
Write-Host '64tass'
Write-Host " Action: $TassAction"
if ($TassExe) { Write-Host " Path: $TassExe" } else { Write-Host ' Path: <not selected/found>' }
Write-Host ''
Write-Host 'Configuration file'
Write-Host " Path: $ConfigPath"
if (Test-Path -LiteralPath $ConfigPath -PathType Leaf) {
Write-Host ' Current state: exists'
}
else {
Write-Host ' Current state: not created'
}
# Pending means not yet reflected in the actual INI at the moment the
# summary is printed. This keeps success/error summaries truthful even if
# configuration has already been written earlier in the run.
$currentConfig = Get-WindowsConfigState
$pending = @(Get-ProposedWindowsConfigChanges -ConfigState $currentConfig -ViceExe $ViceExe -TassExe $TassExe)
if ($pending.Count -gt 0) {
Write-Host ''
Write-Host 'Pending valid [windows] configuration discovered during this run:' -ForegroundColor Cyan
foreach ($change in $pending) {
$old = if ($change.OldValue) { $change.OldValue } else { '<not set>' }
Write-Host " $($change.Key):"
Write-Host " current: $old"
Write-Host " new: $($change.NewValue)"
}
}
else {
Write-Host ' Pending changes: none'
}
return $pending
}
function Invoke-QuitWithSummary {
param(
[string]$PythonExe,
[string]$GitExe,
[string]$ViceExe,
[string]$TassExe,
[string]$PythonAction,
[string]$GitAction,
[string]$ViceAction,
[string]$TassAction,
[Parameter(Mandatory=$true)]$OriginalConfig
)
$pending = @(Write-SetupSessionSummary `
-PythonExe $PythonExe -GitExe $GitExe -ViceExe $ViceExe -TassExe $TassExe `
-PythonAction $PythonAction -GitAction $GitAction -ViceAction $ViceAction -TassAction $TassAction `
-OriginalConfig $OriginalConfig)
Write-Host ''
Write-Host 'NOTE: software already installed/upgraded/reinstalled by WinGet will NOT be undone by leaving setup.' -ForegroundColor Yellow
Write-Host 'The choice below controls only whether valid discovered VICE/64tass paths are written to config\c643d.ini.'
if ($pending.Count -gt 0) {
while ($true) {
Write-Host ''
Write-Host 'Save the valid configuration discovered so far before leaving setup?'
Write-Host ' Y / SAVE = write the pending [windows] tass/vice paths'
Write-Host ' N / DISCARD = leave c643d.ini unchanged'
$answer = Read-Host 'Choice [N]'
if ($null -eq $answer) { $answer = '' }
$answer = $answer.Trim()
if (($answer -ieq 'y') -or ($answer -ieq 'yes') -or ($answer -ieq 'save')) {
[void](Update-WindowsConfig -ViceExe $ViceExe -TassExe $TassExe)
Write-Host 'Valid discovered configuration was saved before leaving setup.'
return
}
if (($answer -eq '') -or ($answer -ieq 'n') -or ($answer -ieq 'no') -or ($answer -ieq 'discard')) {
Write-Host 'Configuration was not changed.' -ForegroundColor Yellow
return
}
Write-Host 'Please enter Y/SAVE or N/DISCARD.' -ForegroundColor Yellow
}
}
Write-Host 'There are no pending valid tool-path changes to save.'
}
function Write-SetupHelpHint {
Write-Host 'Setup help:'
Write-Host ' .\setup-windows.cmd -Help'
}
function Show-InstallerHelp {
Write-Host 'c64-3d-toolkit Windows setup help'
Write-Host "target release: v$TargetRelease"
Write-Host "installer revision: $InstallerRevision"
Write-Host ''
Write-Host 'Usage:'
Write-Host ' .\setup-windows.cmd'
Write-Host ' .\setup-windows.cmd -Help'
Write-Host ' .\setup-windows.cmd -VicePath "C:\path\to\VICE\bin\x64sc.exe"'
Write-Host ' .\setup-windows.cmd -TassPath "C:\path\to\64tass.exe"'
Write-Host ' .\setup-windows.cmd -TassPath "C:\path\to\64tass-directory"'
Write-Host ' .\setup-windows.cmd -FindTass'
Write-Host ''
Write-Host 'What setup manages:'
Write-Host ' - Python 3, Git and VICE: exact WinGet package detection plus install/upgrade/reinstall support.'
Write-Host ' - A new VICE installation requires Y/YES. N/NO (default) lets you select an existing copy or install it yourself later.'
Write-Host ' - Blender: optional but highly recommended; if absent, setup asks before installing BlenderFoundation.Blender.'
Write-Host ' - 64tass: manual acquisition only; setup never downloads or executes it.'
Write-Host ' 64tass is REQUIRED to assemble generated data into a runnable .prg; only --no-assemble works without it.'
Write-Host ' Existing valid 64tass config gets its own K/KEEP, C/CHANGE or Q/QUIT prompt.'
Write-Host ' E/ENTER accepts either 64tass.exe itself or the directory containing it.'
Write-Host ' Manual/direct paths are validated and hashed first, then require Y/YES confirmation before use.'
Write-Host ' F/FIND or -FindTass searches common local locations only.'
Write-Host ' D/DRIVE scans one chosen drive. At the drive prompt, any drive letter is valid; blank Enter returns.'
Write-Host ' Once a drive scan has started, Q or Esc stops it; any results found so far are shown for selection.'
Write-Host ' - config\c643d.ini: only confirmed tass/vice values in [windows] are merged.'
Write-Host ' - Q/QUIT prints a session summary; pending valid tass/vice paths can be saved or discarded before exit.'
Write-Host ' - Fatal setup errors also attempt the same summary + save/discard prompt before returning exit code 1.'
Write-Host ''
Write-Host 'Adding 64tass later:'
Write-Host ' 1. Download/build and extract a 64tass.exe that you have chosen to trust.'
Write-Host " Official Windows binaries: $($KnownLocations.Tass.Binaries)"
Write-Host ' 2. Rerun setup with the executable OR its containing directory:'
Write-Host ' .\setup-windows.cmd -TassPath "C:\Tools\64tass\64tass.exe"'
Write-Host ' .\setup-windows.cmd -TassPath "C:\Tools\64tass"'
Write-Host ' or simply run .\setup-windows.cmd and use E/ENTER at the 64tass prompt.'
Write-Host ' 3. Setup checks that the expected 64tass.exe exists and has a recognizable Windows PE header.'
Write-Host ' It does NOT execute the file and cannot prove its publisher/authenticity or runtime behavior.'
Write-Host ' Setup also computes SHA-256. A KNOWN HASH MATCH identifies byte-for-byte equality with the'
Write-Host " 64tass $($KnownLocations.Tass.KnownVersion) Windows executable reference recorded during v0.5.1 preparation."
Write-Host ' 4. Setup shows the proposed config change and asks before writing it. The resulting entry is:'
Write-Host ' [windows]'
Write-Host ' tass = C:\Tools\64tass\64tass.exe'
Write-Host ''
Write-Host 'VICE can be added/repaired later the same way with -VicePath.'
Write-Host ''
Write-Host 'Clean cancellation:'
Write-Host ' Use Q / QUIT if you want the setup session summary and save/discard prompt.'
Write-Host ' Ctrl+C is handled by the surrounding shell and may terminate the batch wrapper immediately.'
Write-Host ''
Write-Host 'Optional manual toolkit validation after configuration (executes the toolchain):'
Write-Host ' py -3 .\c643d.py doctor'
}
function Show-WinGetFallback {
Write-FallbackHeader 'WinGet / App Installer'
Write-Host 'WinGet is provided by Microsoft App Installer on current Windows 11 systems.'
Write-Host 'Official Microsoft installer/update route:'
Write-Host " $($KnownLocations.WinGet.Download)"
Write-Host 'After installing/updating App Installer, open a new PowerShell window and rerun:'
Write-Host ' .\setup-windows.cmd'
Write-SetupHelpHint
}
function Show-WinGetOperationFallback {
param(
[Parameter(Mandatory=$true)][string]$Component,
[Parameter(Mandatory=$true)][string]$Operation,
[Parameter(Mandatory=$true)][string]$PackageId
)
Write-FallbackHeader "$Component / WinGet"
Write-Host "WinGet could not complete the requested $Operation for:"
Write-Host " $PackageId"
Write-Host 'This can mean the WinGet source is unavailable/blocked, the package ID is unavailable,'
Write-Host 'or the vendor installer itself failed. Setup will not silently switch package sources.'
Write-Host 'Check the WinGet output above and your firewall/proxy/VPN policy before retrying.'
Write-SetupHelpHint
}
function Get-WinGetPackageState {
param(
[Parameter(Mandatory=$true)][string]$Id
)
$state = [PSCustomObject]@{
Id = $Id
Status = 'Unknown'
Installed = $false
InstalledVersion = $null
AvailableVersion = $null
QueryExitCode = $null
QueryOutput = $null
}
$winget = Find-WinGet
if (-not $winget) {
return $state
}
$lines = @(& $winget list --exact --id $Id --source winget --accept-source-agreements 2>&1)
$exitCode = $LASTEXITCODE
$output = ($lines | ForEach-Object { "$_" }) -join [Environment]::NewLine
$state.QueryExitCode = $exitCode
$state.QueryOutput = $output
if ($output -match '(?i)No installed package found matching input criteria') {
$state.Status = 'NotInstalled'
return $state
}
foreach ($line in $lines) {
$text = "$line"
# Strip common ANSI terminal sequences before parsing the WinGet table.
$clean = [Regex]::Replace($text, "$([char]27)\[[0-9;?]*[ -/]*[@-~]", '')
$idIndex = $clean.IndexOf($Id, [System.StringComparison]::OrdinalIgnoreCase)
if ($idIndex -lt 0) {
continue
}
$afterId = $clean.Substring($idIndex + $Id.Length).Trim()
if (-not $afterId) {
continue
}
$tokens = @($afterId -split '\s+' | Where-Object { $_ })
if ($tokens.Count -lt 1) {
continue
}
# The exact-ID row begins with the installed version after the package ID.
# Depending on terminal width/WinGet version, the Available and Source
# columns may be omitted. Do not require the trailing `winget` token.
if ($tokens[0] -match '^\d[0-9A-Za-z._+-]*$') {
$state.Status = 'Installed'
$state.Installed = $true
$state.InstalledVersion = $tokens[0]
if (($tokens.Count -ge 2) -and ($tokens[1] -match '^\d[0-9A-Za-z._+-]*$')) {
$state.AvailableVersion = $tokens[1]
}
return $state
}
}
if (($exitCode -eq 0) -and ($output -match [Regex]::Escape($Id))) {
# Exact package appears to be registered, but the human-readable table
# format was not recognized. Never downgrade this to "missing".
$state.Status = 'Installed'
$state.Installed = $true
return $state
}
return $state
}
function Write-WinGetPackageState {
param(
[Parameter(Mandatory=$true)][string]$Label,
[Parameter(Mandatory=$true)]$State
)
if ($State.Status -eq 'Installed') {
$version = if ($State.InstalledVersion) { $State.InstalledVersion } else { '<version not parsed>' }
Write-Host "WinGet package: $($State.Id) [INSTALLED $version]"
if ($State.AvailableVersion) {
Write-Host "WinGet reports an available version: $($State.AvailableVersion)"
}
return
}
if ($State.Status -eq 'NotInstalled') {
Write-Host "WinGet package: $($State.Id) [not installed]"
return
}
Write-Host "WinGet package: $($State.Id) [STATUS UNKNOWN]" -ForegroundColor Yellow
Write-Host 'WinGet package-state lookup could not be completed. Setup will not infer that the package is missing.'
}
function Request-WinGetInstalledAction {
param(
[Parameter(Mandatory=$true)][string]$Label,
[Parameter(Mandatory=$true)]$State
)
while ($true) {
Write-Host ''
Write-Host "$Label is registered as an installed WinGet package:"
Write-Host " $($State.Id)"
if ($State.InstalledVersion) {
Write-Host " installed: $($State.InstalledVersion)"
}
if ($State.AvailableVersion) {
Write-Host " available: $($State.AvailableVersion)"
}
Write-Host ''
Write-Host 'What should setup do?'
Write-Host ' K / KEEP = leave the installed package alone (default)'
Write-Host ' U / UPGRADE = ask WinGet to upgrade this exact package if an upgrade is available'
if ($State.InstalledVersion) {
Write-Host ' R / REINSTALL = force-reinstall the same installed version through this exact package ID'
}
else {
Write-Host ' R / REINSTALL = force-reinstall via this exact package ID (version could not be parsed)'
}
Write-Host ' Q / QUIT = show the session summary, then quit'
$answer = Read-Host 'Choice [K]'
if ($null -eq $answer) { $answer = '' }
$answer = $answer.Trim()
if (($answer -eq '') -or ($answer -ieq 'k') -or ($answer -ieq 'keep')) { return 'Keep' }
if (($answer -ieq 'u') -or ($answer -ieq 'upgrade') -or ($answer -ieq 'update')) { return 'Upgrade' }
if (($answer -ieq 'r') -or ($answer -ieq 'reinstall') -or ($answer -ieq 'repair')) { return 'Reinstall' }
if (($answer -ieq 'q') -or ($answer -ieq 'quit') -or ($answer -ieq 'cancel') -or ($answer -ieq 'exit')) { return 'Quit' }
Write-Host 'Please enter K, U, R or Q.' -ForegroundColor Yellow
}
}
function Invoke-WinGetPackageOperation {
param(
[Parameter(Mandatory=$true)][ValidateSet('Install','Upgrade','Reinstall')][string]$Operation,
[Parameter(Mandatory=$true)][string]$Id,
[Parameter(Mandatory=$true)][string]$Label,
[string]$Version
)
$winget = Find-WinGet
if (-not $winget) {
Show-WinGetFallback
throw "WinGet is required for the requested $Label operation."
}
switch ($Operation) {
'Install' {
Write-Host "Installing $Label ($Id) with WinGet..."
& $winget install --exact --id $Id --source winget --accept-package-agreements --accept-source-agreements
}
'Upgrade' {
Write-Host "Checking/upgrading $Label ($Id) with WinGet..."
& $winget upgrade --exact --id $Id --source winget --accept-package-agreements --accept-source-agreements
}
'Reinstall' {
if ($Version) {
Write-Host "Force-reinstalling $Label ($Id), version $Version, with WinGet..."
& $winget install --exact --id $Id --version $Version --source winget --accept-package-agreements --accept-source-agreements --force
}
else {
Write-Host "Force-reinstalling $Label ($Id) with WinGet; installed version was not parsed..."
& $winget install --exact --id $Id --source winget --accept-package-agreements --accept-source-agreements --force
}
}
}
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
Show-WinGetOperationFallback -Component $Label -Operation $Operation.ToLowerInvariant() -PackageId $Id
throw "WinGet $Operation failed for $Label (exit code $exitCode)."
}
Refresh-ProcessPath
}
function Invoke-WinGetInstalledMaintenance {
param(
[Parameter(Mandatory=$true)][string]$Label,
[Parameter(Mandatory=$true)]$State
)
$action = Request-WinGetInstalledAction -Label $Label -State $State
if ($action -eq 'Quit') {
return 'Quit'
}
if ($action -eq 'Keep') {
return 'Keep'
}
try {
if ($action -eq 'Reinstall') {
Invoke-WinGetPackageOperation -Operation Reinstall -Id $State.Id -Label $Label -Version $State.InstalledVersion
}
else {
Invoke-WinGetPackageOperation -Operation Upgrade -Id $State.Id -Label $Label
}
return $action
}
catch {
Write-Host "$Label WinGet $action failed: $($_.Exception.Message)" -ForegroundColor Yellow
Write-Host 'The existing installation/configuration will be preserved where possible.'
return 'Failed'
}
}
function Install-WinGetPackage {
param(
[Parameter(Mandatory=$true)][string]$Id,
[Parameter(Mandatory=$true)][string]$Label
)
Invoke-WinGetPackageOperation -Operation Install -Id $Id -Label $Label
}
function Show-PythonFallback {
Write-FallbackHeader 'Python 3'
Write-Host 'Official Python for Windows:'
Write-Host " $($KnownLocations.Python.Download)"
Write-Host 'Install Python 3, then rerun:'
Write-Host ' .\setup-windows.cmd'
Write-SetupHelpHint
}
function Show-GitFallback {
Write-FallbackHeader 'Git'
Write-Host 'Official Git for Windows:'
Write-Host " $($KnownLocations.Git.Download)"
Write-Host 'Install Git, then rerun:'
Write-Host ' .\setup-windows.cmd'
Write-SetupHelpHint
}
function Show-BlenderFallback {
Write-FallbackHeader 'Blender (optional, highly recommended)'
Write-Host 'Blender is required only for animated .blend scene builds; classic OBJ/SVG/procedural builds still work without it.'
Write-Host 'Official Blender download:'
Write-Host " $($KnownLocations.Blender.Download)"
Write-Host 'Preferred Windows install command:'
Write-Host " winget install --exact --id $($KnownLocations.Blender.WingetId) --source winget"
}
function Request-BlenderInstall {
while ($true) {
Write-Host ''
Write-Host 'Blender was not found. Installing it is HIGHLY RECOMMENDED for the authored 3-D scene/camera pipeline.' -ForegroundColor Cyan
Write-Host 'Blender remains optional for the existing OBJ, SVG and procedural workflows.'
Write-Host 'Install Blender now through the exact WinGet package BlenderFoundation.Blender?'
Write-Host ' Y / YES = install Blender (default)'
Write-Host ' N / NO = skip Blender and continue setup'
$answer = Read-Host 'Choice [Y]'
if ($null -eq $answer) { $answer = '' }
$answer = $answer.Trim()
if (($answer -eq '') -or ($answer -ieq 'y') -or ($answer -ieq 'yes')) { return $true }
if (($answer -ieq 'n') -or ($answer -ieq 'no') -or ($answer -ieq 'skip')) { return $false }
Write-Host 'Please enter Y or N.' -ForegroundColor Yellow
}
}
function Request-ViceInstall {
Write-Host ''
Write-Host 'VICE was not found. It provides the C64 emulator and the cartconv cartridge-building utility.' -ForegroundColor Cyan
Write-Host "Install VICE now through WinGet package $($KnownLocations.VICE.PreferredWingetId)?"
Write-Host 'If you decline, select an existing x64sc.exe below or install VICE yourself later.'
while ($true) {
Write-Host ' Y / YES = install VICE'
Write-Host ' N / NO = do not install; select an existing copy or skip (default)'
Write-Host ' Q / QUIT = show the session summary, then quit'
$answer = Read-Host 'Choice [N]'
if ($null -eq $answer) { $answer = '' }
$answer = $answer.Trim()
if (($answer -ieq 'y') -or ($answer -ieq 'yes')) { return 'Install' }
if (($answer -eq '') -or ($answer -ieq 'n') -or ($answer -ieq 'no') -or ($answer -ieq 'skip')) { return 'Manual' }
if (($answer -ieq 'q') -or ($answer -ieq 'quit') -or ($answer -ieq 'cancel') -or ($answer -ieq 'exit')) { return 'Quit' }
Write-Host 'Please enter Y, N or Q.' -ForegroundColor Yellow
}
}
function Show-ViceFallback {
Write-FallbackHeader 'VICE'
Write-Host 'Official VICE project/downloads:'
Write-Host " $($KnownLocations.VICE.Download)"
Write-Host 'If you already have VICE installed or extracted, enter its x64sc.exe path below.'
Write-Host 'You may enter either the full x64sc.exe path or the VICE directory.'
Write-Host 'Command-line override for later runs:'
Write-Host ' .\setup-windows.cmd -VicePath "C:\path\to\VICE\bin\x64sc.exe"'
Write-SetupHelpHint
}
function Show-64tassFallback {
Write-FallbackHeader '64tass'
Write-Host '64tass was not found. This installer deliberately does NOT download or install it automatically.' -ForegroundColor Yellow
Write-Host '64tass is REQUIRED to assemble a runnable .prg. You may skip it temporarily, but normal builds cannot finish until it is configured.' -ForegroundColor Yellow
Write-Host 'Only table/source generation with --no-assemble can run without 64tass.'
Write-Host ''
Write-Host 'Easiest Windows option:'
Write-Host ' 1. Download the current Windows binary yourself from:'
Write-Host " $($KnownLocations.Tass.Binaries)"
Write-Host ' 2. Extract it somewhere you control.'
Write-Host ' 3. Use E/ENTER to enter the .exe or its directory, F/FIND for common locations,'
Write-Host ' or D/DRIVE to choose one whole drive. Blank returns before scanning; Q/Esc cancels once scanning.'
Write-Host ' You can also skip it now and add it later:'
Write-Host ' .\setup-windows.cmd -TassPath "C:\Tools\64tass\64tass.exe"'
Write-Host ' .\setup-windows.cmd -TassPath "C:\Tools\64tass"'
Write-Host ''
Write-Host 'Official upstream locations:'
Write-Host " Project: $($KnownLocations.Tass.Project)"
Write-Host " Windows binaries: $($KnownLocations.Tass.Binaries)"
Write-Host " Source archives: $($KnownLocations.Tass.Source)"
Write-Host " Manual/homepage: $($KnownLocations.Tass.Manual)"
Write-Host ''
Write-Host "Current upstream release recorded for v0.5.1 preparation: $($KnownLocations.Tass.KnownVersion)"
Write-Host 'The project has a documented history of antivirus false positives on MinGW-built Windows binaries.'
Write-Host 'Review/verify any prebuilt executable according to your own security policy before running it.'
Write-Host ''
Write-Host 'Setup validation is deliberately non-executing:'
Write-Host ' - expected filename must be 64tass.exe'
Write-Host ' - the file must exist and have a recognizable Windows PE executable header'
Write-Host ' - SHA-256 is computed; a known hash match identifies identical bytes to the recorded reference'
Write-Host ' - a hash match does NOT by itself prove publisher identity/safety or runtime correctness'
Write-Host ''
Write-Host 'Manual alternatives:'
Write-Host ' - Build 64tass yourself from the official source archive.'
Write-Host ' - If you intentionally use MSYS2, its official 64tass package is another manual route.'
Write-Host ' This installer will NOT install MSYS2 or invoke pacman.'
Write-Host ''
Write-Host 'When a valid path is selected, setup shows the proposed [windows] tass change and asks before writing config\c643d.ini.'
Write-SetupHelpHint
}
function Get-Sha256String {
param([Parameter(Mandatory=$true)][string]$Path)
try {
return (Get-FileHash -LiteralPath $Path -Algorithm SHA256 -ErrorAction Stop).Hash.ToLowerInvariant()
}
catch {
return $null
}
}
function Get-64tassHashInfo {
param([Parameter(Mandatory=$true)][string]$Path)
$hash = Get-Sha256String -Path $Path
$known = $false
if ($hash -and ($hash -ieq $KnownLocations.Tass.KnownExeSha256)) {
$known = $true
}
return [PSCustomObject]@{
Path = $Path
Sha256 = $hash
KnownMatch = $known
}
}
function Write-64tassHashInfo {
param([Parameter(Mandatory=$true)][string]$Path)
$info = Get-64tassHashInfo -Path $Path
Write-Host '64tass SHA-256:'
if ($info.Sha256) {
Write-Host " $($info.Sha256)"
}
else {
Write-Host ' <could not calculate>' -ForegroundColor Yellow
return
}
if ($info.KnownMatch) {
Write-Host "KNOWN HASH MATCH: byte-for-byte match with the 64tass $($KnownLocations.Tass.KnownVersion)"
Write-Host 'Windows executable reference recorded from the manually obtained SourceForge package during v0.5.1 preparation.'
Write-Host 'This hash match identifies identical bytes; it is not a general safety/authenticity guarantee.'
}
else {
Write-Host 'UNKNOWN HASH: the file does not match the single 64tass Windows executable reference known to this installer.' -ForegroundColor Yellow
Write-Host 'That does not mean the file is malicious; it may be another release or a locally built executable.'
}
}