mirror of
https://github.com/ayflying/p2p.git
synced 2026-03-04 17:29:22 +00:00
更新不同系统的解压方式,区分zip与gzip
This commit is contained in:
@@ -456,7 +456,7 @@ func (s *sP2P) receiveGatewayMessages(ctx context.Context) {
|
||||
|
||||
g.Log().Info(ctx, "文件接收完成")
|
||||
// 开始覆盖文件与重启
|
||||
err = service.System().Update(ctx)
|
||||
err = service.System().Update(ctx, "")
|
||||
|
||||
//// 调用不同系统的更新服务
|
||||
//service.OS().Update(msgData.Version, msgData.Server)
|
||||
|
||||
@@ -48,15 +48,23 @@ type GitHubRelease struct {
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
func (s *sSystem) Update(ctx context.Context) (err error) {
|
||||
func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) {
|
||||
//拼接操作系统和架构(格式:OS_ARCH)
|
||||
platform := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
runFile := gcmd.GetArg(0).String()
|
||||
oldFile, err := service.System().RenameRunningFile(runFile)
|
||||
g.Log().Debugf(ctx, "执行文件改名为%v", oldFile)
|
||||
gz := path.Join("download", platform+".gz")
|
||||
err = gcompress.UnGzipFile(gz, runFile)
|
||||
if gzFile == "" {
|
||||
gzFile = path.Join("download", platform+".gz")
|
||||
}
|
||||
|
||||
ext := gfile.Ext(gzFile)
|
||||
if ext == "zip" {
|
||||
err = gcompress.UnZipFile(gzFile, runFile)
|
||||
} else {
|
||||
err = gcompress.UnGzipFile(gzFile, runFile)
|
||||
}
|
||||
|
||||
go func() {
|
||||
log.Println("5秒后开始重启...")
|
||||
@@ -186,13 +194,18 @@ func (s *sSystem) CheckUpdate() {
|
||||
if strings.Contains(fmt.Sprintf("_%s.", asset.Name), platform) {
|
||||
fmt.Printf("- %s\n", asset.BrowserDownloadUrl)
|
||||
|
||||
// 下载更新文件
|
||||
fileDownload, err2 := g.Client().Get(ctx, asset.BrowserDownloadUrl)
|
||||
if err2 != nil {
|
||||
return
|
||||
}
|
||||
//filename := gfile.Name()
|
||||
err = gfile.PutBytes(path.Join("download", asset.Name), fileDownload.ReadAll())
|
||||
updateFile := path.Join("download", asset.Name)
|
||||
err = gfile.PutBytes(updateFile, fileDownload.ReadAll())
|
||||
|
||||
err = s.Update(ctx, updateFile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// 保存最新版本号到文件
|
||||
gfile.PutContents("download/version.txt", latestVersion)
|
||||
break
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
type (
|
||||
ISystem interface {
|
||||
Init()
|
||||
Update(ctx context.Context) (err error)
|
||||
Update(ctx context.Context, gzFile string) (err error)
|
||||
// RestartSelf 实现 Windows 平台下的程序自重启
|
||||
RestartSelf() error
|
||||
// RenameRunningFile 重命名正在运行的程序文件(如 message.exe → message.exe~)
|
||||
|
||||
Reference in New Issue
Block a user