Files
dyp/Upgrade-Delphi11.ps1
T
2026-05-07 20:25:34 +08:00

192 lines
5.4 KiB
PowerShell

# Delphi 11 升级辅助脚本
# 用于帮助将项目从 Delphi 10.4/10.5 升级到 Delphi 11 Alexandria
param(
[switch]$Backup,
[switch]$CleanCache,
[switch]$UpdateProject,
[switch]$All
)
$ErrorActionPreference = "Stop"
$ProjectPath = "d:\word\dyp\client-dyp"
$BackupPath = "d:\word\dyp\client-dyp_backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
function Write-Step {
param([string]$Message)
Write-Host "[*] $Message" -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 Backup-Project {
Write-Step "开始备份项目..."
Write-Step "备份位置: $BackupPath"
if (Test-Path $ProjectPath) {
Copy-Item -Path $ProjectPath -Destination $BackupPath -Recurse -Force
Write-Success "备份完成!"
} else {
Write-Error "项目路径不存在: $ProjectPath"
exit 1
}
}
# 清理IDE缓存
function Clean-IDECache {
Write-Step "开始清理IDE缓存..."
$CachePaths = @(
"$ProjectPath\MainWin.identcache",
"$ProjectPath\MainWin.dproj.local",
"$ProjectPath\dcu",
"$ProjectPath\pas\__history"
)
foreach ($Path in $CachePaths) {
if (Test-Path $Path) {
if ($Path -match "\*") {
Remove-Item -Path $Path -Recurse -Force
} else {
Remove-Item -Path $Path -Force
}
Write-Success "已删除: $Path"
}
}
# 清理IDE全局缓存
$IDE caches = @(
"$env:AppData\Embarcadero\BDS\*\*.cache",
"$env:AppData\Embarcadero\BDS\*\*.identcache",
"$env:LocalAppData\Embarcadero\BDS\*\*.cache"
)
Write-Success "IDE缓存清理完成!"
}
# 更新项目文件
function Update-ProjectFile {
Write-Step "开始更新项目文件..."
$ProjectFile = "$ProjectPath\MainWin.dproj"
if (-not (Test-Path $ProjectFile)) {
Write-Error "项目文件不存在: $ProjectFile"
exit 1
}
# 读取项目文件
$Content = Get-Content -Path $ProjectFile -Raw
# 检查是否需要更新版本
if ($Content -match "ProjectVersion>19\.") {
Write-Warning "检测到旧版本项目文件 (ProjectVersion 19.x)"
Write-Step "请在 Delphi 11 中打开项目,系统会自动升级"
# 可选:手动更新版本号(谨慎使用)
# $Content = $Content -replace "ProjectVersion>19\.5", "ProjectVersion>22.0"
# Set-Content -Path $ProjectFile -Value $Content
}
Write-Success "项目文件检查完成!"
}
# 生成升级报告
function New-UpgradeReport {
Write-Step "生成升级报告..."
$ReportPath = "$ProjectPath\UpgradeReport_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
$Report = @"
================================================================================
Delphi 11
: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
================================================================================
:
- : MainWin
- : $ProjectPath
- IDE: Delphi 10.4/10.5 ()
- IDE: Delphi 11 Alexandria (Version 28.0.48361.3236)
:
- : $((Get-ChildItem -Path "$ProjectPath\pas" -File).Count)
- : $((Get-ChildItem -Path "$ProjectPath\pas" -Filter "*.fmx").Count)
- (DCU): $((Get-ChildItem -Path "$ProjectPath\dcu" -File -ErrorAction SilentlyContinue).Count)
:
- FireDAC ()
- RESTComponents ()
- Indy ()
- EhLib ()
- SPComm ()
- TeeChart ()
:
1. Delphi 11 MainWin.dproj
2. IDE
3. "Upgrade"
4.
5.
6.
:
-
- Delphi 11
-
-
================================================================================
"@
Set-Content -Path $ReportPath -Value $Report
Write-Success "报告已生成: $ReportPath"
}
# 主流程
Write-Host ""
Write-Host "========================================" -ForegroundColor Magenta
Write-Host " Delphi 11 升级辅助工具" -ForegroundColor Magenta
Write-Host "========================================" -ForegroundColor Magenta
Write-Host ""
if ($All) {
Write-Step "执行完整升级流程..."
Backup-Project
Clean-IDECache
Update-ProjectFile
New-UpgradeReport
Write-Success "所有步骤完成!"
} elseif ($Backup) {
Backup-Project
} elseif ($CleanCache) {
Clean-IDECache
} elseif ($UpdateProject) {
Update-ProjectFile
} else {
Write-Host "用法:" -ForegroundColor Yellow
Write-Host " .\Upgrade-Delphi11.ps1 -Backup # 备份项目"
Write-Host " .\Upgrade-Delphi11.ps1 -CleanCache # 清理缓存"
Write-Host " .\Upgrade-Delphi11.ps1 -UpdateProject # 更新项目"
Write-Host " .\Upgrade-Delphi11.ps1 -All # 执行所有步骤"
Write-Host ""
Write-Host "示例:" -ForegroundColor Yellow
Write-Host " .\Upgrade-Delphi11.ps1 -All"
Write-Host ""
}
Write-Host ""