newmindjet/restore-mmap.ps1

37 lines
1.3 KiB
PowerShell

# Restores "nomad_27 copy.mmap" from Release mmap-current assets.
$ErrorActionPreference = "Stop"
$owner = "hackrobot"
$repo = "newmindjet"
$tag = "mmap-current"
$outFile = Join-Path $PSScriptRoot "nomad_27 copy.mmap"
$api = "https://git.nomadro.cn/api/v1/repos/$owner/$repo/releases/tags/$tag"
Write-Host "Fetching release $tag ..."
$rel = Invoke-RestMethod -Uri $api -Method Get
$assets = $rel.assets | Sort-Object name
if (-not $assets -or $assets.Count -eq 0) { throw "No assets found on release $tag" }
$tmp = Join-Path $env:TEMP ("mmap-restore-" + [guid]::NewGuid().ToString("n"))
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
$i = 0
foreach ($a in $assets) {
$i++
$dest = Join-Path $tmp $a.name
Write-Host "[$i/$($assets.Count)] $($a.name) ($($a.size) bytes)"
Invoke-WebRequest -Uri $a.browser_download_url -OutFile $dest -UseBasicParsing
}
if (Test-Path $outFile) { Remove-Item $outFile -Force }
$parts = Get-ChildItem $tmp -File | Sort-Object Name
$fs = [IO.File]::Create($outFile)
try {
foreach ($p in $parts) {
$bytes = [IO.File]::ReadAllBytes($p.FullName)
$fs.Write($bytes, 0, $bytes.Length)
}
} finally { $fs.Close() }
Write-Host "Wrote $outFile ($((Get-Item $outFile).Length) bytes)"
} finally {
Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
}