diff --git a/.gitmodules b/.gitmodules index 1c08366..461366c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,15 +1,20 @@ [submodule "vendor/warcraftxl"] path = vendor/warcraftxl url = https://github.com/WarcraftXL/wxl-core.git + branch = main [submodule "vendor/modules/wxl-modern-assets"] path = vendor/modules/wxl-modern-assets url = https://github.com/WarcraftXL/wxl-modern-assets.git + branch = main [submodule "vendor/modules/wxl-modern-render"] path = vendor/modules/wxl-modern-render url = https://github.com/WarcraftXL/wxl-modern-render.git + branch = main [submodule "vendor/modules/wxl-unit-outline"] path = vendor/modules/wxl-unit-outline url = https://github.com/WarcraftXL/wxl-unit-outline.git + branch = main [submodule "vendor/modules/wxl-modern-adt"] path = vendor/modules/wxl-modern-adt url = https://github.com/WarcraftXL/wxl-modern-adt.git + branch = main diff --git a/run.ps1 b/run.ps1 index 38be751..0182c92 100644 --- a/run.ps1 +++ b/run.ps1 @@ -37,6 +37,42 @@ if (-not $env:WOW_HOME) { $WOW_HOME = $env:WOW_HOME Write-Host "WOW_HOME = $WOW_HOME" +function Test-ExistingFileWriteAccess { + param([Parameter(Mandatory=$true)][string]$Path) + + try { + $stream = [System.IO.File]::Open( + $Path, + [System.IO.FileMode]::Open, + [System.IO.FileAccess]::Write, + [System.IO.FileShare]::ReadWrite + ) + $stream.Close() + return $true + } catch [System.UnauthorizedAccessException] { + return $false + } catch { + # Sharing violations are handled later by Stop-WowRuntime. They do not + # indicate that the whole script needs an elevated token. + return $true + } +} + +$installedWarcraftXL = Join-Path $WOW_HOME "WarcraftXL.dll" +$isAdministrator = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( + [Security.Principal.WindowsBuiltInRole]::Administrator +) + +if ((Test-Path -LiteralPath $installedWarcraftXL -PathType Leaf) -and + -not (Test-ExistingFileWriteAccess -Path $installedWarcraftXL) -and + -not $isAdministrator) { + Write-Host "WarcraftXL.dll requires administrator access. Requesting elevation..." + $elevatedProcess = Start-Process -FilePath "powershell.exe" -Verb RunAs -PassThru -Wait ` + -WorkingDirectory $ROOT ` + -ArgumentList "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "`"$($MyInvocation.MyCommand.Path)`"", "-Env", $Env + exit $elevatedProcess.ExitCode +} + # --- Paths $SRC_DIR = Join-Path $ROOT "src" $DIST_DIR = Join-Path $ROOT "dist" @@ -44,6 +80,36 @@ $TOOL = Join-Path $ROOT "tool\target\release\tool.exe" $RELOAD_SCRIPT = Join-Path $ROOT "reload_wow.bat" $WXL_BUILD_SCRIPT = Join-Path $ROOT "build-warcraftxl.ps1" +function Stop-WowRuntime { + param([Parameter(Mandatory=$true)][string]$ClientPath) + + $clientRoot = [System.IO.Path]::GetFullPath($ClientPath).TrimEnd('\') + '\' + $runtimeProcesses = @(Get-Process -Name "Wow", "WarcraftXLHost" -ErrorAction SilentlyContinue | Where-Object { + try { + $_.Path -and $_.Path.StartsWith($clientRoot, [System.StringComparison]::OrdinalIgnoreCase) + } catch { + $false + } + }) + + if (-not $runtimeProcesses.Count) { + return + } + + Write-Host "Stopping the running WoW client and WarcraftXL host..." + $runtimeProcesses | Stop-Process -Force + + try { + $runtimeProcesses | Wait-Process -Timeout 10 -ErrorAction Stop + } catch { + $stillRunning = @($runtimeProcesses | Where-Object { -not $_.HasExited }) + if ($stillRunning.Count) { + $processNames = ($stillRunning | ForEach-Object { "$($_.ProcessName) (PID $($_.Id))" }) -join ", " + throw "Could not stop processes that lock WarcraftXL files: $processNames" + } + } +} + # --- Ensure tool exists if (!(Test-Path $TOOL)) { Write-Host "Building Rust tool..." @@ -68,6 +134,7 @@ if (!(Test-Path (Join-Path $DIST_DIR "Data"))) { # --- Build/package/deploy WarcraftXL before the dist sync. The packaged files # are uploaded by upload_to_s3.py and consumed by the launcher manifest. +Stop-WowRuntime -ClientPath $WOW_HOME Write-Host "Building and packaging WarcraftXL..." & $WXL_BUILD_SCRIPT -Configuration Release -ClientPath $WOW_HOME ` -PackagePath $DIST_DIR -Deploy diff --git a/vendor/warcraftxl b/vendor/warcraftxl index 72fb680..ee9d8a9 160000 --- a/vendor/warcraftxl +++ b/vendor/warcraftxl @@ -1 +1 @@ -Subproject commit 72fb6808773bbf773f75e7cf5664997ad3a7fa49 +Subproject commit ee9d8a92a34faf708678873a643a4bfe8ec1cea5