191 lines
5.0 KiB
PowerShell
191 lines
5.0 KiB
PowerShell
# ========================================
|
||
# UE插件引擎版本批量更新工具
|
||
# 作者: AI Assistant
|
||
# 版本: 1.0.0
|
||
# ========================================
|
||
|
||
param(
|
||
[Parameter(HelpMessage="项目路径")]
|
||
[string]$ProjectPath = "E:\UE5\TG_ARPG",
|
||
|
||
[Parameter(HelpMessage="目标引擎版本")]
|
||
[string]$TargetVersion = "5.8.0",
|
||
|
||
[Parameter(HelpMessage="仅检查不更新")]
|
||
[switch]$CheckOnly,
|
||
|
||
[Parameter(HelpMessage="显示详细信息")]
|
||
[switch]$ShowDetails
|
||
)
|
||
|
||
function Write-Header {
|
||
param([string]$Title)
|
||
Write-Host "`n========================================" -ForegroundColor Cyan
|
||
Write-Host " $Title" -ForegroundColor Cyan
|
||
Write-Host "========================================`n" -ForegroundColor Cyan
|
||
}
|
||
|
||
function Write-Success {
|
||
param([string]$Message)
|
||
Write-Host "✅ $Message" -ForegroundColor Green
|
||
}
|
||
|
||
function Write-Warning {
|
||
param([string]$Message)
|
||
Write-Host "⚠️ $Message" -ForegroundColor Yellow
|
||
}
|
||
|
||
function Write-Error {
|
||
param([string]$Message)
|
||
Write-Host "❌ $Message" -ForegroundColor Red
|
||
}
|
||
|
||
function Write-Info {
|
||
param([string]$Message)
|
||
Write-Host "ℹ️ $Message" -ForegroundColor Blue
|
||
}
|
||
|
||
function Get-PluginEngineVersion {
|
||
param([string]$PluginFile)
|
||
|
||
try {
|
||
$content = Get-Content -Path $PluginFile -Raw -ErrorAction Stop
|
||
if ($content -match '"EngineVersion":\s*"([^"]+)"') {
|
||
return $Matches[1]
|
||
}
|
||
return $null
|
||
}
|
||
catch {
|
||
return $null
|
||
}
|
||
}
|
||
|
||
function Update-PluginEngineVersion {
|
||
param(
|
||
[string]$PluginFile,
|
||
[string]$TargetVersion
|
||
)
|
||
|
||
try {
|
||
$content = Get-Content -Path $PluginFile -Raw -ErrorAction Stop
|
||
$originalContent = $content
|
||
|
||
# 替换 EngineVersion
|
||
$newContent = $content -replace '"EngineVersion":\s*"[^"]+"', "`"EngineVersion`": `"$TargetVersion`""
|
||
|
||
if ($content -ne $newContent) {
|
||
Set-Content -Path $PluginFile -Value $newContent -Encoding UTF8 -ErrorAction Stop
|
||
return $true
|
||
}
|
||
return $false
|
||
}
|
||
catch {
|
||
Write-Error "更新失败: $($_.Exception.Message)"
|
||
return $false
|
||
}
|
||
}
|
||
|
||
# ========================================
|
||
# 主程序
|
||
# ========================================
|
||
|
||
Write-Header "UE插件引擎版本批量更新工具"
|
||
|
||
# 验证项目路径
|
||
if (-not (Test-Path $ProjectPath)) {
|
||
Write-Error "项目路径不存在: $ProjectPath"
|
||
exit 1
|
||
}
|
||
|
||
$PluginsPath = Join-Path $ProjectPath "Plugins"
|
||
if (-not (Test-Path $PluginsPath)) {
|
||
Write-Error "插件目录不存在: $PluginsPath"
|
||
exit 1
|
||
}
|
||
|
||
Write-Info "项目路径: $ProjectPath"
|
||
Write-Info "插件目录: $PluginsPath"
|
||
Write-Info "目标版本: $TargetVersion"
|
||
if ($CheckOnly) {
|
||
Write-Info "模式: 仅检查"
|
||
}
|
||
Write-Host ""
|
||
|
||
# 扫描所有插件
|
||
Write-Host "正在扫描插件..." -ForegroundColor Yellow
|
||
$pluginFiles = Get-ChildItem -Path $PluginsPath -Recurse -Filter "*.uplugin" -ErrorAction SilentlyContinue
|
||
|
||
if (-not $pluginFiles) {
|
||
Write-Warning "未找到任何插件"
|
||
exit 0
|
||
}
|
||
|
||
Write-Info "找到 $($pluginFiles.Count) 个插件"
|
||
Write-Host ""
|
||
|
||
# 统计
|
||
$stats = @{
|
||
Updated = 0
|
||
AlreadyLatest = 0
|
||
NoVersion = 0
|
||
Failed = 0
|
||
Total = $pluginFiles.Count
|
||
}
|
||
|
||
# 处理每个插件
|
||
foreach ($pluginFile in $pluginFiles) {
|
||
$pluginName = $pluginFile.BaseName
|
||
$pluginPath = $pluginFile.FullName
|
||
|
||
$currentVersion = Get-PluginEngineVersion -PluginFile $pluginPath
|
||
|
||
if ($null -eq $currentVersion) {
|
||
if ($ShowDetails) {
|
||
Write-Host "[$pluginName] " -NoNewline -ForegroundColor White
|
||
Write-Host "未指定引擎版本" -ForegroundColor Gray
|
||
}
|
||
$stats.NoVersion++
|
||
continue
|
||
}
|
||
|
||
Write-Host "[$pluginName] " -NoNewline -ForegroundColor White
|
||
Write-Host "当前版本: $currentVersion" -NoNewline
|
||
|
||
if ($currentVersion -eq $TargetVersion) {
|
||
Write-Host " (已是最新)" -ForegroundColor Green
|
||
$stats.AlreadyLatest++
|
||
continue
|
||
}
|
||
|
||
Write-Host " -> 目标: $TargetVersion" -ForegroundColor Yellow
|
||
|
||
if (-not $CheckOnly) {
|
||
$success = Update-PluginEngineVersion -PluginFile $pluginPath -TargetVersion $TargetVersion
|
||
if ($success) {
|
||
Write-Success " 已更新"
|
||
$stats.Updated++
|
||
}
|
||
else {
|
||
Write-Error " 更新失败"
|
||
$stats.Failed++
|
||
}
|
||
}
|
||
else {
|
||
Write-Info " (检查模式 - 未更新)"
|
||
}
|
||
}
|
||
|
||
# 输出统计
|
||
Write-Header "更新统计"
|
||
Write-Host "总插件数: $($stats.Total)" -ForegroundColor White
|
||
Write-Host "已更新: $($stats.Updated)" -ForegroundColor Green
|
||
Write-Host "已是最新: $($stats.AlreadyLatest)" -ForegroundColor Blue
|
||
Write-Host "无版本号: $($stats.NoVersion)" -ForegroundColor Gray
|
||
Write-Host "更新失败: $($stats.Failed)" -ForegroundColor Red
|
||
|
||
if ($CheckOnly) {
|
||
Write-Host "`n提示: 使用 -CheckOnly 参数可以只检查而不更新" -ForegroundColor Yellow
|
||
}
|
||
|
||
Write-Host "`n完成!`n" -ForegroundColor Green
|