Skip to content

Commit

Permalink
Merge branch 'main' of github.com:qjfoidnh/BaiduPCS-Go into main
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Jan 21, 2021
2 parents c1de2ff + 2b247d2 commit 493597d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co
* [4. 网盘内列出文件和目录](#4-网盘内列出文件和目录)
* [5. 下载文件](#5-下载文件)
* [6. 设置下载最大并发量](#6-设置下载最大并发量)
* [7. 退出程序](#7-退出程序)
* [7. 恢复默认配置](#7-恢复默认配置)
* [8. 退出程序](#8-退出程序)
- [已知问题](#已知问题)
- [TODO](#todo)
- [交流反馈](#交流反馈)
Expand Down Expand Up @@ -987,7 +988,11 @@ cli交互模式下, 运行命令 `config set -max_parallel 2` 将下载最大并

注意:下载最大并发量的值不宜设置过高, 可能会导致百度帐号被限制下载

## 7. 退出程序
## 7. 恢复默认配置

cli交互模式下, 运行命令 `config reset`

## 8. 退出程序

运行命令 `quit``exit` 或 组合键 `Ctrl+C` 或 组合键 `Ctrl+D`

Expand Down
4 changes: 2 additions & 2 deletions internal/pcsconfig/pcsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *PCSConfig) init() error {
return ErrConfigFileNotExist
}

c.initDefaultConfig()
c.InitDefaultConfig()
err := c.loadConfigFromFile()
if err != nil {
return err
Expand Down Expand Up @@ -219,7 +219,7 @@ func (c *PCSConfig) loadConfigFromFile() (err error) {
return nil
}

func (c *PCSConfig) initDefaultConfig() {
func (c *PCSConfig) InitDefaultConfig() {
c.AppID = 266719
c.CacheSize = 65536
c.MaxParallel = 1
Expand Down
16 changes: 15 additions & 1 deletion internal/pcsupdate/pcsupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CheckUpdate(version string, yes bool) {
}

// 没有更新, 或忽略 Beta 版本, 和版本前缀不符的
if strings.Contains(releaseInfo.TagName, "Beta") || !strings.HasPrefix(releaseInfo.TagName, "v") || version >= releaseInfo.TagName {
if strings.Contains(releaseInfo.TagName, "Beta") || !strings.HasPrefix(releaseInfo.TagName, "v") || needUpdate(version, releaseInfo.TagName) {
fmt.Printf("未检测到更新!\n")
return
}
Expand Down Expand Up @@ -255,3 +255,17 @@ func CheckUpdate(version string, yes bool) {

fmt.Printf("更新完毕, 请重启程序\n")
}

func needUpdate(current, latest string) bool {
// 去除第一个字符'v'
v1 := strings.Split(current[1:], ".")
v2 := strings.Split(latest[1:], ".")
for i := range v1 {
a, _ := strconv.Atoi(v1[i])
b, _ := strconv.Atoi(v2[i])
if a < b {
return true
}
}
return false
}
23 changes: 20 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strings"
"unicode"

"github.com/olekukonko/tablewriter"
"github.com/peterh/liner"
"github.com/qjfoidnh/BaiduPCS-Go/baidupcs"
"github.com/qjfoidnh/BaiduPCS-Go/internal/pcscommand"
"github.com/qjfoidnh/BaiduPCS-Go/internal/pcsconfig"
Expand All @@ -29,8 +31,6 @@ import (
"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/getip"
"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/pcstime"
"github.com/qjfoidnh/BaiduPCS-Go/pcsverbose"
"github.com/olekukonko/tablewriter"
"github.com/peterh/liner"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -1375,7 +1375,7 @@ func main() {

strLength, strMd5, strSliceMd5, strCrc32 := strconv.FormatInt(lp.Length, 10), hex.EncodeToString(lp.MD5), hex.EncodeToString(lp.SliceMD5), strconv.FormatUint(uint64(lp.CRC32), 10)
fileName := filepath.Base(filePath)
regFileName := strings.Replace(fileName, " ", "_", -1 )
regFileName := strings.Replace(fileName, " ", "_", -1)
regFileName = strings.Replace(regFileName, "#", "_", -1)
tb := pcstable.NewTable(os.Stdout)
tb.SetColumnAlignment([]int{tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT})
Expand Down Expand Up @@ -1978,6 +1978,23 @@ func main() {
},
},
},
{
Name: "reset",
Usage: "恢复默认配置项",
UsageText: app.Name + " config reset",
Description: "",
Action: func(c *cli.Context) error {
pcsconfig.Config.InitDefaultConfig()
err := pcsconfig.Config.Save()
if err != nil {
fmt.Println(err)
return err
}
pcsconfig.Config.PrintTable()
fmt.Println("恢复默认配置成功")
return nil
},
},
},
},
{
Expand Down

0 comments on commit 493597d

Please sign in to comment.