# Requires Windows PowerShell 5.1 or newer. Native language downloads use Battle.net. [CmdletBinding()] param( [string]$WoWPath, [ValidateSet("none", "en", "enru")][string]$VoicePacks = "en", [string]$CachePath, [switch]$Restore, [string]$BackupPath, [ValidateSet("auto", "en", "ru")][string]$Language = "auto", [switch]$LanguageOnly, [switch]$NonInteractive ) Set-StrictMode -Version 2.0 $ErrorActionPreference = 'Stop' $bundle = $PSScriptRoot $utf8 = New-Object System.Text.UTF8Encoding($false) # RuenUI is the current addon ID. Legacy saves and bindings migrate during setup. $addonNames = @('RuenUI') $stage = $null; $gameLock = $null; $cacheLock = $null function Write-Utf8([string]$Path, [string]$Text) { [System.IO.File]::WriteAllText($Path, $Text, $utf8) } function Assert-GameClosed { if (@(Get-Process -Name Wow, WowClassic -ErrorAction SilentlyContinue).Count -gt 0) { throw 'Close World of Warcraft before installing or restoring. Battle.net can stay open.' } } function Assert-NoLinks([string]$Path) { $current = $Path while ($current) { if (Test-Path -LiteralPath $current) { $item = Get-Item -LiteralPath $current -Force if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw "This path uses a link/junction. Use the actual game folder: $current" } } $parent = Split-Path -Parent $current if ($parent -eq $current) { break } $current = $parent } } function Assert-NoNestedLinks([string]$Path) { Assert-NoLinks $Path if (Test-Path -LiteralPath $Path -PathType Container) { foreach ($item in @(Get-ChildItem -LiteralPath $Path -Recurse -Force)) { if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw "Linked content cannot be replaced safely: $($item.FullName)" } } } } function Resolve-Forever([string]$Candidate) { if (-not $Candidate) { return } $Candidate = $Candidate.Trim().Trim('"') if (Test-Path -LiteralPath $Candidate -PathType Container) { $Candidate = (Get-Item -LiteralPath $Candidate).FullName.TrimEnd([char[]]'\/') } foreach ($p in @($Candidate, (Join-Path $Candidate '_forever_'))) { if ((Split-Path -Leaf $p) -eq '_forever_' -and (Test-Path -LiteralPath (Join-Path $p 'Wow.exe') -PathType Leaf)) { return (Get-Item -LiteralPath $p).FullName } } } function Find-Forever { if ($WoWPath) { $found = Resolve-Forever $WoWPath if (-not $found) { throw 'The supplied folder must contain _forever_\Wow.exe, or be the _forever_ folder itself.' } return $found } $candidates = New-Object 'System.Collections.Generic.List[string]' foreach ($base in @($env:ProgramFiles, ${env:ProgramFiles(x86)})) { if ($base) { $candidates.Add((Join-Path $base 'World of Warcraft')) } } $registryPaths = @( 'HKLM:\SOFTWARE\Blizzard Entertainment\World of Warcraft', 'HKLM:\SOFTWARE\WOW6432Node\Blizzard Entertainment\World of Warcraft', 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\World of Warcraft', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\World of Warcraft' ) foreach ($key in $registryPaths) { $entry = Get-ItemProperty -LiteralPath $key -ErrorAction SilentlyContinue if ($entry) { foreach ($property in @('InstallPath', 'InstallLocation')) { $p = $entry.PSObject.Properties[$property] if ($p -and $p.Value) { $candidates.Add([string]$p.Value) } } } } foreach ($drive in @(Get-PSDrive -PSProvider FileSystem)) { foreach ($relative in @('World of Warcraft', 'Games\World of Warcraft', 'Battle.net\World of Warcraft', 'Program Files (x86)\World of Warcraft', 'Program Files\World of Warcraft')) { $candidates.Add((Join-Path $drive.Root $relative)) } } $found = @($candidates | ForEach-Object { Resolve-Forever $_ } | Sort-Object -Unique) if ($found.Count -eq 1) { return $found[0] } if ($found.Count -gt 1) { Write-Host 'Several Forever installations were found:' for ($i = 0; $i -lt $found.Count; $i++) { Write-Host ("{0}: {1}" -f ($i + 1), $found[$i]) } if ($NonInteractive) { throw 'Several installations found. Supply -WoWPath.' } $selection = Read-Host 'Enter the number to configure' $number = 0 if ([int]::TryParse($selection, [ref]$number) -and $number -ge 1 -and $number -le $found.Count) { return $found[$number - 1] } throw 'No valid installation selected. Nothing changed.' } if ($NonInteractive) { throw 'No unique installation found. Supply -WoWPath.' } $chosen = Read-Host 'Paste the World of Warcraft folder path (Forever must already be installed)' $result = Resolve-Forever $chosen if (-not $result) { throw 'Could not find _forever_\Wow.exe. Nothing changed.' } return $result } function Test-LanguageSelection([string]$Root) { $info = Join-Path (Split-Path -Parent $Root) '.build.info' if (-not (Test-Path -LiteralPath $info -PathType Leaf)) { return $false } $rows = @(Get-Content -LiteralPath $info | ConvertFrom-Csv -Delimiter '|') foreach ($row in $rows) { $product = $row.PSObject.Properties | Where-Object { $_.Name -like 'Product!*' } | Select-Object -First 1 $active = $row.PSObject.Properties | Where-Object { $_.Name -like 'Active!*' } | Select-Object -First 1 $tags = $row.PSObject.Properties | Where-Object { $_.Name -like 'Tags!*' } | Select-Object -First 1 if ($product -and $product.Value -eq 'wowf' -and $active -and $active.Value -eq '1' -and $tags) { foreach ($locale in @('enUS', 'ruRU')) { foreach ($kind in @('text', 'speech')) { if ($tags.Value -notmatch ($locale + '\s+' + $kind + '\?')) { return $false } } } return $true } } return $false } function Prepare-Languages([string]$Root) { if (Test-LanguageSelection $Root) { Write-Host 'English + Russian are selected in the game installation. Wait for Battle.net to finish any active download before playing.' return } Write-Host 'One-time game language preparation / Однократная загрузка языков игры' -ForegroundColor Yellow Write-Host 'Battle.net > WoW: Forever > gear next to Play > Modify Install.' Write-Host 'For immediate Russian startup, select Russian for BOTH default Text and Speech languages in the same dialog.' Write-Host 'Keep BOTH English and Russian checked. Start Update and wait until the download reaches 100%, even if Play appears earlier.' Write-Host 'Battle.net > WoW: Forever > шестерёнка > Изменить установку.' Write-Host 'Оставьте английский и русский. Начните обновление и дождитесь 100%, даже если «Играть» появится раньше.' Write-Host 'The addon recordings are bundled; Blizzard game files are downloaded by Battle.net once on this PC.' if ($NonInteractive) { throw 'English and Russian native game files have not both been selected. Complete Modify Install, then run this installer again.' } foreach ($base in @(${env:ProgramFiles(x86)}, $env:ProgramFiles)) { if (-not $base) { continue } $launcher = Join-Path $base 'Battle.net/Battle.net Launcher.exe' if (Test-Path -LiteralPath $launcher -PathType Leaf) { Start-Process -FilePath $launcher; break } } $answer = Read-Host 'When the download finishes, press Enter; type cancel to stop / После загрузки нажмите Enter (cancel — отмена)' if ($answer -eq 'cancel') { throw 'Cancelled before changing files.' } Assert-GameClosed if (-not (Test-LanguageSelection $Root)) { throw 'Both languages are still not selected for WoW: Forever. Complete Modify Install, then run this installer again.' } } function Language-Config([string]$Root, [string]$Locale) { $file = Join-Path $Root 'WTF/Config.wtf' $text = if (Test-Path -LiteralPath $file -PathType Leaf) { [IO.File]::ReadAllText($file) } else { '' } $lines = @($text -split '\r?\n' | Where-Object { $_ -notmatch '^SET\s+(textLocale|audioLocale)\s' -and $_ -ne '' }) $lines += 'SET textLocale "' + $Locale + '"' $lines += 'SET audioLocale "' + $Locale + '"' return ($lines -join "`r`n") + "`r`n" } function Safe-RelativePath([string]$Root, [string]$Relative) { if ([IO.Path]::IsPathRooted($Relative) -or $Relative -match '(^|[\\/])\.\.([\\/]|$)' -or $Relative.Contains(':')) { throw "Invalid relative path in package: $Relative" } $path = Join-Path $Root $Relative Assert-NoLinks $path return $path } function Verify-Package { $manifest = Get-Content -LiteralPath (Join-Path $bundle 'manifest.json') -Raw | ConvertFrom-Json if ($manifest.format -ne 1) { throw 'Unsupported package format.' } $listed = @{} Assert-NoNestedLinks $bundle foreach ($entry in $manifest.files) { if ($listed.ContainsKey($entry.path)) { throw 'Duplicate manifest entry.' }; $listed[$entry.path] = $true $path = Safe-RelativePath $bundle $entry.path if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "Package file missing: $($entry.path). Extract the whole ZIP first." } $hash = (Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash if ($hash -ne $entry.sha256) { throw "Package integrity check failed: $($entry.path). Extract a fresh copy." } } foreach ($file in @(Get-ChildItem -LiteralPath $bundle -File -Recurse -Force)) { $rel = $file.FullName.Substring($bundle.Length).TrimStart([char[]]'\/').Replace('\','/') if ($rel -ne 'manifest.json' -and -not $listed.ContainsKey($rel)) { throw ('Unexpected package file: ' + $rel) } } if (-not (Select-String -LiteralPath (Join-Path $bundle 'RuenUI/RuenUI.toc') -Pattern '^## Interface:.*16001' -Quiet)) { throw 'This release is not marked compatible with Forever.' } } function Restore-Receipt([string]$Backup) { $receiptPath = Join-Path $Backup 'receipt.json' $receipt = Get-Content -LiteralPath $receiptPath -Raw | ConvertFrom-Json if ($receipt.format -ne 1) { throw 'Unsupported backup format.' } $root = Resolve-Forever $receipt.gameRoot if (-not $root -or $root -ne $receipt.gameRoot) { throw 'The backup game path is no longer valid.' } Assert-NoLinks $root Assert-NoNestedLinks $Backup $restoreLock = Join-Path $root '.ruen-install.lock' Assert-NoLinks $restoreLock $script:gameLock = [IO.File]::Open($restoreLock, [IO.FileMode]::OpenOrCreate, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None) $seen = @{} $backupRoots = @((Join-Path $root 'Ruen-UI-Backups'), (Join-Path $root 'Brad-Setup-Backups')) if ((Split-Path -Parent (Get-Item -LiteralPath $Backup).FullName) -notin $backupRoots) { throw 'Use an original backup inside this game install.' } foreach ($entry in @($receipt.entries)) { $relative = [string]$entry.path if ($seen.ContainsKey($relative)) { throw 'Duplicate backup target.' }; $seen[$relative] = $true if ($relative -notmatch '^(Interface/AddOns/((?:RuenUI|BradStockUI)(?:/LanguageDefaults\.lua)?|GunSilencerForever|Leatrix_Plus|Leatrix_Maps|Spoken|Spoken_Quests|SpokenQuestsAudioAlliance|SpokenQuestsAudioShared|SpokenQuestsAudio_ruRU|VoiceQuest)|WTF/Config\.wtf|WTF/Account/[^/]+/(config-cache\.wtf|bindings-cache\.wtf|AddOns\.txt|edit-mode-cache-account\.txt|SavedVariables/(GunSilencerForever|Leatrix_Plus|Leatrix_Maps|VoiceQuest|RuenUI|BradStockUI|Spoken|Spoken_Quests)\.lua(?:\.bak)?)|WTF/Account/[^/]+/[^/]+/[^/]+/(AddOns\.txt|config-cache\.wtf|bindings-cache\.wtf|edit-mode-cache-character\.txt|SavedVariables/(VoiceQuest|RuenUI|BradStockUI)\.lua(?:\.bak)?))$') { throw "Unexpected backup target: $relative" } $target = Safe-RelativePath $root $relative $old = Safe-RelativePath (Join-Path $Backup 'original') $relative if ($entry.existed -and -not (Test-Path -LiteralPath $old)) { throw "Backup missing: $relative" } Assert-NoNestedLinks $target Assert-NoNestedLinks $old } $restoreArchive = Join-Path $Backup ('before-restore-' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $restoreArchive | Out-Null foreach ($entry in @($receipt.entries)) { $relative = [string]$entry.path $target = Safe-RelativePath $root $relative $old = Safe-RelativePath (Join-Path $Backup 'original') $relative if (Test-Path -LiteralPath $target) { $retained = Safe-RelativePath $restoreArchive $relative New-Item -ItemType Directory -Path (Split-Path -Parent $retained) -Force | Out-Null Move-Item -LiteralPath $target -Destination $retained } if ($entry.existed) { New-Item -ItemType Directory -Path (Split-Path -Parent $target) -Force | Out-Null Copy-Item -LiteralPath $old -Destination $target -Recurse } } Write-Host "Restored the pre-install files. Later files were retained in: $restoreArchive" -ForegroundColor Green } function Add-BackupOnly([string]$Relative) { $plan.Add([pscustomobject]@{path = $Relative; source = $null; text = $null; backupOnly = $true}) } function Matches-Source([string]$Source, [string]$Target) { if (-not (Test-Path -LiteralPath $Target)) { return $false } if (Test-Path -LiteralPath $Source -PathType Leaf) { if (-not (Test-Path -LiteralPath $Target -PathType Leaf)) { return $false } return (Get-FileHash -LiteralPath $Source -Algorithm SHA256).Hash -eq (Get-FileHash -LiteralPath $Target -Algorithm SHA256).Hash } if (-not (Test-Path -LiteralPath $Target -PathType Container)) { return $false } $files = @(Get-ChildItem -LiteralPath $Source -File -Recurse -Force) if ($files.Count -ne @(Get-ChildItem -LiteralPath $Target -File -Recurse -Force).Count) { return $false } foreach ($file in $files) { $relative = $file.FullName.Substring($Source.Length).TrimStart([char[]]'\/') if (-not (Matches-Source $file.FullName (Join-Path $Target $relative))) { return $false } } return $true } try { Assert-GameClosed if ($Restore) { if (-not $BackupPath) { throw 'Supply -BackupPath with the backup folder printed by the installer.' } Restore-Receipt $BackupPath exit 0 } Verify-Package . (Join-Path $bundle 'Tools/Migrate-RuenUI.ps1') . (Join-Path $bundle 'Tools/Resolve-RuenDependencies.ps1') $gameRoot = Find-Forever Assert-NoLinks $gameRoot $lockPath = Join-Path $gameRoot '.ruen-install.lock' Assert-NoLinks $lockPath $gameLock = [IO.File]::Open($lockPath, [IO.FileMode]::OpenOrCreate, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None) Write-Host "Configuring: $gameRoot" if ($LanguageOnly -and $Language -eq 'auto') { throw 'Use -Language en or -Language ru with -LanguageOnly.' } if ($LanguageOnly -and -not (Test-Path -LiteralPath (Join-Path $gameRoot 'Interface/AddOns/RuenUI/Controls.lua'))) { throw 'Install the Ruen UI package before switching its language.' } if ($Language -ne 'auto') { Prepare-Languages $gameRoot } $plan = New-Object 'System.Collections.Generic.List[object]' if ($Language -eq 'auto') { Add-BackupOnly 'WTF/Config.wtf' } else { $locale = if ($Language -eq 'ru') { 'ruRU' } else { 'enUS' } $plan.Add([pscustomobject]@{path = 'WTF/Config.wtf'; source = $null; text = (Language-Config $gameRoot $locale)}) } if (-not $LanguageOnly) { if (-not $CachePath) { $CachePath = Join-Path $env:LOCALAPPDATA 'RuenUI/Downloads' } Assert-NoLinks $CachePath [void][IO.Directory]::CreateDirectory($CachePath) $cacheLockPath = Join-Path $CachePath '.install.lock' Assert-NoLinks $cacheLockPath $cacheLock = [IO.File]::Open($cacheLockPath, [IO.FileMode]::OpenOrCreate, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None) $stage = Join-Path $CachePath ('stage-' + [guid]::NewGuid().ToString('N')) [void][IO.Directory]::CreateDirectory($stage) Write-Host 'Ruen beta installs an ESDF layout and keybindings on each character. /ruen restore undoes its in-game preferences.' Write-Host 'Companion addons are fetched directly from their authors. Existing compatible addons and saved preferences are retained.' Write-Host 'Gun audio uses a suppressed recording at 100%; nearby stock gunfire is muted. /ruen guns off restores native sound.' $payload = Prepare-RuenDependencies $bundle $gameRoot $stage $VoicePacks $CachePath $stagedRuen = Join-Path $stage 'RuenUI' Copy-Item -LiteralPath $payload.Sources['RuenUI'] -Destination $stagedRuen -Recurse foreach ($name in @('HardwareProfile.lua', 'LanguageDefaults.lua')) { $existing = Join-Path $gameRoot ('Interface/AddOns/RuenUI/' + $name) Assert-NoLinks $existing if (Test-Path -LiteralPath $existing -PathType Leaf) { Copy-Item -LiteralPath $existing -Destination (Join-Path $stagedRuen $name) -Force } } $payload.Sources['RuenUI'] = $stagedRuen $addonNames = @($payload.Enabled) Assert-GameClosed foreach ($addon in @($payload.Sources.Keys | Sort-Object)) { $plan.Add([pscustomobject]@{path = 'Interface/AddOns/' + $addon; source = $payload.Sources[$addon]; text = $null}) } $accountRoot = Join-Path $gameRoot 'WTF/Account' $accounts = @() if (Test-Path -LiteralPath $accountRoot) { Assert-NoLinks $accountRoot $accounts = @(Get-ChildItem -LiteralPath $accountRoot -Directory | Where-Object { $_.Name -ne 'SavedVariables' }) } foreach ($account in $accounts) { Assert-NoLinks $account.FullName foreach ($relative in @('config-cache.wtf', 'bindings-cache.wtf', 'edit-mode-cache-account.txt', 'SavedVariables/RuenUI.lua', 'SavedVariables/GunSilencerForever.lua', 'SavedVariables/Leatrix_Plus.lua', 'SavedVariables/Leatrix_Maps.lua', 'SavedVariables/Spoken.lua', 'SavedVariables/Spoken_Quests.lua')) { Add-BackupOnly ('WTF/Account/' + $account.Name + '/' + $relative) } $accountAddons = Join-Path $account.FullName 'AddOns.txt' if (Test-Path -LiteralPath $accountAddons -PathType Leaf) { $lines = @(Get-Content -LiteralPath $accountAddons | Where-Object { (($_ -split ':', 2)[0].Trim()) -notin @($addonNames + 'BradStockUI') }) $lines += @($addonNames | ForEach-Object { $_ + ': enabled' }) $plan.Add([pscustomobject]@{path = 'WTF/Account/' + $account.Name + '/AddOns.txt'; source = $null; text = ($lines -join "`r`n") + "`r`n"}) } # First-login Ruen preferences merge in-game and retain originals for /ruen restore. # Never replace an existing companion addon's entire SavedVariables file. foreach ($realm in @(Get-ChildItem -LiteralPath $account.FullName -Directory | Where-Object { $_.Name -ne 'SavedVariables' })) { Assert-NoLinks $realm.FullName foreach ($character in @(Get-ChildItem -LiteralPath $realm.FullName -Directory | Where-Object { $_.Name -ne 'SavedVariables' })) { Assert-NoLinks $character.FullName $base = 'WTF/Account/' + $account.Name + '/' + $realm.Name + '/' + $character.Name foreach ($relative in @('config-cache.wtf', 'bindings-cache.wtf', 'edit-mode-cache-character.txt', 'SavedVariables/RuenUI.lua')) { Add-BackupOnly ($base + '/' + $relative) } $addonFile = Join-Path $character.FullName 'AddOns.txt' $lines = @() if (Test-Path -LiteralPath $addonFile) { $lines = @(Get-Content -LiteralPath $addonFile) } $lines = @($lines | Where-Object { (($_ -split ':', 2)[0].Trim()) -notin @($addonNames + 'BradStockUI') }) $lines += @($addonNames | ForEach-Object { $_ + ': enabled' }) $plan.Add([pscustomobject]@{path = $base + '/AddOns.txt'; source = $null; text = ($lines -join "`r`n") + "`r`n"}) } } } Add-RuenMigration $gameRoot $plan } # Full package installation if ($LanguageOnly) { $accountRoot = Join-Path $gameRoot 'WTF/Account' if (Test-Path -LiteralPath $accountRoot) { Assert-NoLinks $accountRoot foreach ($account in @(Get-ChildItem -LiteralPath $accountRoot -Directory | Where-Object { $_.Name -ne 'SavedVariables' })) { foreach ($addon in @('RuenUI', 'Spoken')) { Add-BackupOnly ('WTF/Account/' + $account.Name + '/SavedVariables/' + $addon + '.lua') } } } } if ($Language -ne 'auto') { $request = [guid]::NewGuid().ToString('N') $defaults = "local _, P = ...`nP.installLanguage = `"$locale`"`nP.installLanguageRequest = `"$request`"`n" if ($LanguageOnly) { $plan.Add([pscustomobject]@{path = 'Interface/AddOns/RuenUI/LanguageDefaults.lua'; source = $null; text = $defaults}) } else { $ruenItem = $plan | Where-Object { $_.path -eq 'Interface/AddOns/RuenUI' } | Select-Object -First 1 $ruenItem | Add-Member -NotePropertyName languageDefaults -NotePropertyValue $defaults } } # Validate every destination before making any changes. $needsChange = $false foreach ($item in $plan) { $target = Safe-RelativePath $gameRoot $item.path Assert-NoNestedLinks $target if ($item.PSObject.Properties['backupOnly']) { continue } if ($item.PSObject.Properties['languageDefaults']) { $needsChange = $true } if ($item.PSObject.Properties['removeOnly']) { if (Test-Path -LiteralPath $target) { $needsChange = $true } continue } if ($null -ne $item.text) { if (-not (Test-Path -LiteralPath $target -PathType Leaf) -or [IO.File]::ReadAllText($target) -ne $item.text) { $needsChange = $true } } elseif (-not (Matches-Source $item.source $target)) { $needsChange = $true } } if (-not $needsChange) { Write-Host 'This exact package and its preferences are already installed. No files or backups added.' -ForegroundColor Green exit 0 } [long]$required = 134217728 foreach ($item in $plan) { $target = Safe-RelativePath $gameRoot $item.path foreach ($path in @($target, $item.source)) { if ($path -and (Test-Path -LiteralPath $path)) { if (Test-Path -LiteralPath $path -PathType Leaf) { $required += (Get-Item -LiteralPath $path).Length } else { foreach ($file in @(Get-ChildItem -LiteralPath $path -File -Recurse)) { $required += $file.Length } } } } } Assert-RuenSpace $gameRoot $required $stamp = (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + [guid]::NewGuid().ToString('N').Substring(0, 8) $backup = Join-Path $gameRoot ('Ruen-UI-Backups/' + $stamp) Assert-NoLinks $backup New-Item -ItemType Directory -Path $backup -Force | Out-Null $entries = New-Object 'System.Collections.Generic.List[object]' $changed = New-Object 'System.Collections.Generic.List[object]' foreach ($item in $plan) { $target = Safe-RelativePath $gameRoot $item.path $existed = Test-Path -LiteralPath $target $entries.Add([pscustomobject]@{path = $item.path; existed = [bool]$existed}) if ($existed) { $old = Safe-RelativePath (Join-Path $backup 'original') $item.path New-Item -ItemType Directory -Path (Split-Path -Parent $old) -Force | Out-Null Copy-Item -LiteralPath $target -Destination $old -Recurse } } $receipt = [ordered]@{format = 1; gameRoot = $gameRoot; created = (Get-Date).ToString('o'); status = 'prepared'; entries = @($entries.ToArray())} Write-Utf8 (Join-Path $backup 'receipt.json') ($receipt | ConvertTo-Json -Depth 8) try { foreach ($item in $plan) { if ($item.PSObject.Properties['backupOnly']) { continue } Assert-GameClosed $target = Safe-RelativePath $gameRoot $item.path $entry = $entries | Where-Object { $_.path -eq $item.path } | Select-Object -First 1 $changed.Add($entry) New-Item -ItemType Directory -Path (Split-Path -Parent $target) -Force | Out-Null if (Test-Path -LiteralPath $target) { Remove-Item -LiteralPath $target -Recurse -Force } if ($item.PSObject.Properties['removeOnly']) { continue } if ($null -ne $item.text) { Write-Utf8 $target $item.text } else { Copy-Item -LiteralPath $item.source -Destination $target -Recurse } if ($item.PSObject.Properties['languageDefaults']) { Write-Utf8 (Join-Path $target 'LanguageDefaults.lua') $item.languageDefaults } } $receipt.status = 'installed' Write-Utf8 (Join-Path $backup 'receipt.json') ($receipt | ConvertTo-Json -Depth 8) } catch { $installError = $_ foreach ($entry in @($changed.ToArray())) { $target = Safe-RelativePath $gameRoot $entry.path if (Test-Path -LiteralPath $target) { Remove-Item -LiteralPath $target -Recurse -Force } if ($entry.existed) { Copy-Item -LiteralPath (Join-Path (Join-Path $backup 'original') $entry.path) -Destination $target -Recurse } } $receipt.status = 'rolled_back' Write-Utf8 (Join-Path $backup 'receipt.json') ($receipt | ConvertTo-Json -Depth 8) throw $installError } if ($LanguageOnly) { Write-Host "Language request saved: $locale. Enter a character once so Ruen UI updates Battle.net; then fully exit and relaunch WoW if the text is still in the old language." -ForegroundColor Green Write-Host "Backup: $backup" exit 0 } # Remember this installation for the reusable optimizer; each PC measures itself. if ($env:LOCALAPPDATA) { $localConfig = Join-Path $env:LOCALAPPDATA 'Ruen-UI' New-Item -ItemType Directory -Path $localConfig -Force | Out-Null Write-Utf8 (Join-Path $localConfig 'install.json') (@{gameRoot=$gameRoot} | ConvertTo-Json) } Write-Host 'For sustained optimization: launch WoW, then run Ruen-Setup.exe --optimize. Play normally; /reload imports the result.' Write-Host 'Installed: Ruen UI stock UI/graphics profile, Leatrix Plus, Leatrix Maps, Spoken with selected voice packs, Gun Silencer Forever.' -ForegroundColor Green Write-Host 'Launch WoW: Forever and enter a character. Settings apply automatically.' Write-Host 'A fresh account may request one /reload. Future changes are retained.' Write-Host 'Quest narration uses the voice packs you selected. /ruen language en or ru changes text/audio/narration (restart); /ruen voice en or ru changes narration immediately.' if ($Language -ne 'auto') { Write-Host "Language request: $locale. After download, enter a character once; Ruen UI updates the launcher. Fully exit/relaunch if text is still in the old language." } Write-Host "Backup: $backup" Write-Host 'To undo: run this script with -Restore -BackupPath followed by that folder in quotes.' } catch { Write-Host ("Setup stopped: " + $_.Exception.Message) -ForegroundColor Red if ($_.Exception -is [UnauthorizedAccessException] -or $_.Exception.Message -match 'access.+denied|permission denied') { Write-Host 'Run Install-Ruen-UI.cmd as administrator for this installation, or use a game folder you can write to.' } exit 1 } finally { if ($stage -and (Test-Path -LiteralPath $stage)) { Remove-Item -LiteralPath $stage -Recurse -Force } if ($cacheLock) { $cacheLock.Dispose() } if ($gameLock) { $gameLock.Dispose() } }