File: package.ps1

package info (click to toggle)
openrct2-objects 1.3.7%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 15,956 kB
  • sloc: python: 305; sh: 71; makefile: 25
file content (66 lines) | stat: -rw-r--r-- 2,097 bytes parent folder | download | duplicates (3)
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
#!/bin/pwsh
$ErrorActionPreference = "Stop"

# Create zip archive containing objects
$useZip = $false
if (Get-Command "zip" -ErrorAction SilentlyContinue)
{
    # Use zip if possible as it handles permissions better on unix
    $useZip = $true
    Write-Host "Using zip instead of Compress-Archive"
}

Write-Host -ForegroundColor Cyan "Re-creating artifacts directory..."
Remove-Item -Force -Recurse artifacts -ErrorAction SilentlyContinue
New-Item -Force -ItemType Directory artifacts,artifacts/objects | Out-Null

Write-Host -ForegroundColor Cyan "Copying objects..."
Push-Location objects
    Copy-Item -Recurse "official","rct1","rct2","rct2ww","rct2tt" ../artifacts/objects
Pop-Location

Write-Host -ForegroundColor Cyan "Creating parkobj files..."
foreach ($d in Get-ChildItem -Directory -Recurse artifacts/objects)
{
    if (Test-Path (Join-Path $d.FullName object.json))
    {
        $objName = $d.Name
        $src = Resolve-Path -Relative $d.FullName
        $dst = $src + ".parkobj"
        Write-Host "$src -> $dst"
        if ($useZip)
        {
            Push-Location $src
                zip -r9 "../$objName.parkobj" (Get-ChildItem).Name
                if ($LASTEXITCODE -ne 0)
                {
                    throw "zip failed with $LASTEXITCODE"
                }
            Pop-Location
        }
        else
        {
            # We must use .zip extension for Compress-Archive to work
            Compress-Archive -Force "$src/*" -DestinationPath ($dst + ".zip") -CompressionLevel Optimal
            Move-Item ($dst + ".zip") $dst
        }
        Remove-Item -Force -Recurse $d.FullName
    }
}

Write-Host -ForegroundColor Cyan "Creating final archive..."
if ($useZip)
{
    Push-Location "artifacts/objects"
        zip -r9 "../objects.zip" (Get-ChildItem).Name
        if ($LASTEXITCODE -ne 0)
        {
            throw "zip failed with $LASTEXITCODE"
        }
    Pop-Location
}
else
{
    Compress-Archive -Force "artifacts/objects/*" -DestinationPath "artifacts/objects.zip" -CompressionLevel Optimal
}
Remove-Item -Force -Recurse artifacts/objects