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