Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
增加 mobi 配置字段
Browse files Browse the repository at this point in the history
  • Loading branch information
zsakvo committed May 24, 2019
1 parent c4535c8 commit f374500
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
29 changes: 25 additions & 4 deletions getConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strconv"

"github.com/Unknwon/goconfig"
)
Expand All @@ -19,7 +20,7 @@ func getConfig() {
} else {
initSettings()
fmt.Println("已初始化 conf.ini 配置文件,请按提示填写后运行本程序")
os.Exit(1)
os.Exit(0)
}
}

Expand Down Expand Up @@ -69,6 +70,17 @@ func getToken() string {
return tokenMap["token"]
}

func getMobi() {
mobiMap := getSection("mobi")
hintBool, err := strconv.ParseBool(mobiMap["hint"])
if err != nil {
mobi.hint = true
} else {
mobi.hint = hintBool
}
mobi.caliPath = mobiMap["calibre-path"]
}

func initSettings() {
os.Create("conf.ini")
cfg, err := goconfig.LoadConfigFile("conf.ini")
Expand All @@ -83,13 +95,15 @@ func initSettings() {
cfg.SetKeyComments("path", "tmp", "# 临时目录,必填")
cfg.SetValue("path", "out", "output")
cfg.SetKeyComments("path", "out", "# 输出目录,必填")
cfg.SetValue("mobi", "hint", "true")
cfg.SetKeyComments("mobi", "hint", "# 首次提示,只能为 true 或 false")
cfg.SetValue("mobi", "calibre-path", "")
cfg.SetKeyComments("mobi", "calibre-path", "# calibre 路径,请精确到 ebook-convert 可执行文件所在的目录")
err1 := goconfig.SaveConfigFile(cfg, "conf.ini")
check(err1)
}

func initConfig() {
getConfig()
getPathSettings()
func setSeparator() {
if ostype == "windows" {
pathSeparator = "\\"
} else if ostype == "linux" {
Expand All @@ -98,3 +112,10 @@ func initConfig() {
pathSeparator = "/"
}
}

func initConfig() {
getConfig()
getPathSettings()
setSeparator()
getMobi()
}
8 changes: 7 additions & 1 deletion struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const initEncryptKey = "zG2nSeEfSHfvTCHy5LCcqtBbQehKNLXn"
var ostype = runtime.GOOS
var pathSeparator string

// var bar progressbar.ProgressBar
var bar *pb.ProgressBar
var ping int64
var book cbook
Expand All @@ -24,6 +23,13 @@ var path pathSettings
var config *goconfig.ConfigFile
var download cdownload

var mobi cmobi

type cmobi struct {
hint bool
caliPath string
}

type ctoken struct {
readerID string
loginToken string
Expand Down
1 change: 1 addition & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main

0 comments on commit f374500

Please sign in to comment.