修复解压缩zip的错误

This commit is contained in:
2025-10-30 17:58:49 +08:00
parent 607af816c4
commit 49c84b886b
4 changed files with 16 additions and 6 deletions

View File

@@ -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)

View File

@@ -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(), "开发模式,不检查更新")
}

View File

@@ -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
}

View File

@@ -17,7 +17,7 @@ type (
RestartSelf() error
// RenameRunningFile 重命名正在运行的程序文件(如 message.exe → message.exe~
RenameRunningFile(exePath string) (string, error)
CheckUpdate()
CheckUpdate() (err error)
}
)