|
| 1 | +param( |
| 2 | + [ValidateSet('Menu','Install','Check','Repair','Restore','Remove')][string]$Action='Menu', |
| 3 | + [string]$PackageDir=$PSScriptRoot, [string]$InstallDir=$PSScriptRoot, |
| 4 | + [string]$GameRoot, [string]$GameExe, |
| 5 | + [ValidateSet('dxgi.dll','winmm.dll','version.dll','dbghelp.dll','d3d12.dll','wininet.dll','winhttp.dll','OptiScaler.asi')][string]$Proxy, |
| 6 | + [switch]$NonInteractive |
| 7 | +) |
| 8 | +. (Join-Path $PSScriptRoot 'Aurora_Common.ps1') |
| 9 | +. (Join-Path $PSScriptRoot 'Aurora_Installer.ps1') |
| 10 | +$exitCode=0; $report=Join-Path ([IO.Path]::GetTempPath()) ('Aurora-RC3-'+[Guid]::NewGuid().ToString('N')+'.json') |
| 11 | +try { |
| 12 | + $PackageDir=Get-AuroraPath $PackageDir; $InstallDir=Get-AuroraPath $InstallDir |
| 13 | + Write-Host "`n Aurora 安装器 RC3`n" -ForegroundColor Cyan |
| 14 | + Write-Host ' 正在自动检测游戏…' |
| 15 | + if (-not $GameRoot -and ((Test-Path -LiteralPath (Join-Path $InstallDir 'OptiScaler\AuroraSetup\installation.json')) -or (Test-Path -LiteralPath (Get-AuroraIndexPath $InstallDir)))) { |
| 16 | + $GameRoot=Resolve-AuroraDeploymentRoot $InstallDir |
| 17 | + } |
| 18 | + if (-not $GameRoot) { |
| 19 | + $roots=@(Find-AuroraGames @($InstallDir,$PackageDir)) |
| 20 | + if ($roots.Count -eq 1) { $GameRoot=$roots[0] } |
| 21 | + elseif ($roots.Count -gt 1) { |
| 22 | + if ($NonInteractive) { throw '检测到多个游戏,请通过 GameRoot 指定本次游戏。' } |
| 23 | + $n=Read-AuroraChoice '检测到多个游戏,请选择要安装的游戏' ($roots+@('取消')) |
| 24 | + if ($n -gt $roots.Count) { exit 0 }; $GameRoot=$roots[$n-1] |
| 25 | + } else { |
| 26 | + if ($NonInteractive) { throw '未能自动定位游戏,请通过 GameRoot 指定游戏目录。' } |
| 27 | + $inputPath=Read-Host ' 未自动找到游戏,请粘贴游戏目录或 EXE 路径(直接回车退出)' |
| 28 | + if (-not $inputPath) { exit 0 }; $GameRoot=Resolve-AuroraDeploymentRoot $inputPath |
| 29 | + } |
| 30 | + } |
| 31 | + $GameRoot=Get-AuroraPath $GameRoot; Assert-AuroraGameRoot $GameRoot |
| 32 | + $index=Open-AuroraIndex $GameRoot |
| 33 | + if ($Action -in @('Menu','Install','Repair')) { |
| 34 | + $scan=Get-AuroraScan $GameRoot |
| 35 | + if (-not $scan.Complete -and $Action -ne 'Menu') { throw '游戏目录未能完整读取,已停止安装。请确认目录权限,并避免目录联接。' } |
| 36 | + $candidates=@(Get-AuroraDeploymentCandidates $scan) |
| 37 | + if (-not $candidates.Count -and $Action -ne 'Menu') { throw '未发现安全的 x64 游戏入口。请确认完整游戏目录;与 x64 工具共用目录的入口不会自动注入。' } |
| 38 | + if ($GameExe -and -not @($candidates | Where-Object { $_.Path -ieq (Get-AuroraPath $GameExe) }).Count) { throw '指定 EXE 未通过安全筛选。' } |
| 39 | + Write-Host (' ✓ 已检测到游戏:'+[IO.Path]::GetFileName($GameRoot)) -ForegroundColor Green |
| 40 | + Write-Host (' ✓ 将覆盖 '+@($candidates | Group-Object Directory).Count+' 个游戏入口目录') -ForegroundColor Green |
| 41 | + foreach ($c in @($candidates | Select-Object -First 3)) { Write-Host (' '+$c.Path.Substring($GameRoot.Length).TrimStart('\')) } |
| 42 | + if ($candidates.Count -gt 3) { Write-Host ' 其余入口见详细报告。' } |
| 43 | + if (-not $scan.Complete -or -not $candidates.Count) { Write-Host ' ! 当前不能安全安装;仍可选择恢复 / 卸载。' -ForegroundColor Yellow } |
| 44 | + Write-Host ' ✓ 自动匹配 Proxy,保留现有配置,替换前备份' -ForegroundColor Green |
| 45 | + Write-Host ' ! SL1 和未知 Runtime 保留;安装后请进游戏核对效果' -ForegroundColor Yellow |
| 46 | + Write-AuroraJson $report ([pscustomobject]@{GameRoot=$GameRoot;Candidates=$candidates;RuntimeGroups=@(Get-AuroraRuntimeGroups $scan $candidates)}) |
| 47 | + if (-not $NonInteractive) { |
| 48 | + while ($true) { |
| 49 | + Write-Host "`n [1 / Enter] 一键安装 / 更新`n [2] 修复 / 恢复 / 卸载`n [3] 高级工具与诊断`n [Q] 退出" |
| 50 | + $choice=Read-Host ' 请选择' |
| 51 | + if ($choice -in @('','1')) { $Action='Install'; break } |
| 52 | + if ($choice -ieq 'Q') { exit 0 } |
| 53 | + if ($choice -eq '2') { |
| 54 | + $n=Read-AuroraChoice '修复 / 恢复 / 卸载' @('修复安装并安全同步 Runtime','恢复游戏原版 Runtime','卸载所有已记录的 Aurora 副本','返回') |
| 55 | + if ($n -eq 4) { continue }; $Action=@('Repair','Restore','Remove')[$n-1]; break |
| 56 | + } |
| 57 | + if ($choice -eq '3') { |
| 58 | + $n=Read-AuroraChoice '高级工具与诊断' @('查看完整扫描报告','手动修改 Proxy','只读诊断实际加载情况','返回') |
| 59 | + if ($n -eq 1) { Get-Content -LiteralPath $report -Raw -Encoding UTF8 | Write-Host } |
| 60 | + if ($n -eq 2) { |
| 61 | + $proxies=@('dxgi.dll','winmm.dll','version.dll','dbghelp.dll','d3d12.dll','wininet.dll','winhttp.dll','OptiScaler.asi') |
| 62 | + Write-Host ' 异环默认 winmm.dll;已有第三方 Proxy 时不会覆盖。ASI 需要已有 ASI Loader。' -ForegroundColor Yellow |
| 63 | + $p=Read-AuroraChoice 'Proxy' ($proxies+@('返回自动策略')) |
| 64 | + $Proxy=$null; if ($p -le $proxies.Count) { $Proxy=$proxies[$p-1] } |
| 65 | + } |
| 66 | + if ($n -eq 3) { $Action='Check'; break } |
| 67 | + } |
| 68 | + } |
| 69 | + } elseif ($Action -eq 'Menu') { $Action='Install' } |
| 70 | + } |
| 71 | + if ($Action -in @('Install','Repair')) { |
| 72 | + Write-Host "`n 正在备份并部署 Aurora…" |
| 73 | + $index=Install-AuroraDeployment $GameRoot $PackageDir $Proxy $report |
| 74 | + Write-Host "`n ✓ 安装完成,所有候选入口已部署并校验。" -ForegroundColor Green |
| 75 | + Write-Host ' 可以启动游戏,按 Insert 核对 Aurora。' |
| 76 | + } elseif ($index -and $Action -in @('Restore','Remove')) { |
| 77 | + $preserved=@(Remove-AuroraDeployment $index $report -RuntimeOnly:($Action -eq 'Restore')) |
| 78 | + Write-Host "`n ✓ 已恢复可恢复的原版文件。" -ForegroundColor Green |
| 79 | + if ($Action -eq 'Remove') { Write-Host ' ✓ 已清理清单记录且未被修改的 Aurora 副本。' -ForegroundColor Green } |
| 80 | + if ($preserved.Count) { Write-Host (' ! 保留了 '+$preserved.Count+' 个用户修改文件,备份与详情已保留。') -ForegroundColor Yellow } |
| 81 | + } elseif ($index -and $Action -eq 'Check') { |
| 82 | + foreach ($target in $index.Targets) { |
| 83 | + foreach ($exe in $target.Executables) { |
| 84 | + $log=Join-Path ([IO.Path]::GetTempPath()) ('Aurora-Check-'+[Guid]::NewGuid().ToString('N')+'.log.txt') |
| 85 | + Invoke-AuroraRuntimeTask Check $GameRoot $target.Directory $log $exe |
| 86 | + Write-Host (' ✓ 诊断报告:'+$log) -ForegroundColor Green |
| 87 | + } |
| 88 | + } |
| 89 | + Save-AuroraInstallReport $index $report |
| 90 | + } else { |
| 91 | + # Existing RC2 installations keep their original recovery path and journals. |
| 92 | + $args=@('-NoProfile','-ExecutionPolicy','Bypass','-File',(Join-Path $PSScriptRoot 'Aurora_Setup_Legacy.ps1'),'-Action',$Action,'-InstallDir',$InstallDir,'-GameRoot',$GameRoot,'-NonInteractive') |
| 93 | + if ($GameExe) { $args+=@('-GameExe',$GameExe) } |
| 94 | + & powershell.exe @args 2>&1 | Out-File -LiteralPath ([IO.Path]::ChangeExtension($report,'.txt')) -Encoding utf8 -Append |
| 95 | + if ($LASTEXITCODE) { throw 'RC2 恢复 / 诊断未完成,请查看详情。' } |
| 96 | + Write-Host ' ✓ 操作完成。' -ForegroundColor Green |
| 97 | + } |
| 98 | +} catch { |
| 99 | + $exitCode=4 |
| 100 | + Write-Host ("`n ✕ "+$_.Exception.Message) -ForegroundColor Red |
| 101 | + $_ | Out-String | Add-Content -LiteralPath ([IO.Path]::ChangeExtension($report,'.log.txt')) -Encoding UTF8 |
| 102 | +} |
| 103 | +$available=@($report,[IO.Path]::ChangeExtension($report,'.txt'),[IO.Path]::ChangeExtension($report,'.log.txt')) | Where-Object { Test-Path -LiteralPath $_ } |
| 104 | +if (@($available).Count) { Write-Host ("`n 详细报告:"+@($available)[0]) } |
| 105 | +if (-not $NonInteractive) { |
| 106 | + while ((Read-Host ' [D] 查看详情 / [Enter] 退出') -ieq 'D') { |
| 107 | + foreach ($path in @($report,[IO.Path]::ChangeExtension($report,'.txt'),[IO.Path]::ChangeExtension($report,'.log.txt'))) { |
| 108 | + if (Test-Path -LiteralPath $path) { Get-Content -LiteralPath $path -Raw -Encoding UTF8 | Write-Host } |
| 109 | + } |
| 110 | + } |
| 111 | +} |
| 112 | +exit $exitCode |
0 commit comments