mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-31 18:59:44 +08:00
- 根据当前安装标记精确选择 MSI 或 Portable 更新包 - MSI 更新下载到用户缓存并通过 msiexec 保留原目录安装重启 - 下载与安装前校验包类型并隔离不同安装方式的缓存 - 补充安装模式、脚本执行和更新清理测试
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
_ "embed"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
//go:embed windows_msi_update.ps1
|
|
var windowsMSIUpdatePowerShellScript string
|
|
|
|
type windowsMSIUpdateLaunchContext struct {
|
|
SourcePath string
|
|
TargetPath string
|
|
StagedDir string
|
|
LogPath string
|
|
MSILogPath string
|
|
MSIExecPath string
|
|
PID int
|
|
}
|
|
|
|
func buildWindowsMSIUpdatePowerShellScript() string {
|
|
normalized := strings.ReplaceAll(windowsMSIUpdatePowerShellScript, "\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_PID="+strconv.Itoa(context.PID),
|
|
)
|
|
configureWindowsUpdateCommand(cmd)
|
|
return cmd
|
|
}
|