# Rewrites app manifests to ensure they contain the correct archive and version numbers as given in init.js
[CmdletBinding()]
param (
[switch]$dryrun = $false
)
# Get the appVersion and archive from init.js
$init_params = Get-Content -Raw "$PSScriptRoot\..\www\js\init.js"
$VERSION = ''
if ($init_params -match 'params\[[''"]appVersion[''"]]\s*=\s*[''"]([^''"]+)') {
$VERSION = $matches[1]
$NUMERICVERSION = $VERSION -replace '[-A-Z]+$', ''
}
$FILE = ''
if ($init_params -match 'params\[[''"]packagedFile[''"]]\s*=\s*[^|]+[^''"]*[''"]([^''"]+)') {
$FILE = $matches[1]
## If the file doesn't match a ZIM archive, empty it
if ($FILE -notmatch '\.zim$') {
$FILE = ''
}
}
if ($VERSION -ne '') {
"`nUpdating appxmanifests..."
$FileList = ls *.appxmanifest
ForEach ($Manifest in $FileList) {
"Rewriting $Manifest..."
$FileContent = (Get-Content $Manifest -Raw)
$FileContent = $FileContent -ireplace '(\s*', ""
if ($FILE) {
$FileContent = $FileContent -ireplace '()(\s+)(?=`${2}"
}
$FileContent = $FileContent -replace '\s+$', ''
if (!$dryrun) {
$FileContent | Set-Content -encoding "utf8BOM" $Manifest
} else {
echo "[DRYRUN] Would have written modified $Manifest"
}
}
"`nDone.`n"
} else {
"No valid VERSION or FILENAME were found. Manifests were unchanged.`n"
}