192 lines
5.4 KiB
PowerShell
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 "" |