XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEToolBox

【WPF】XFE工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
$ErrorActionPreference = 'Stop'
$repositoryRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
$workspaceBase = Join-Path $env:LOCALAPPDATA 'XFEToolBox/CrossVersion/EditorWorkspaces'
$libraryRoot = Join-Path $repositoryRoot 'XFEToolBox.QuickTools'
$sourceFiles = @((Get-Item -LiteralPath (Join-Path $libraryRoot 'QuickToolCatalog.cs')))
$sourceFiles += Get-ChildItem -LiteralPath (Join-Path $libraryRoot 'Services'), (Join-Path $libraryRoot 'Views') -Filter '*.cs' -File
$projects = [ordered]@{
    ClipboardPlus = 'Clipboard'; ScreenAssistant = 'Screen'; QuickCalculator = 'Calculator'; PortInspector = 'Ports'
    DeveloperText = 'Text'; BatchRenamer = 'Rename'; QrTool = 'Qr'; SystemShortcuts = 'System'
}
$notes = @{
    ClipboardPlus = '重做片段库、搜索筛选、片段详情与隐私设置。'
    ScreenAssistant = '重做截图画布、工具栏、像素缩放与 OCR 结果区。'
    QuickCalculator = '新增可点击的计算器键盘、大号结果、历史记录及独立换算分页。'
    PortInspector = '重做端口进程表格、实时筛选、端点统计及进程检查器。'
    DeveloperText = '重做输入输出双栏编辑器、编码工具栏、正则与差异分页。'
    BatchRenamer = '重做规则面板、改名前后表格预览与执行/撤销操作区。'
    QrTool = '重做生成/识别分页、大尺寸二维码预览与解码内容区。'
    SystemShortcuts = '重做音频、麦克风、窗口置顶、防休眠与网络状态面板。'
}
$utf8 = [Text.UTF8Encoding]::new($false)
foreach ($folder in $projects.Keys) {
    $projectRoot = Join-Path $workspaceBase $folder
    # Generated source snapshots use a private namespace, so an older host cannot
    # silently replace the package UI with its built-in 1.0 implementation.
    $implementationRoot = Join-Path $projectRoot 'Code/Implementation'
    foreach ($source in $sourceFiles) {
        $relative = [IO.Path]::GetRelativePath($libraryRoot, $source.FullName)
        $destination = Join-Path $implementationRoot $relative
        [IO.Directory]::CreateDirectory([IO.Path]::GetDirectoryName($destination)) | Out-Null
        $content = [IO.File]::ReadAllText($source.FullName).Replace('XFEToolBox.QuickTools', 'XFEToolBox.Tools.QuickSuite')
        [IO.File]::WriteAllText($destination, "// Generated from XFEToolBox.QuickTools/$relative. Update through SynchronizeToolProjects.ps1.`n" + $content, $utf8)
    }
    [IO.File]::Copy((Join-Path $PSScriptRoot 'PackageTemplates/PackagedQuickTools.cs'), (Join-Path $implementationRoot 'PackagedQuickTools.cs'), $true)
    $entryPath = Join-Path $projectRoot 'Code/Views/MainPage.xaml.cs'
    $entry = [IO.File]::ReadAllText($entryPath).Replace('using XFEToolBox.Client.Utilities;', 'using XFEToolBox.Tools.QuickSuite;').Replace('QuickToolsBridge.Create(', 'PackagedQuickTools.Create(')
    [IO.File]::WriteAllText($entryPath, $entry, $utf8)
    $manifestPath = Join-Path $projectRoot 'manifest.json'
    $manifest = Get-Content -LiteralPath $manifestPath -Raw | ConvertFrom-Json
    $manifest.version = '1.1.0'
    if ($folder -eq 'QuickCalculator') { $manifest.window.minHeight = 640 }
    $manifest.description = $manifest.subtitle + '。' + $notes[$folder] + '界面及实现随工具包独立交付,正常功能无需管理员权限。'
    $manifest.releaseNotes = $notes[$folder] + '修复独立工具包入口;使用已有分类与 Fluent 图标;新版实现随包发布,不依赖主程序旧页面。'
    [IO.File]::WriteAllText($manifestPath, ($manifest | ConvertTo-Json -Depth 20) + "`n", $utf8)
    $readmePath = Join-Path $projectRoot 'README.md'
    $readme = [IO.File]::ReadAllText($readmePath)
    $readme = [regex]::Replace($readme, '(?m)^- 工具版本[^\r\n]*', '- 工具版本 1.1.0,需要 XFEToolBox 1.3.0 或更新的宿主。Code/Implementation 包含可编辑的完整实现快照,页面不依赖宿主旧版组件;NuGet 引用可在工程配置查看。')
    $designNote = '- 1.1.0 界面:' + $notes[$folder]
    if ($readme.Contains('- 1.1.0 界面:')) { $readme = [regex]::Replace($readme, '(?m)^- 1\.1\.0 界面:[^\r\n]*', $designNote) }
    else { $readme = $readme.TrimEnd() + "`n" + $designNote + "`n" }
    [IO.File]::WriteAllText($readmePath, $readme, $utf8)
    Write-Output "Synchronized $folder 1.1.0 ($($sourceFiles.Count) source files)"
}