File size: 1,731 Bytes
27bba44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
param([string]$OutDir = "")
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$TarName = "DressCode.tar"
$TarPath = Join-Path $ScriptDir $TarName
if (-not $OutDir) { $OutDir = Join-Path $ScriptDir "data\DressCode" }

function Join-Parts([string]$OutFile) {
    $parts = Get-ChildItem -Path ($OutFile + ".part*") -EA SilentlyContinue | Sort-Object Name
    if (-not $parts -or $parts.Count -eq 0) { return $false }
    Write-Host "==> Joining $($parts.Count) parts -> $OutFile"
    if (Test-Path $OutFile) { Remove-Item $OutFile -Force }
    $fs = [System.IO.File]::Open($OutFile, 'Create')
    try {
        foreach ($p in $parts) {
            Write-Host "  + $($p.Name)"
            $src = [System.IO.File]::OpenRead($p.FullName)
            try { $src.CopyTo($fs) } finally { $src.Dispose() }
        }
    } finally { $fs.Dispose() }
    return $true
}

if (-not (Test-Path $TarPath)) {
    if (-not (Join-Parts $TarPath)) { Write-Error "Missing $TarPath / parts" }
}

$parent = Split-Path -Parent $OutDir
New-Item -ItemType Directory -Force -Path $parent | Out-Null
Write-Host "==> Extracting $TarName -> $parent"
& tar.exe -xf $TarPath -C $parent
if ($LASTEXITCODE -ne 0) { throw "tar extract failed" }

$Root = $OutDir
foreach ($c in @((Join-Path $parent "DressCode"), (Join-Path $OutDir "DressCode"), $OutDir)) {
    if (Test-Path (Join-Path $c "dresses")) { $Root = $c; break }
}
$missing = $false
foreach ($n in @("dresses", "upper_body", "lower_body")) {
    if (-not (Test-Path (Join-Path $Root $n))) { Write-Host "  MISSING: $n"; $missing = $true }
    else { Write-Host "  OK: $n" }
}
if ($missing) { throw "layout check failed" }
Write-Host "==> Done. Dataset root: $Root"