-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip-objects.ps1
72 lines (54 loc) · 2.21 KB
/
zip-objects.ps1
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
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.CompressionLevel]$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
$verbose = $args.length -eq 1 -and $args[0] -eq '-v'
$homepath = Get-Location
$objectTotal = 0
$objectSuccess = 0
$outdir = "$($homepath)/dist"
New-Item -Path $outdir -ItemType Directory -Force | Out-Null
Set-Location ./objects
$groupPaths = Get-ChildItem -Directory
foreach ($groupPath in $groupPaths) {
Set-Location $groupPath
$objectPaths = Get-ChildItem -Directory
foreach ($objectPath in $objectPaths) {
Set-Location $objectPath
$objectTotal++
if (Test-Path "images.json") {
# Ignore paths with images.json in them, as they are probably not done
Set-Location ..
continue
}
# Get object identifier from the file itself
$objectName = (Select-String -Path .\object.json '"id": "([\w\.]*)"' -AllMatches).Matches.Groups[1].Value
$outfile = "$($outdir)/$($objectName).parkobj"
# Remove old zip file, if it exists
if (Test-Path $outfile) {
Remove-Item $outfile -ErrorAction Stop
}
if ($verbose) {
Write-Output "Zipping $objectName..."
}
# Get file list
$Files = @(Get-ChildItem "./" -Recurse -File)
$FullFilenames = $files | ForEach-Object -Process {Write-Output -InputObject $_.FullName}
# Create zip file
try {
$zip = [System.IO.Compression.ZipFile]::Open($outfile, [System.IO.Compression.ZipArchiveMode]::Create)
# Write entries with relative paths as names
foreach ($fname in $FullFilenames) {
$relativePath = $fname.Replace((Get-Location).Path + '\', '')
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $fname, $relativePath, $compressionLevel)
}
} finally {
if ($zip) { $zip.Dispose() }
}
$objectSuccess += 1
Set-Location ..
}
Set-Location ..
}
# Go home
Set-Location $homepath
Write-Output "Created $objectSuccess out of $objectTotal objects."