66 lines
3.6 KiB
PowerShell
66 lines
3.6 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$root = [System.IO.Path]::GetFullPath((Split-Path (Split-Path $PSScriptRoot -Parent) -Parent))
|
|
try {
|
|
if (-not [Environment]::Is64BitOperatingSystem -or $env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
|
|
throw '此离线包需要 Intel/AMD 64 位 Windows 电脑。'
|
|
}
|
|
|
|
$manifestPath = Join-Path $root 'manifest.json'
|
|
if (-not (Test-Path -LiteralPath $manifestPath -PathType Leaf)) {
|
|
throw '未找到离线包清单 manifest.json。请解压完整离线包后再启动。'
|
|
}
|
|
$manifest = Get-Content -Raw -Encoding UTF8 $manifestPath | ConvertFrom-Json
|
|
$maxRelativePath = 0
|
|
foreach ($entry in $manifest.files) {
|
|
if ($null -eq $entry.path -or $entry.path -isnot [string] -or [string]::IsNullOrWhiteSpace($entry.path)) {
|
|
throw '离线包清单包含无效文件路径。请重新解压完整离线包。'
|
|
}
|
|
if ($entry.path.Length -gt $maxRelativePath) { $maxRelativePath = $entry.path.Length }
|
|
}
|
|
if ($maxRelativePath -eq 0) { throw '离线包清单没有文件路径。请重新解压完整离线包。' }
|
|
$maxRootLength = 248 - $maxRelativePath
|
|
if ($root.Length -gt $maxRootLength) {
|
|
$recommended = if ($env:LOCALAPPDATA) { Join-Path $env:LOCALAPPDATA 'QualityCenter' } else { '当前用户可写的较短本地 NTFS 目录' }
|
|
throw "部署目录路径过长:根路径和清单最长相对路径不能超过 248 个字符。请尝试 $recommended;若该路径仍过长,请选择更短的当前用户可写 NTFS 目录。"
|
|
}
|
|
$driveRoot = [System.IO.Path]::GetPathRoot($root)
|
|
$drive = [System.IO.DriveInfo]::new($driveRoot)
|
|
if ($drive.DriveType -ne [System.IO.DriveType]::Fixed -or $drive.DriveFormat -ne 'NTFS') {
|
|
throw '请将离线包解压到本机固定 NTFS 磁盘上的当前用户可写目录。'
|
|
}
|
|
|
|
$python = Join-Path $root 'runtimes\python\python.exe'
|
|
if (-not (Test-Path -LiteralPath $python -PathType Leaf)) {
|
|
throw '未找到随包提供的 Python 运行环境。请重新解压完整离线包。'
|
|
}
|
|
$env:PYTHONUTF8 = '1'
|
|
$env:PYTHONIOENCODING = 'utf-8'
|
|
$env:PYTHONDONTWRITEBYTECODE = '1'
|
|
$env:QUALITY_UPDATE_ENABLED = 'true'
|
|
|
|
# Recover an interrupted app-local update before reading mutable deployment
|
|
# configuration or starting the local service processes.
|
|
& $python (Join-Path $root 'deploy\bootstrap\update-recovery.py')
|
|
if ($LASTEXITCODE -ne 0) { throw '更新恢复仍未完成。请保留本地更新备份后重试。' }
|
|
|
|
$port = 5280
|
|
$config = Join-Path $root '.runtime\deployment.json'
|
|
if (Test-Path -LiteralPath $config -PathType Leaf) {
|
|
$port = [int](Get-Content -Raw -Encoding UTF8 $config | ConvertFrom-Json).webPort
|
|
}
|
|
if ($port -lt 1024 -or $port -gt 65535) { throw '网页端口配置无效。' }
|
|
|
|
if (Test-Path (Join-Path $root 'migration\manifest.json')) {
|
|
& $python (Join-Path $root 'deploy\offline\restore_migration.py')
|
|
if ($LASTEXITCODE -ne 0) { throw '数据恢复未完成。现有数据库已保留,请查看 runtimedata\logs。' }
|
|
}
|
|
|
|
Write-Host '正在以当前用户启动本机应用进程;不会安装系统组件、创建 Windows 服务或更改防火墙规则。'
|
|
Write-Host "网页服务使用内网监听,端口为 $port。其他设备能否访问取决于 Windows 当前防火墙和网络策略。"
|
|
& $python (Join-Path $root 'deploy\offline\control.py') start --lan
|
|
if ($LASTEXITCODE -ne 0) { throw '启动未完成。请查看 runtimedata\logs\supervisor.log。' }
|
|
} catch {
|
|
Write-Host $_ -ForegroundColor Red
|
|
exit 1
|
|
}
|