Import Amiga applications and desktop tools
This commit is contained in:
commit
1c144c9a3c
347 files changed
+423483
No files matched your search
@@ -0,0 +1,48 @@
|
||||
$ErrorActionPreference='Stop'
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$root='C:\Amiga'
|
||||
$backup='C:\Amiga\backup-riparazione-20261030\drawer-prima-riordino.zip'
|
||||
if(Test-Path -LiteralPath $backup){throw 'Backup già presente: non sovrascrivo'}
|
||||
$files=@(foreach($volume in @('HD0','Share','WHDLoad')){Get-ChildItem -LiteralPath (Join-Path $root $volume) -Recurse -File -Filter '*.info'})
|
||||
$zip=[IO.Compression.ZipFile]::Open($backup,'Create')
|
||||
try{foreach($f in $files){[IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip,$f.FullName,$f.FullName.Substring($root.Length+1).Replace('\','/'))|Out-Null}}finally{$zip.Dispose()}
|
||||
function Put16($b,$o,$v){$b[$o]=[byte](($v -shr 8)-band 255);$b[$o+1]=[byte]($v-band 255)}
|
||||
function Put32($b,$o,$v){$b[$o]=[byte](($v-shr 24)-band 255);$b[$o+1]=[byte](($v-shr 16)-band 255);$b[$o+2]=[byte](($v-shr 8)-band 255);$b[$o+3]=[byte]($v-band 255)}
|
||||
$records=@(foreach($f in $files){
|
||||
$b=[IO.File]::ReadAllBytes($f.FullName)
|
||||
if($b.Length-lt 78 -or $b[0]-ne 227 -or $b[1]-ne 16){continue}
|
||||
$object=$f.FullName.Substring(0,$f.FullName.Length-5)
|
||||
$isDisk=$f.Name-ieq 'Disk.info'
|
||||
if(-not $isDisk -and -not(Test-Path -LiteralPath $object)){continue}
|
||||
$drawerPointer=($b[66]-bor $b[67]-bor $b[68]-bor $b[69])-ne 0
|
||||
[pscustomobject]@{Path=$f.FullName;Name=[IO.Path]::GetFileName($object);Parent=$f.DirectoryName;IsDisk=$isDisk;IsDirectory=(Test-Path -LiteralPath $object -PathType Container);Bytes=$b;Original=$b.Clone();Drawer=($drawerPointer -and $b.Length-ge 134 -and $b[48]-in @(1,2));W=($b[12]*256+$b[13]);H=($b[14]*256+$b[15]);Changed=$false}
|
||||
})
|
||||
$leftOut=@{}
|
||||
foreach($v in @('HD0','Share','WHDLoad')){
|
||||
$bp=Join-Path $root "$v\.backdrop"
|
||||
if(Test-Path -LiteralPath $bp){foreach($line in [IO.File]::ReadAllLines($bp)){if($line.StartsWith(':')){$leftOut[(Join-Path $root ($v+'\'+$line.Substring(1).Replace('/','\')+'.info'))]=$true}}}
|
||||
}
|
||||
$groups=0
|
||||
foreach($group in ($records|Where-Object {-not $_.IsDisk -and -not $leftOut.ContainsKey($_.Path)}|Group-Object Parent)){
|
||||
$ordered=@($group.Group|Sort-Object @{Expression={-not $_.IsDirectory}},Name)
|
||||
$cellW=150;$cellH=88
|
||||
foreach($r in $ordered){$cellW=[Math]::Max($cellW,[Math]::Max($r.Name.Length*8+24,$r.W+24));$cellH=[Math]::Max($cellH,$r.H+30)}
|
||||
$columns=[Math]::Max(1,[Math]::Floor(940/$cellW));$i=0
|
||||
foreach($r in $ordered){Put32 $r.Bytes 58 (20+($i%$columns)*$cellW);Put32 $r.Bytes 62 (14+[Math]::Floor($i/$columns)*$cellH);$r.Changed=$true;$i++}
|
||||
$groups++
|
||||
}
|
||||
$windows=0
|
||||
foreach($r in $records){if($r.Drawer){
|
||||
Put16 $r.Bytes 78 80;Put16 $r.Bytes 80 55;Put16 $r.Bytes 82 1000;Put16 $r.Bytes 84 720
|
||||
Put32 $r.Bytes 126 0;Put32 $r.Bytes 130 0
|
||||
$r.Changed=$true;$windows++
|
||||
}}
|
||||
$allowed=@(58..65)+@(78..85)+@(126..133)
|
||||
$changed=0
|
||||
foreach($r in $records|Where-Object Changed){
|
||||
for($i=0;$i-lt $r.Bytes.Length;$i++){if($r.Bytes[$i]-ne $r.Original[$i] -and $i-notin $allowed){throw "Modifica fuori dai campi posizione: $($r.Path), $i"}}
|
||||
[IO.File]::WriteAllBytes($r.Path,$r.Bytes)
|
||||
if(-not [Linq.Enumerable]::SequenceEqual([byte[]][IO.File]::ReadAllBytes($r.Path),[byte[]]$r.Bytes)){throw "Verifica scrittura fallita: $($r.Path)"}
|
||||
$changed++
|
||||
}
|
||||
[pscustomobject]@{Backup=$backup;BackupIcons=$files.Count;OrderedDirectories=$groups;SavedWindows=$windows;UpdatedIcons=$changed}|ConvertTo-Json
|
||||
Reference in new issue
Block a user