mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-07 07:03:34 +08:00
- 安装更新前先确认关闭当前安装目录下的 GoNavi 实例,并继续执行未保存 SQL 退出保护 - 按可执行文件路径枚举并复核进程身份,优雅关闭超时后再强制终止,避免 PID 复用误杀 - 通过全局维护事件阻止更新期间启动新实例,并由 PowerShell 更新器完成跨权限无空窗交接 - 同步更新前端交互、多语言提示、Wails 绑定及 Windows 发布资产校验
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"errors"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
type windowsUpdateMaintenanceLease struct {
|
|
Name string
|
|
Release func()
|
|
}
|
|
|
|
type windowsUpdateHandoff struct {
|
|
Name string
|
|
Wait func() error
|
|
Close func()
|
|
}
|
|
|
|
func WindowsUpdateMaintenanceActive(goos string, executablePath string) (bool, error) {
|
|
if !strings.EqualFold(strings.TrimSpace(goos), "windows") {
|
|
return false, nil
|
|
}
|
|
name, err := resolveWindowsUpdateMaintenanceName(executablePath)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return windowsUpdateMaintenanceObjectActive(name)
|
|
}
|
|
|
|
func acquireWindowsUpdateMaintenance(executablePath string) (windowsUpdateMaintenanceLease, error) {
|
|
name, err := resolveWindowsUpdateMaintenanceName(executablePath)
|
|
if err != nil {
|
|
return windowsUpdateMaintenanceLease{}, err
|
|
}
|
|
return acquireWindowsUpdateMaintenanceObject(name)
|
|
}
|
|
|
|
func resolveWindowsUpdateMaintenanceName(executablePath string) (string, error) {
|
|
executablePath = strings.TrimSpace(executablePath)
|
|
if executablePath == "" {
|
|
return "", errors.New("update maintenance executable path is empty")
|
|
}
|
|
absolute, err := filepath.Abs(executablePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if evaluated, evalErr := filepath.EvalSymlinks(absolute); evalErr == nil {
|
|
absolute = evaluated
|
|
}
|
|
installDir := strings.ToLower(filepath.Clean(filepath.Dir(absolute)))
|
|
digest := sha256.Sum256([]byte(installDir))
|
|
return `Global\GoNavi-Update-` + hex.EncodeToString(digest[:16]), nil
|
|
}
|