cu-trainer/Ultra Paradise Linux/build-mac.ps1
| 1 | $ErrorActionPreference = "Stop" |
| 2 | $root = $PSScriptRoot |
| 3 | $ver = ([xml](Get-Content (Join-Path $root "app\UltraParadise.Linux.csproj"))).Project.PropertyGroup[0].Version |
| 4 | $env:DOTNET_CLI_TELEMETRY_OPTOUT = "1"; $env:DOTNET_NOLOGO = "1" |
| 5 | $appName = "Ultra Paradise CU-Trainer" |
| 6 | $bundleId = "casualexpie.ultraparadise.cutrainer" |
| 7 | $exe = "UltraParadiseCUTrainer" |
| 8 | |
| 9 | & powershell -ExecutionPolicy Bypass -File (Join-Path $root "plugin\build.ps1") |
| 10 | if ($LASTEXITCODE -ne 0) { throw "plugin build failed" } |
| 11 | |
| 12 | $signer = Join-Path $root "tools\macsign\bin\macsign.exe" |
| 13 | Push-Location (Join-Path $root "tools\macsign") |
| 14 | 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 } |
| 15 | |
| 16 | Add-Type -AssemblyName System.Drawing |
| 17 | function New-Icns([string]$src, [string]$out) { |
| 18 | $img = [System.Drawing.Image]::FromFile($src) |
| 19 | $ms = New-Object System.IO.MemoryStream |
| 20 | $types = @(@("icp4", 16), @("icp5", 32), @("icp6", 64), @("ic07", 128), @("ic08", 256), @("ic09", 512), @("ic10", 1024)) |
| 21 | $chunks = @() |
| 22 | foreach ($t in $types) { |
| 23 | $s = $t[1] |
| 24 | $bmp = New-Object System.Drawing.Bitmap $s, $s |
| 25 | $g = [System.Drawing.Graphics]::FromImage($bmp) |
| 26 | $g.InterpolationMode = if ($s -ge $img.Width) { "NearestNeighbor" } else { "HighQualityBicubic" } |
| 27 | $g.PixelOffsetMode = "Half" |
| 28 | $g.DrawImage($img, 0, 0, $s, $s) |
| 29 | $g.Dispose() |
| 30 | $pm = New-Object System.IO.MemoryStream |
| 31 | $bmp.Save($pm, [System.Drawing.Imaging.ImageFormat]::Png) |
| 32 | $bmp.Dispose() |
| 33 | $chunks += , @($t[0], $pm.ToArray()) |
| 34 | } |
| 35 | $img.Dispose() |
| 36 | $total = 8 |
| 37 | foreach ($c in $chunks) { $total += 8 + $c[1].Length } |
| 38 | $bw = New-Object System.IO.BinaryWriter $ms |
| 39 | function BE([int]$v) { $b = [BitConverter]::GetBytes($v); [Array]::Reverse($b); return $b } |
| 40 | $bw.Write([Text.Encoding]::ASCII.GetBytes("icns")); $bw.Write((BE $total)) |
| 41 | foreach ($c in $chunks) { $bw.Write([Text.Encoding]::ASCII.GetBytes($c[0])); $bw.Write((BE (8 + $c[1].Length))); $bw.Write([byte[]]$c[1]) } |
| 42 | $bw.Flush() |
| 43 | [IO.File]::WriteAllBytes($out, $ms.ToArray()) |
| 44 | } |
| 45 | |
| 46 | $plist = @" |
| 47 | <?xml version="1.0" encoding="UTF-8"?> |
| 48 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 49 | <plist version="1.0"> |
| 50 | <dict> |
| 51 | <key>CFBundleDevelopmentRegion</key><string>en</string> |
| 52 | <key>CFBundleDisplayName</key><string>Ultra Paradise CU:Trainer</string> |
| 53 | <key>CFBundleName</key><string>$appName</string> |
| 54 | <key>CFBundleExecutable</key><string>$exe</string> |
| 55 | <key>CFBundleIdentifier</key><string>$bundleId</string> |
| 56 | <key>CFBundleIconFile</key><string>icon</string> |
| 57 | <key>CFBundleInfoDictionaryVersion</key><string>6.0</string> |
| 58 | <key>CFBundlePackageType</key><string>APPL</string> |
| 59 | <key>CFBundleShortVersionString</key><string>$ver</string> |
| 60 | <key>CFBundleVersion</key><string>$ver</string> |
| 61 | <key>LSMinimumSystemVersion</key><string>12.0</string> |
| 62 | <key>LSApplicationCategoryType</key><string>public.app-category.games</string> |
| 63 | <key>NSHighResolutionCapable</key><true/> |
| 64 | <key>NSHumanReadableCopyright</key><string>Copyright (c) casualexpie. Source-available: opensource.smellypawz.com</string> |
| 65 | </dict> |
| 66 | </plist> |
| 67 | "@.Replace("`r`n", "`n") |
| 68 | |
| 69 | Get-ChildItem $root -Filter "UltraParadise-Mac-*" | Remove-Item -Force |
| 70 | $readme = [IO.File]::ReadAllText((Join-Path $root "README-mac.txt")).Replace("@@VER@@", $ver).Replace("`r`n", "`n") |
| 71 | $results = @() |
| 72 | foreach ($t in @(@("osx-arm64", "AppleSilicon"), @("osx-x64", "Intel"))) { |
| 73 | $rid = $t[0]; $label = $t[1] |
| 74 | $pub = Join-Path $root "out\$rid" |
| 75 | Remove-Item $pub -Recurse -Force -ErrorAction SilentlyContinue |
| 76 | Push-Location (Join-Path $root "app") |
| 77 | try { |
| 78 | & dotnet publish -c Release -r $rid -p:PublishSingleFile=false -p:IncludeNativeLibrariesForSelfExtract=false -p:EnableCompressionInSingleFile=false -o $pub | Out-Null |
| 79 | if ($LASTEXITCODE -ne 0) { throw "app build failed for $rid" } |
| 80 | } finally { Pop-Location } |
| 81 | |
| 82 | $pkg = Join-Path $root "out\macpkg-$rid\UltraParadise-CU-Trainer" |
| 83 | Remove-Item (Split-Path $pkg -Parent) -Recurse -Force -ErrorAction SilentlyContinue |
| 84 | $app = Join-Path $pkg "$appName.app" |
| 85 | $contents = Join-Path $app "Contents" |
| 86 | New-Item -ItemType Directory (Join-Path $contents "MacOS"), (Join-Path $contents "Resources") -Force | Out-Null |
| 87 | Copy-Item (Join-Path $pub "*") (Join-Path $contents "MacOS") -Recurse |
| 88 | $plistFile = Join-Path $contents "Info.plist" |
| 89 | [IO.File]::WriteAllText($plistFile, $plist, (New-Object Text.UTF8Encoding($false))) |
| 90 | [IO.File]::WriteAllText((Join-Path $contents "PkgInfo"), "APPL????", (New-Object Text.ASCIIEncoding)) |
| 91 | New-Icns (Join-Path $root "art\icon.png") (Join-Path $contents "Resources\icon.icns") |
| 92 | & $signer (Join-Path $contents "MacOS\$exe") $bundleId $plistFile |
| 93 | if ($LASTEXITCODE -ne 0) { throw "signing failed for $rid" } |
| 94 | & $signer (Join-Path $contents "MacOS\createdump") "createdump" |
| 95 | & $signer --verify (Join-Path $contents "MacOS\$exe") |
| 96 | if ($LASTEXITCODE -ne 0) { throw "signature check failed for $rid" } |
| 97 | [IO.File]::WriteAllText((Join-Path $pkg "README.txt"), $readme, (New-Object Text.UTF8Encoding($false))) |
| 98 | |
| 99 | $zip = Join-Path $root "UltraParadise-Mac-$ver-$label.zip" |
| 100 | & powershell -ExecutionPolicy Bypass -File (Join-Path $root "zipunix.ps1") -Src $pkg -Out $zip -Exec "$exe,createdump" |
| 101 | $results += $zip |
| 102 | } |
| 103 | |
| 104 | Write-Host "" |
| 105 | Write-Host "macOS v$ver" |
| 106 | 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()) } |