Files
bdot1andClaude Opus 5.5 1674bd0c5e v1.26.3: DopingControl 0.7.0, from its new home on octowow.st
DopingControl moved to octowow.st/git/ShempError/DopingControl with 0.7.0
(GitHub stops at 0.6.4), so WhoDidIt's copy had stopped updating. Pinned
at e6561d3: an Addons tab (who runs BigWigs, Threat Meter, EPGP, SuperWoW,
Rinse), enchant names on the Equipment tab, a silent scan on BigWigs pull
timers, a test-mode reminder.

Reviewed for running inside WhoDidIt: scan/pull.lua replaces the global
SendAddonMessage with a pass-through (pcall-guarded, all returns kept), so
every WhoDidIt send goes through it unchanged; the Addons tab sends hidden
queries to the raid and SWOW_Q to GUILD (tab open, at most every 30 s,
never in combat). DopingLoader's leader-only wraps still fit. No changes.

tools/EmbedUpdate.ps1: octowow.st shows scripts and git an anti-bot page
and the tool doesn't try to get past it, so DopingControl's spec is Manual:
download <Web>/archive/<Pin>.zip in a browser and run -Only Doping
-FromZip <zip>. The zip's comment (git archive) is the commit; another one
is refused unless -Latest. The tool keeps WDI_NOTICE.txt across updates,
names the real source in wdi_version.lua, and counts a WoW whose path
Windows hides (started as administrator) as running.

Checked: test install in a scratch game folder (wrong-commit zip refused),
LuaCheck on all 31 files, a smoke test in OctoBG's 1.12 mock (67 checks:
every tab, the wrapper, the queries, the loader's wraps), a /reload before
restarting (old .toc) loads without errors. Not tried in game. New files:
restart WoW fully once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 21:19:48 +01:00

486 lines
25 KiB
PowerShell
Vendored

<#
EmbedUpdate (maintainer tool) - keeps the addons built into WhoDidIt up to date.
WhoDidIt carries other addons inside it, so they don't have to be
installed separately. They ship in the WhoDidIt repository; for the maintainer,
this downloads each from its official source at the pinned commit and, whenever its authors
push a new version, fetches that too.
Chronicle logger ChronicleCompanion by Emyrk (chronicleclassic.com)
github.com/Emyrk/ChronicleCompanion (pinned commit)
-> WhoDidIt\Chronicle
RollFor the master-loot roller by Obszczymucha, sica42's
1.12 fork (the original now only supports TBC)
github.com/sica42/roll-for-vanilla (pinned commit, v4.8.1)
-> WhoDidIt\RollFor
DopingControl the raid consumables / buffs / enchants checker by
ShempError (MIT), octowow.st/git/ShempError/DopingControl
since 0.7.0 (github.com/ShempError/DopingControl up to
0.6.4) (pinned commit) -> WhoDidIt\DopingControl
To run from inside WhoDidIt, a few things in their files are changed,
and nothing else is touched:
- their version comes from <folder>\wdi_version.lua instead of their
own .toc (the Chronicle logger also starts on WhoDidIt's
ADDON_LOADED)
- paths to their images point at WhoDidIt\<folder>
- every file starts with "if WDI_<KEY>_SKIP then return end", so the
built-in copy stands down if the separate addon is still switched on
- .xml file lists (libraries) are expanded into WhoDidIt.toc
WhoDidIt.toc gets their file list and saved variables, and
WhoDidIt\Bindings.xml their key bindings. If a new version can't be
adapted safely, the current one is kept.
Updates are only swapped in while WoW is closed; one that arrives while
you're playing is downloaded and installed when you exit.
Pinned versions: each addon is installed at the exact commit in its Pin
(below), a version the WhoDidIt maintainer has tested - never whatever
happens to be newest upstream. To try a newer one: run with -Latest, test
it in game, then put the commit it prints into Pin and release.
Hosts that only let browsers through (octowow.st's git shows scripts and
git itself an anti-bot page) can't be fetched by this script, and it
doesn't try to get past that: download the pinned commit's zip in a
browser (the address is in the log line) and give it to -FromZip. The
zip's comment holds the commit it was made from (git archive writes it),
so a zip of any other commit is refused unless -Latest.
The maintainer runs it by hand, then commits the result:
EmbedUpdate.ps1 check all of them and install updates
EmbedUpdate.ps1 -Only RollFor just one (Chronicle, RollFor or Doping)
EmbedUpdate.ps1 -Force download and reinstall even if up to date
EmbedUpdate.ps1 -Only Doping -FromZip <file.zip> install from a zip you downloaded
#>
param([switch]$Force, [string]$Only = "", [switch]$Latest, [string]$FromZip = "")
$script:EmbedLatest = $Latest
$script:EmbedZip = $FromZip
$EmbedUA = "WhoDidIt-EmbedUpdate/1.0 (+https://github.com/bdot89/WhoDidIt)"
$AddonDir = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$EmbedWow = (Resolve-Path (Join-Path $AddonDir "..\..\..")).Path
$EmbedToc = Join-Path $AddonDir "WhoDidIt.toc"
$EmbedBinds = Join-Path $AddonDir "Bindings.xml"
$EmbedUtf8 = New-Object Text.UTF8Encoding $false
# not needed in game: tests, docs, editor files, the other client's libraries
$EmbedSkip = @("tests", "test", "examples", "docs", ".github", ".gitignore", ".idea", ".vscode", ".luarc.json",
".editorconfig", "bcc", "globaldefs.lua", "screenshots", "dev")
$EmbedSpecs = @{
Chronicle = @{
Name = "Chronicle logger"; Key = "CHRON"; Addon = "ChronicleCompanion"; Dest = "Chronicle"
Repo = "Emyrk/ChronicleCompanion"; Ref = "branch"; Branch = "main"; SubDir = ""
Pin = "b367dfe17d1183a43552d3985cad6362c7051457"; PinLabel = "0.38"
VersionFn = "WDI_ChronVersion"; EqualsName = $true; Bindings = $false
Begin = "# >>> Chronicle files (generated)"; End = "# <<< Chronicle files"
# any use of its own name left over would break once it runs inside WhoDidIt
Forbid = @('["'']ChronicleCompanion["'']')
}
RollFor = @{
Name = "RollFor"; Key = "ROLLFOR"; Addon = "RollFor"; Dest = "RollFor"
Repo = "sica42/roll-for-vanilla"; Ref = "release"; Branch = "master"; SubDir = "RollFor"
Pin = "7f64d60872e66c4244c821986db56aacc11ed641"; PinLabel = "v4.8.1"
VersionFn = "WDI_RollForVersion"; EqualsName = $false; Bindings = $true
Begin = "# >>> RollFor files (generated)"; End = "# <<< RollFor files"
# "RollFor" is also its chat/addon-message prefix, so only API uses are checked
Forbid = @('GetAddOnMetadata\(\s*["'']RollFor["'']', 'IsAddOnLoaded\(\s*["'']RollFor["'']',
'AddOns[\\/]+RollFor[\\/]', 'ADDON_LOADED')
}
Doping = @{
Name = "DopingControl"; Key = "DOPING"; Addon = "DopingControl"; Dest = "DopingControl"
Repo = "ShempError/DopingControl"; Ref = "branch"; Branch = "main"; SubDir = ""
# moved to OctoWoW's git with 0.7.0; it only lets browsers through (see -FromZip)
Web = "https://octowow.st/git/ShempError/DopingControl"; Manual = $true
Pin = "e6561d3bceed6567716b2425cf9c26a3e121e6ba"; PinLabel = "0.7.0"; PinDate = "2026-10-15"
VersionFn = "WDI_DopingVersion"; EqualsName = $true; Bindings = $false
Begin = "# >>> DopingControl files (generated)"; End = "# <<< DopingControl files"
# its .toc lists a developer-only file (dev\raiddump.lua) that isn't published
AllowMissing = $true
Forbid = @('GetAddOnMetadata\(\s*["'']DopingControl["'']', 'IsAddOnLoaded\(\s*["'']DopingControl["'']',
'AddOns[\\/]+DopingControl[\\/]', 'arg1\s*[~=]=\s*["'']DopingControl["'']')
}
}
if (-not (Get-Command Log -ErrorAction SilentlyContinue)) {
function Log($msg) { Write-Host ("[{0}] {1}" -f (Get-Date -Format "HH:mm:ss"), $msg) }
}
# ------------------------------------------------------------------ helpers
function Get-EmbedPaths($s) {
@{ dir = (Join-Path $AddonDir $s.Dest); new = (Join-Path $AddonDir ($s.Dest + ".new")); old = (Join-Path $AddonDir ($s.Dest + ".old")) }
}
# <folder>\wdi_version.lua -> @{ version; commit; files; sv; svChar; binds }
function Get-EmbedInfo($s, $dir) {
$f = Join-Path $dir "wdi_version.lua"
if (-not (Test-Path -LiteralPath $f)) { return $null }
$t = [IO.File]::ReadAllText($f)
$files = @()
foreach ($m in [regex]::Matches($t, '(?m)^-- file: (.+)$')) { $files += $m.Groups[1].Value.Trim() }
$binds = @()
foreach ($m in [regex]::Matches($t, '(?m)^-- binding: (.+)$')) { $binds += $m.Groups[1].Value.Trim() }
return @{
version = [regex]::Match($t, "WDI_$($s.Key)_VERSION\s*=\s*""([^""]*)""").Groups[1].Value
commit = [regex]::Match($t, "WDI_$($s.Key)_COMMIT\s*=\s*""([^""]*)""").Groups[1].Value
sv = [regex]::Match($t, '(?m)^-- savedvariables: (.*)$').Groups[1].Value.Trim()
svChar = [regex]::Match($t, '(?m)^-- savedvariablespercharacter: (.*)$').Groups[1].Value.Trim()
files = $files
binds = $binds
}
}
function Test-WowRunning {
foreach ($p in Get-Process -ErrorAction SilentlyContinue) {
try {
if ($p.Path -and $p.Path.StartsWith($EmbedWow + "\", [StringComparison]::OrdinalIgnoreCase)) { return $true }
# Windows hides the path of a game started as administrator: a WoW we can't place counts
if (-not $p.Path -and $p.ProcessName -match '^WoW') { return $true }
} catch { if ($p.ProcessName -match '^WoW') { return $true } }
}
return $false
}
function Get-GitHub($url) {
Invoke-RestMethod -Uri $url -TimeoutSec 30 -Headers @{ "User-Agent" = $EmbedUA; "Accept" = "application/vnd.github+json" }
}
# where the addon's source is published
function Get-EmbedWeb($s) { if ($s.Web) { $s.Web } else { "https://github.com/$($s.Repo)" } }
# the commit a git archive zip was made from: git writes it as the zip's comment
function Get-ZipCommit([string]$path) {
$b = [IO.File]::ReadAllBytes($path)
for ($i = $b.Length - 22; $i -ge [Math]::Max(0, $b.Length - 65557); $i--) {
if ($b[$i] -eq 0x50 -and $b[$i + 1] -eq 0x4B -and $b[$i + 2] -eq 0x05 -and $b[$i + 3] -eq 0x06) {
$n = [BitConverter]::ToUInt16($b, $i + 20)
if ($i + 22 + $n -gt $b.Length) { break }
$c = [Text.Encoding]::ASCII.GetString($b, $i + 22, $n).Trim()
if ($c -match '^[0-9a-f]{40}$') { return $c }
break
}
}
throw "'$path' doesn't say which commit it was made from (download it from the commit's archive link)"
}
# the commit to install: the latest release's, or the branch head
function Get-EmbedTarget($s) {
# a zip the maintainer downloaded (-FromZip): the pinned commit, unless -Latest
if ($script:EmbedZip) {
$zip = (Resolve-Path -LiteralPath $script:EmbedZip).Path
$sha = Get-ZipCommit $zip
if ($s.Pin -and $sha -ne $s.Pin -and -not $script:EmbedLatest) {
throw "the zip is commit $($sha.Substring(0, 7)), not the pinned $($s.Pin.Substring(0, 7)) ($($s.PinLabel)); move the Pin, or add -Latest to try it"
}
$pinned = ($sha -eq $s.Pin)
$date = if ($pinned -and $s.PinDate) { $s.PinDate } else { (Get-Date).ToString("yyyy-MM-dd") }
$label = if ($pinned) { "pinned " + $s.PinLabel } else { "from a zip" }
return @{ sha = $sha; date = $date; label = $label; zip = $zip }
}
# a host this script can't read: only the pin, installed from a zip
if ($s.Manual) {
if ($script:EmbedLatest) { throw "this script can't read $(Get-EmbedWeb $s); look for a newer version there" }
return @{ sha = $s.Pin; date = $s.PinDate; label = "pinned " + $s.PinLabel; manual = $true }
}
# the tested version, unless -Latest asks for the newest
if ($s.Pin -and -not $script:EmbedLatest) {
$c = Get-GitHub "https://api.github.com/repos/$($s.Repo)/commits/$($s.Pin)"
return @{ sha = [string]$c.sha; date = ([datetime]$c.commit.committer.date).ToString("yyyy-MM-dd"); label = "pinned " + $s.PinLabel }
}
$label = $s.Branch
$ref = $s.Branch
if ($s.Ref -eq "release") {
try {
$rel = Get-GitHub "https://api.github.com/repos/$($s.Repo)/releases/latest"
if ($rel.tag_name) { $ref = [string]$rel.tag_name; $label = $ref }
} catch { }
}
$c = Get-GitHub "https://api.github.com/repos/$($s.Repo)/commits/$ref"
return @{ sha = [string]$c.sha; date = ([datetime]$c.commit.committer.date).ToString("yyyy-MM-dd"); label = $label }
}
function Copy-EmbedTree($from, $to) {
New-Item -ItemType Directory -Path $to -Force | Out-Null
foreach ($i in Get-ChildItem -LiteralPath $from -Force) {
if ($EmbedSkip -contains $i.Name -or $i.Extension -eq ".toc" -or $i.Extension -eq ".sh") { continue }
$d = Join-Path $to $i.Name
if ($i.PSIsContainer) { Copy-EmbedTree $i.FullName $d } else { Copy-Item -LiteralPath $i.FullName -Destination $d }
}
}
# a .xml file list -> the .lua files it loads, in order (Include / Script only)
function Expand-EmbedXml($root, [string]$rel, $depth) {
if ($depth -gt 5) { throw "'$rel' includes too deeply" }
$path = Join-Path $root $rel
if (-not (Test-Path -LiteralPath $path)) { throw "'$rel' isn't in the download" }
$xml = [IO.File]::ReadAllText($path)
$xml = [regex]::Replace($xml, '(?s)<!--.*?-->', '')
$base = Split-Path $rel -Parent
$out = @()
foreach ($m in [regex]::Matches($xml, '<(\w+)\b([^>]*)/?>')) {
$tag = $m.Groups[1].Value
if ($tag -eq "Ui") { continue }
$file = [regex]::Match($m.Groups[2].Value, 'file\s*=\s*"([^"]+)"').Groups[1].Value -replace '/', '\'
$full = if ($base) { Join-Path $base $file } else { $file }
if ($tag -eq "Include" -and $file) { $out += Expand-EmbedXml $root $full ($depth + 1) }
elseif ($tag -eq "Script" -and $file) { $out += $full }
else { throw "'$rel' uses <$tag> - only file lists can be built in" }
}
return $out
}
# the changes that let their files run from inside WhoDidIt
function Convert-EmbedLua($s, [string]$text) {
$a = [regex]::Escape($s.Addon)
if ($text.Length -gt 0 -and $text[0] -eq [char]0xFEFF) { $text = $text.Substring(1) }
$text = [regex]::Replace($text, '(?:[\w.:]+[.:])?GetAddOnMetadata\(\s*"' + $a + '"\s*,\s*"Version"\s*\)', $s.VersionFn + '()')
$text = [regex]::Replace($text, 'GetAddOnMetadata\(\s*"' + $a + '"', 'GetAddOnMetadata("WhoDidIt"')
$text = [regex]::Replace($text, 'IsAddOnLoaded\(\s*"' + $a + '"\s*\)', 'IsAddOnLoaded("WhoDidIt")')
if ($s.EqualsName) { $text = [regex]::Replace($text, '(==|~=)\s*"' + $a + '"', '${1} "WhoDidIt"') }
$text = [regex]::Replace($text, '(?i)Interface(\\\\|/)AddOns(\\\\|/)' + $a + '(\\\\|/)', 'Interface${1}AddOns${2}WhoDidIt${3}' + $s.Dest + '${3}')
# same line as their first line, so error line numbers still match the source
return "if WDI_$($s.Key)_SKIP then return end " + $text
}
function Split-Names([string]$list) { @($list -split ',' | ForEach-Object { $_.Trim() } | Where-Object { $_ }) }
# WhoDidIt.toc with this addon's files and saved variables filled in
function New-EmbedToc($s, $info) {
$raw = [IO.File]::ReadAllText($EmbedToc)
$nl = if ($raw.Contains("`r`n")) { "`r`n" } else { "`n" }
$lines = $raw -split "\r?\n"
$b = [Array]::IndexOf($lines, $s.Begin); $e = [Array]::IndexOf($lines, $s.End)
if ($b -lt 0 -or $e -lt $b) { throw "WhoDidIt.toc is missing the '$($s.Begin)' / '$($s.End)' lines" }
$out = New-Object System.Collections.Generic.List[string]
$haveChar = $false
for ($i = 0; $i -lt $b; $i++) {
$l = $lines[$i]
# saved variables: add theirs, never remove (the other built-in addon's are on the same line)
if ($l -match '^##\s*SavedVariables(PerCharacter)?\s*:\s*(.*)$') {
$isChar = [bool]$matches[1]
$names = @(Split-Names $matches[2])
$add = if ($isChar) { @(Split-Names $info.svChar) } else { @(Split-Names $info.sv) }
foreach ($n in $add) { if ($names -notcontains $n) { $names += $n } }
if ($isChar) { $haveChar = $true; $out.Add("## SavedVariablesPerCharacter: " + ($names -join ", ")) }
else { $out.Add("## SavedVariables: " + ($names -join ", ")) }
continue
}
$out.Add($l)
}
if (-not $haveChar -and $info.svChar) {
$at = 0
for ($i = 0; $i -lt $out.Count; $i++) { if ($out[$i] -match '^##\s*SavedVariables\s*:') { $at = $i + 1 } }
$out.Insert($at, "## SavedVariablesPerCharacter: " + ((Split-Names $info.svChar) -join ", "))
}
$out.Add($s.Begin)
$out.Add($s.Dest + "\wdi_version.lua")
foreach ($f in $info.files) { $out.Add($s.Dest + "\" + $f) }
for ($i = $e; $i -lt $lines.Count; $i++) { $out.Add($lines[$i]) }
$text = ($out -join $nl)
return @{ text = $text; changed = ($text -ne $raw) }
}
# WhoDidIt\Bindings.xml with this addon's key bindings filled in
function New-EmbedBindings($s, $info) {
if (-not $s.Bindings) { return @{ changed = $false } }
$raw = [IO.File]::ReadAllText($EmbedBinds)
$begin = "<!-- >>> $($s.Name) bindings (generated) -->"; $end = "<!-- <<< $($s.Name) bindings -->"
$b = $raw.IndexOf($begin); $e = $raw.IndexOf($end)
if ($b -lt 0 -or $e -lt $b) { throw "Bindings.xml is missing the '$begin' / '$end' lines" }
$nl = if ($raw.Contains("`r`n")) { "`r`n" } else { "`n" }
$body = ""
foreach ($x in $info.binds) { $body += "`t" + $x + $nl }
$text = $raw.Substring(0, $b + $begin.Length) + $nl + $body + "`t" + $raw.Substring($e)
return @{ text = $text; changed = ($text -ne $raw) }
}
# ------------------------------------------------------------------ build + install
function Build-EmbedStaging($s, $t) {
$p = Get-EmbedPaths $s
$short = $t.sha.Substring(0, 7)
$zip = if ($t.zip) { $t.zip } else { Join-Path $env:TEMP "wdi-$($s.Dest)-$short.zip" }
$tmp = Join-Path $env:TEMP "wdi-$($s.Dest)-$short"
try {
if (-not $t.zip) {
Invoke-WebRequest -Uri "https://codeload.github.com/$($s.Repo)/zip/$($t.sha)" -OutFile $zip -UseBasicParsing -TimeoutSec 120 -Headers @{ "User-Agent" = $EmbedUA }
}
if (Test-Path $tmp) { Remove-Item $tmp -Recurse -Force }
Expand-Archive -LiteralPath $zip -DestinationPath $tmp -Force
$src = (Get-ChildItem -LiteralPath $tmp -Directory | Select-Object -First 1).FullName
if ($s.SubDir) { $src = Join-Path $src $s.SubDir }
$toc = Join-Path $src ($s.Addon + ".toc")
if (-not (Test-Path -LiteralPath $toc)) { throw "no $($s.Addon).toc in the download" }
# their .toc: version, saved variables, file list (.xml lists expanded)
$meta = @{}; $files = @()
foreach ($l in [IO.File]::ReadAllLines($toc)) {
$x = $l.Trim()
if ($x -match '^##\s*([^:]+?)\s*:\s*(.*)$') { $meta[$matches[1]] = $matches[2].Trim(); continue }
if ($x -eq "" -or $x.StartsWith("#")) { continue }
$x = $x -replace '/', '\'
if ($x -match '\.\.' -or $x -match '^[\\/]' -or $x -match ':') { throw "unexpected file path '$x' in their .toc" }
if ($x -match '\.xml$') { $files += Expand-EmbedXml $src $x 0 }
elseif ($x -match '\.lua$') { $files += $x }
else { throw "their .toc loads '$x', which can't be built in" }
}
$version = ($meta["Version"] -replace '[^0-9A-Za-z._-]', '')
if (-not $version) { throw "no version in their .toc" }
if ($files.Count -eq 0) { throw "their .toc lists no files" }
# key bindings
$binds = @()
if ($s.Bindings) {
$bf = Join-Path $src "Bindings.xml"
if (Test-Path -LiteralPath $bf) {
$bx = [regex]::Replace([IO.File]::ReadAllText($bf), '(?s)<!--.*?-->', '')
foreach ($m in [regex]::Matches($bx, '(?s)<Binding\b[^>]*>.*?</Binding>')) {
$b = ($m.Value -replace '\s*\r?\n\s*', ' ').Trim()
# a key pressed while the addon isn't loaded must not raise an error
$b = $b -replace '>\s*(RollFor\.key_bindings\.\w+)\(\)\s*<', '>if RollFor and RollFor.key_bindings then $1() end<'
$binds += $b
}
}
}
if (Test-Path $p.new) { Remove-Item $p.new -Recurse -Force }
if ($s.AllowMissing) {
# the game skips a listed file that doesn't exist, so do the same
$files = @($files | Where-Object { Test-Path -LiteralPath (Join-Path $src $_) })
}
Copy-EmbedTree $src $p.new
# WhoDidIt's own credit note in the folder (not in their download)
$notice = Join-Path $p.dir "WDI_NOTICE.txt"
if (Test-Path -LiteralPath $notice) { Copy-Item -LiteralPath $notice -Destination (Join-Path $p.new "WDI_NOTICE.txt") }
$bad = @()
foreach ($f in $files) {
$fp = Join-Path $p.new $f
if (-not (Test-Path -LiteralPath $fp)) { throw "their .toc loads '$f' but it isn't in the download" }
$lua = Convert-EmbedLua $s ([IO.File]::ReadAllText($fp))
$n = 0
foreach ($ln in ($lua -split "\n")) {
$n++
foreach ($pat in $s.Forbid) { if ($ln -match $pat) { $bad += "$f line $n" } }
}
[IO.File]::WriteAllText($fp, $lua, $EmbedUtf8)
}
if ($bad.Count -gt 0) { throw ("their code uses its own name in a way WhoDidIt can't adapt (" + (($bad | Select-Object -First 5) -join ", ") + ")") }
$v = New-Object System.Collections.Generic.List[string]
$v.Add("-- Generated by WhoDidIt's tools\WhoDidIt-Sync - do not edit.")
$v.Add("-- $($s.Addon) from $(Get-EmbedWeb $s) ($($t.label), commit $($t.sha))")
$v.Add("-- savedvariables: " + $meta["SavedVariables"])
$v.Add("-- savedvariablespercharacter: " + $meta["SavedVariablesPerCharacter"])
foreach ($f in $files) { $v.Add("-- file: $f") }
foreach ($x in $binds) { $v.Add("-- binding: $x") }
$v.Add("WDI_$($s.Key)_VERSION = `"$version`"")
$v.Add("WDI_$($s.Key)_COMMIT = `"$($t.sha)`"")
$v.Add("WDI_$($s.Key)_DATE = `"$($t.date)`"")
[IO.File]::WriteAllText((Join-Path $p.new "wdi_version.lua"), (($v -join "`n") + "`n"), $EmbedUtf8)
return (Get-EmbedInfo $s $p.new)
} catch {
if (Test-Path $p.new) { Remove-Item $p.new -Recurse -Force -ErrorAction SilentlyContinue }
throw
} finally {
if (-not $t.zip) { Remove-Item $zip -Force -ErrorAction SilentlyContinue }
Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
}
}
# swap <folder>.new in, update WhoDidIt.toc and Bindings.xml; $true if either changed
function Install-EmbedStaging($s) {
$p = Get-EmbedPaths $s
$info = Get-EmbedInfo $s $p.new
if (-not $info) { throw "$($s.Dest).new is incomplete" }
$toc = New-EmbedToc $s $info
$bnd = New-EmbedBindings $s $info
if (Test-Path $p.old) { Remove-Item $p.old -Recurse -Force }
if (Test-Path $p.dir) { Rename-Item -LiteralPath $p.dir -NewName ($s.Dest + ".old") }
try {
Rename-Item -LiteralPath $p.new -NewName $s.Dest
} catch {
if (Test-Path $p.old) { Rename-Item -LiteralPath $p.old -NewName $s.Dest }
throw
}
if ($toc.changed) { [IO.File]::WriteAllText($EmbedToc, $toc.text, $EmbedUtf8) }
if ($bnd.changed) { [IO.File]::WriteAllText($EmbedBinds, $bnd.text, $EmbedUtf8) }
if (Test-Path $p.old) { Remove-Item $p.old -Recurse -Force -ErrorAction SilentlyContinue }
return ($toc.changed -or $bnd.changed)
}
# ------------------------------------------------------------------ main
function Update-Embedded($s, [switch]$Force) {
$p = Get-EmbedPaths $s
$running = Test-WowRunning
# an update downloaded while WoW was open
if ((Test-Path $p.new) -and -not $running) {
$st = Get-EmbedInfo $s $p.new
try {
[void](Install-EmbedStaging $s)
Log "$($s.Name): installed v$($st.version), downloaded earlier"
} catch { Log ("$($s.Name): couldn't install the downloaded update: " + $_.Exception.Message) }
}
$have = Get-EmbedInfo $s $p.dir
try {
$t = Get-EmbedTarget $s
} catch {
Log ("$($s.Name): couldn't check for updates (" + $_.Exception.Message + ")")
return
}
if (-not $Force -and $have -and $have.commit -eq $t.sha) {
Log "$($s.Name): v$($have.version) is up to date"
return
}
if ($t.manual) {
Log ("$($s.Name): the pin is $($s.PinLabel) ($($s.Pin.Substring(0, 7))) but " + $(if ($have) { "v$($have.version) is installed" } else { "it isn't installed" }) + ".")
Log "$($s.Name): download $(Get-EmbedWeb $s)/archive/$($s.Pin).zip in a browser, then run EmbedUpdate.ps1 -Only $(@($EmbedSpecs.Keys | Where-Object { $EmbedSpecs[$_] -eq $s })[0]) -FromZip <the zip>"
return
}
$staged = Get-EmbedInfo $s $p.new
if (-not $Force -and $staged -and $staged.commit -eq $t.sha) {
Log "$($s.Name): v$($staged.version) is downloaded and installs when WoW is closed"
return
}
try {
$new = Build-EmbedStaging $s $t
} catch {
$keep = if ($have) { "keeping v$($have.version)" } else { "not installed" }
Log ("$($s.Name): update skipped, $keep - " + $_.Exception.Message)
return
}
$what = if ($have) { "updated v$($have.version) -> v$($new.version)" } else { "installed v$($new.version)" }
# first install: nothing to disturb. Updates wait until WoW is closed.
if ($running -and $have) {
Log "$($s.Name): v$($new.version) downloaded ($($t.label), $($t.date)) - it installs when you close WoW"
return
}
try {
$changed = Install-EmbedStaging $s
} catch {
Log ("$($s.Name): couldn't install: " + $_.Exception.Message)
return
}
Log "$($s.Name): $what ($($t.label), $($t.sha.Substring(0, 7)), $($t.date))"
if ($running -and $changed) { Log "$($s.Name): exit WoW and start it again to load it (a /reload isn't enough)" }
}
function Update-Chronicle([switch]$Force) { Update-Embedded $EmbedSpecs.Chronicle -Force:$Force }
function Update-RollFor([switch]$Force) { Update-Embedded $EmbedSpecs.RollFor -Force:$Force }
function Update-Doping([switch]$Force) { Update-Embedded $EmbedSpecs.Doping -Force:$Force }
# run directly (not dot-sourced by WhoDidIt-Sync)
if ($MyInvocation.InvocationName -ne ".") {
$ErrorActionPreference = "Stop"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if ($FromZip -and -not $EmbedSpecs.ContainsKey($Only)) { throw "-FromZip needs -Only Chronicle, RollFor or Doping (the addon the zip is)" }
foreach ($k in @("Chronicle", "RollFor", "Doping")) {
if ($Only -and $Only -ne $k) { continue }
Update-Embedded $EmbedSpecs[$k] -Force:$Force
}
}