Files
MyGoNavi/internal/app/windows_msi_update_script.go
Syngnat 60d172254d 🐛 fix(update): 安装前确认并安全关闭当前安装的全部实例
- 安装更新前先确认关闭当前安装目录下的 GoNavi 实例,并继续执行未保存 SQL 退出保护
- 按可执行文件路径枚举并复核进程身份,优雅关闭超时后再强制终止,避免 PID 复用误杀
- 通过全局维护事件阻止更新期间启动新实例,并由 PowerShell 更新器完成跨权限无空窗交接
- 同步更新前端交互、多语言提示、Wails 绑定及 Windows 发布资产校验
2026-07-21 10:55:08 +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",
"Bypass",
"-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
}