From 49c84b886bcb41e2e0f0768e1be5f38961659d9c Mon Sep 17 00:00:00 2001 From: ayflying Date: Thu, 30 Oct 2025 17:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=A3=E5=8E=8B=E7=BC=A9zi?= =?UTF-8?q?p=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/p2p/p2p.go | 3 ++- internal/logic/system/system.go | 5 ++++- internal/logic/system/update.go | 12 +++++++++--- internal/service/system.go | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/logic/p2p/p2p.go b/internal/logic/p2p/p2p.go index fd48711..200394f 100644 --- a/internal/logic/p2p/p2p.go +++ b/internal/logic/p2p/p2p.go @@ -188,9 +188,10 @@ func (s *sP2P) removeDuplicates(strs []string) []string { return result } +const privKeyPath = "runtime/p2p.key" + // 生成固定密钥(核心:通过固定种子生成相同密钥) func (s *sP2P) generateFixedKey() (crypto.PrivKey, error) { - privKeyPath := "runtime/message.key" if ok := gfile.Exists(privKeyPath); ok { // 从文件读取密钥 keyBytes := gfile.GetBytes(privKeyPath) diff --git a/internal/logic/system/system.go b/internal/logic/system/system.go index 7dbdf95..5ca3fb8 100644 --- a/internal/logic/system/system.go +++ b/internal/logic/system/system.go @@ -17,7 +17,10 @@ func init() { getDev, _ := g.Cfg().GetWithEnv(gctx.New(), "dev") if !getDev.Bool() { - service.System().CheckUpdate() + err := service.System().CheckUpdate() + if err != nil { + g.Log().Errorf(gctx.New(), "检查更新失败:%v", err) + } } else { g.Log().Debugf(gctx.New(), "开发模式,不检查更新") } diff --git a/internal/logic/system/update.go b/internal/logic/system/update.go index 95d8db8..8b0bfde 100644 --- a/internal/logic/system/update.go +++ b/internal/logic/system/update.go @@ -60,11 +60,16 @@ func (s *sSystem) Update(ctx context.Context, gzFile string) (err error) { } ext := gfile.Ext(gzFile) - if ext == "zip" { - err = gcompress.UnZipFile(gzFile, runFile) + if ext == ".zip" { + g.Log().Debugf(ctx, "zip解压%v到%v", gzFile, gfile.Dir(runFile)) + err = gcompress.UnZipFile(gzFile, gfile.Dir(runFile)) } else { + g.Log().Debugf(ctx, "gzip解压%v到%v", gzFile, runFile) err = gcompress.UnGzipFile(gzFile, runFile) } + if err != nil { + return + } go func() { log.Println("5秒后开始重启...") @@ -174,7 +179,7 @@ func (s *sSystem) getLatestVersion() (string, []*Assets, error) { return release.TagName, release.Assets, nil } -func (s *sSystem) CheckUpdate() { +func (s *sSystem) CheckUpdate() (err error) { ctx := gctx.New() latestVersion, assets, err := s.getLatestVersion() if err != nil { @@ -214,4 +219,5 @@ func (s *sSystem) CheckUpdate() { } else { fmt.Printf("当前已是最新版本:%s\n", localVersion) } + return } diff --git a/internal/service/system.go b/internal/service/system.go index 9a2cea4..87c7c15 100644 --- a/internal/service/system.go +++ b/internal/service/system.go @@ -17,7 +17,7 @@ type ( RestartSelf() error // RenameRunningFile 重命名正在运行的程序文件(如 message.exe → message.exe~) RenameRunningFile(exePath string) (string, error) - CheckUpdate() + CheckUpdate() (err error) } )