43 lines
2.3 KiB
PowerShell
43 lines
2.3 KiB
PowerShell
# Fetches the pinned pdfium build (bblanchon/pdfium-binaries, Windows x64) into third_party/pdfium/.
|
|
# The archive's sha256 is pinned: a different file is refused and nothing is extracted.
|
|
# pdfium-render's `pdfium_latest` feature (0.9.5) targets chromium/8125: keep the two in step.
|
|
# Usage: powershell -File scripts/fetch-pdfium.ps1 [-Dest <folder>]
|
|
param([string]$Dest = (Join-Path $PSScriptRoot '..\third_party\pdfium'))
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$Release = 'chromium/8125'
|
|
$Url = 'https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F8125/pdfium-win-x64.tgz'
|
|
$Sha256 = '9a964261760cff52570aabf038ab346d3a5034dd8b30d0d5fe8861235d356b8b'
|
|
|
|
$Dest = [IO.Path]::GetFullPath($Dest)
|
|
$marker = Join-Path $Dest 'RELEASE'
|
|
if ((Test-Path (Join-Path $Dest 'bin\pdfium.dll')) -and (Test-Path $marker) -and ((Get-Content $marker -Raw).Trim() -eq "$Release $Sha256")) {
|
|
Write-Host "pdfium $Release already in $Dest"
|
|
exit 0
|
|
}
|
|
|
|
$tmp = Join-Path ([IO.Path]::GetTempPath()) ("pdfium-" + [Guid]::NewGuid())
|
|
New-Item -ItemType Directory -Force $tmp | Out-Null
|
|
try {
|
|
$archive = Join-Path $tmp 'pdfium-win-x64.tgz'
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $archive
|
|
$got = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLowerInvariant()
|
|
if ($got -ne $Sha256) { throw "pdfium archive sha256 mismatch: expected $Sha256, got $got. Nothing was extracted." }
|
|
$x = Join-Path $tmp 'x'
|
|
New-Item -ItemType Directory -Force $x | Out-Null
|
|
# Windows' own bsdtar: Git's GNU tar on PATH reads "F:\..." as a remote host.
|
|
& (Join-Path $env:SystemRoot 'System32\tar.exe') -xzf $archive -C $x
|
|
if ($LASTEXITCODE -ne 0) { throw "tar failed ($LASTEXITCODE)" }
|
|
if (Test-Path $Dest) { Remove-Item -Recurse -Force $Dest }
|
|
New-Item -ItemType Directory -Force (Join-Path $Dest 'bin') | Out-Null
|
|
Copy-Item (Join-Path $x 'bin\pdfium.dll') (Join-Path $Dest 'bin\pdfium.dll')
|
|
Copy-Item (Join-Path $x 'LICENSE') (Join-Path $Dest 'LICENSE')
|
|
Copy-Item -Recurse (Join-Path $x 'licenses') (Join-Path $Dest 'licenses')
|
|
Copy-Item (Join-Path $x 'VERSION') (Join-Path $Dest 'VERSION')
|
|
Set-Content -Encoding ascii $marker "$Release $Sha256"
|
|
Write-Host "pdfium $Release -> $Dest"
|
|
} finally {
|
|
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
|
|
}
|