Files
MyGoNavi/internal/app/windows_msi_update_script.go
Syngnat 3ac390f0dc 🐛 fix(update): 支持 Windows 便携版 ZIP 自动更新
- 将便携版更新资产切换为普通 ZIP,并兼容复用已下载包
- 解压后映射版本化目标文件名,保留旧版 EXE 更新兼容
- 将内嵌 PowerShell 更新脚本策略收紧为 RemoteSigned
- 补充 ZIP、目标路径与启动参数回归测试
2026-07-23 13:07:03 +08:00

59 lines
1.6 KiB
Go

package app
import (
_ "embed"
"os/exec"
"strconv"
"strings"
)
//go:embed windows_msi_update.ps1
var windowsMSIUpdatePowerShellScript string
//go:embed windows_shortcut_repair.ps1
var windowsShortcutRepairPowerShellScript string
type windowsMSIUpdateLaunchContext struct {
SourcePath string
TargetPath string
StagedDir string
LogPath string
MSILogPath string
MSIExecPath string
MaintenanceEventName string
HandoffEventName string
PID int
}
func buildWindowsMSIUpdatePowerShellScript() string {
script := windowsShortcutRepairPowerShellScript + "\n\n" + windowsMSIUpdatePowerShellScript
normalized := strings.ReplaceAll(script, "\r\n", "\n")
return strings.ReplaceAll(normalized, "\n", "\r\n")
}
func buildWindowsMSILaunchCommand(scriptPath string, context windowsMSIUpdateLaunchContext) *exec.Cmd {
cmd := exec.Command(
"powershell.exe",
"-NoProfile",
"-NonInteractive",
"-ExecutionPolicy",
windowsUpdatePowerShellExecutionPolicy,
"-File",
scriptPath,
)
cmd.Dir = context.StagedDir
cmd.Env = append(cmd.Environ(),
"GONAVI_UPDATE_SOURCE="+context.SourcePath,
"GONAVI_UPDATE_TARGET="+context.TargetPath,
"GONAVI_UPDATE_STAGED_DIR="+context.StagedDir,
"GONAVI_UPDATE_LOG_PATH="+context.LogPath,
"GONAVI_UPDATE_MSI_LOG_PATH="+context.MSILogPath,
"GONAVI_UPDATE_MSIEXEC_PATH="+context.MSIExecPath,
"GONAVI_UPDATE_MAINTENANCE_EVENT_NAME="+context.MaintenanceEventName,
"GONAVI_UPDATE_HANDOFF_EVENT_NAME="+context.HandoffEventName,
"GONAVI_UPDATE_PID="+strconv.Itoa(context.PID),
)
configureWindowsUpdateCommand(cmd)
return cmd
}