$ErrorActionPreference = "Stop" $root = $PSScriptRoot $ver = ([xml](Get-Content (Join-Path $root "app\UltraParadise.Linux.csproj"))).Project.PropertyGroup[0].Version $env:DOTNET_CLI_TELEMETRY_OPTOUT = "1"; $env:DOTNET_NOLOGO = "1" $appName = "Ultra Paradise CU-Trainer" $bundleId = "casualexpie.ultraparadise.cutrainer" $exe = "UltraParadiseCUTrainer" & powershell -ExecutionPolicy Bypass -File (Join-Path $root "plugin\build.ps1") if ($LASTEXITCODE -ne 0) { throw "plugin build failed" } $signer = Join-Path $root "tools\macsign\bin\macsign.exe" Push-Location (Join-Path $root "tools\macsign") try { & dotnet build -c Release -o (Join-Path $root "tools\macsign\bin") | Out-Null; if ($LASTEXITCODE -ne 0) { throw "signer build failed" } } finally { Pop-Location } Add-Type -AssemblyName System.Drawing function New-Icns([string]$src, [string]$out) { $img = [System.Drawing.Image]::FromFile($src) $ms = New-Object System.IO.MemoryStream $types = @(@("icp4", 16), @("icp5", 32), @("icp6", 64), @("ic07", 128), @("ic08", 256), @("ic09", 512), @("ic10", 1024)) $chunks = @() foreach ($t in $types) { $s = $t[1] $bmp = New-Object System.Drawing.Bitmap $s, $s $g = [System.Drawing.Graphics]::FromImage($bmp) $g.InterpolationMode = if ($s -ge $img.Width) { "NearestNeighbor" } else { "HighQualityBicubic" } $g.PixelOffsetMode = "Half" $g.DrawImage($img, 0, 0, $s, $s) $g.Dispose() $pm = New-Object System.IO.MemoryStream $bmp.Save($pm, [System.Drawing.Imaging.ImageFormat]::Png) $bmp.Dispose() $chunks += , @($t[0], $pm.ToArray()) } $img.Dispose() $total = 8 foreach ($c in $chunks) { $total += 8 + $c[1].Length } $bw = New-Object System.IO.BinaryWriter $ms function BE([int]$v) { $b = [BitConverter]::GetBytes($v); [Array]::Reverse($b); return $b } $bw.Write([Text.Encoding]::ASCII.GetBytes("icns")); $bw.Write((BE $total)) foreach ($c in $chunks) { $bw.Write([Text.Encoding]::ASCII.GetBytes($c[0])); $bw.Write((BE (8 + $c[1].Length))); $bw.Write([byte[]]$c[1]) } $bw.Flush() [IO.File]::WriteAllBytes($out, $ms.ToArray()) } $plist = @" CFBundleDevelopmentRegionen CFBundleDisplayNameUltra Paradise CU:Trainer CFBundleName$appName CFBundleExecutable$exe CFBundleIdentifier$bundleId CFBundleIconFileicon CFBundleInfoDictionaryVersion6.0 CFBundlePackageTypeAPPL CFBundleShortVersionString$ver CFBundleVersion$ver LSMinimumSystemVersion12.0 LSApplicationCategoryTypepublic.app-category.games NSHighResolutionCapable NSHumanReadableCopyrightCopyright (c) casualexpie. Source-available: opensource.smellypawz.com "@.Replace("`r`n", "`n") Get-ChildItem $root -Filter "UltraParadise-Mac-*" | Remove-Item -Force $readme = [IO.File]::ReadAllText((Join-Path $root "README-mac.txt")).Replace("@@VER@@", $ver).Replace("`r`n", "`n") $results = @() foreach ($t in @(@("osx-arm64", "AppleSilicon"), @("osx-x64", "Intel"))) { $rid = $t[0]; $label = $t[1] $pub = Join-Path $root "out\$rid" Remove-Item $pub -Recurse -Force -ErrorAction SilentlyContinue Push-Location (Join-Path $root "app") try { & dotnet publish -c Release -r $rid -p:PublishSingleFile=false -p:IncludeNativeLibrariesForSelfExtract=false -p:EnableCompressionInSingleFile=false -o $pub | Out-Null if ($LASTEXITCODE -ne 0) { throw "app build failed for $rid" } } finally { Pop-Location } $pkg = Join-Path $root "out\macpkg-$rid\UltraParadise-CU-Trainer" Remove-Item (Split-Path $pkg -Parent) -Recurse -Force -ErrorAction SilentlyContinue $app = Join-Path $pkg "$appName.app" $contents = Join-Path $app "Contents" New-Item -ItemType Directory (Join-Path $contents "MacOS"), (Join-Path $contents "Resources") -Force | Out-Null Copy-Item (Join-Path $pub "*") (Join-Path $contents "MacOS") -Recurse $plistFile = Join-Path $contents "Info.plist" [IO.File]::WriteAllText($plistFile, $plist, (New-Object Text.UTF8Encoding($false))) [IO.File]::WriteAllText((Join-Path $contents "PkgInfo"), "APPL????", (New-Object Text.ASCIIEncoding)) New-Icns (Join-Path $root "art\icon.png") (Join-Path $contents "Resources\icon.icns") & $signer (Join-Path $contents "MacOS\$exe") $bundleId $plistFile if ($LASTEXITCODE -ne 0) { throw "signing failed for $rid" } & $signer (Join-Path $contents "MacOS\createdump") "createdump" & $signer --verify (Join-Path $contents "MacOS\$exe") if ($LASTEXITCODE -ne 0) { throw "signature check failed for $rid" } [IO.File]::WriteAllText((Join-Path $pkg "README.txt"), $readme, (New-Object Text.UTF8Encoding($false))) $zip = Join-Path $root "UltraParadise-Mac-$ver-$label.zip" & powershell -ExecutionPolicy Bypass -File (Join-Path $root "zipunix.ps1") -Src $pkg -Out $zip -Exec "$exe,createdump" $results += $zip } Write-Host "" Write-Host "macOS v$ver" foreach ($z in $results) { Write-Host (" {0} {1:N1} MB {2}" -f (Split-Path $z -Leaf), ((Get-Item $z).Length / 1MB), (Get-FileHash $z).Hash.ToLower()) }