67 lines
3.1 KiB
PowerShell
67 lines
3.1 KiB
PowerShell
# ===========================================================================
|
|
# 补丁 v10:重写四个角度按钮槽
|
|
# * 统一入口 adjustSelectedAngle(step)
|
|
# * 没选中输入框时按焦点推断;仍没有则弹提示(不再静默失效)
|
|
# * 以界面当前值为基准加减(手工输入不会被旧值覆盖)
|
|
# ===========================================================================
|
|
$ErrorActionPreference = 'Stop'
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
|
|
|
$root = 'D:\Code\cavity_LIBS_system-master'
|
|
$cpp = Join-Path $root 'mainwindow.cpp'
|
|
$inc = Join-Path $root 'msvc-deps\angle_slots.inc'
|
|
|
|
$text = [System.IO.File]::ReadAllText($cpp, [System.Text.Encoding]::UTF8)
|
|
if ($text.Contains("`r")) { throw '文件含 CR,非预期' }
|
|
$lines = $text -split "`n"
|
|
|
|
# 定位:从 sub_1 的注释行 到 add_2 的结束大括号
|
|
$start = 0; $end = 0
|
|
for ($i = 1; $i -le $lines.Count; $i++) {
|
|
if ($lines[$i-1] -match 'void MainWindow::on_but_angle_sub_1_clicked') { $start = $i - 1; break }
|
|
}
|
|
if ($start -eq 0) { throw '找不到 sub_1 槽' }
|
|
if ($lines[$start-1].Trim() -notmatch '^//') { $start = $start + 1 } # 上面的注释行
|
|
for ($i = $start; $i -le $lines.Count; $i++) {
|
|
if ($lines[$i-1] -match 'void MainWindow::on_but_angle_restoration_clicked') { $end = $i - 2; break }
|
|
}
|
|
if ($end -eq 0) { throw '找不到重置按钮槽' }
|
|
while ($lines[$end-1].Trim() -eq '') { $end-- }
|
|
|
|
Write-Host "替换区间:第 $start .. $end 行(共 $($end - $start + 1) 行)"
|
|
Write-Host " 首行:$($lines[$start-1].Trim())"
|
|
Write-Host " 末行:$($lines[$end-1].Trim())"
|
|
|
|
# 读取新内容(UTF-8,去掉结尾空行)
|
|
$newLines = ([System.IO.File]::ReadAllText($inc, [System.Text.Encoding]::UTF8) -split "`n")
|
|
while ($newLines.Count -gt 0 -and $newLines[$newLines.Count - 1] -eq '') {
|
|
$newLines = $newLines[0..($newLines.Count - 2)]
|
|
}
|
|
|
|
$before = if ($start -gt 1) { $lines[0..($start - 2)] } else { @() }
|
|
$after = if ($end -lt $lines.Count) { $lines[$end..($lines.Count - 1)] } else { @() }
|
|
$lines = @($before) + @($newLines) + @($after)
|
|
|
|
[System.IO.File]::WriteAllText($cpp, ($lines -join "`n"), $utf8NoBom)
|
|
Write-Host "写完:$($lines.Count) 行"
|
|
|
|
# 校验
|
|
$s = [System.Text.Encoding]::UTF8.GetString([System.IO.File]::ReadAllBytes($cpp))
|
|
Write-Host ''
|
|
Write-Host '==== 校验 ===='
|
|
Write-Host (" 汉字={0} 非法UTF8={1} {{={2} }}={3}" -f `
|
|
([regex]::Matches($s,'[\u4e00-\u9fff]')).Count, ([regex]::Matches($s,[char]0xFFFD)).Count,
|
|
([regex]::Matches($s,'\{')).Count, ([regex]::Matches($s,'\}')).Count)
|
|
foreach ($k in 'adjustSelectedAngle','ensureAngleTargetSelected') {
|
|
Write-Host (" {0} 出现 {1} 次" -f $k, ([regex]::Matches($s,[regex]::Escape($k))).Count)
|
|
}
|
|
$nl = $s -split "`n"
|
|
for ($i = 1; $i -le $nl.Count; $i++) {
|
|
if ($nl[$i-1] -match 'void MainWindow::on_but_angle_(add|sub)_\d_clicked') {
|
|
Write-Host (" {0,4} {1}" -f $i, $nl[$i-1])
|
|
Write-Host (" {0,4} {1}" -f ($i+1), $nl[$i])
|
|
Write-Host (" {0,4} {1}" -f ($i+2), $nl[$i+1])
|
|
Write-Host (" {0,4} {1}" -f ($i+3), $nl[$i+2])
|
|
}
|
|
}
|