Skip to content

Commit

Permalink
update read config
Browse files Browse the repository at this point in the history
  • Loading branch information
dvgamerr committed Oct 31, 2022
1 parent 9dd5c55 commit e0dccb2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# DEBUG=debug
DEBUG=debug
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ $RECYCLE.BIN/

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

config.yaml
hoyolab.yaml
47 changes: 42 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,54 @@ import (
"os"
"path"
"path/filepath"
"strings"

"github.com/go-resty/resty/v2"
"github.com/zellyn/kooky"
"github.com/zellyn/kooky/browser/chrome"
"gopkg.in/yaml.v2"
)

var configFile string = "config.yaml"
var configExt string = "yaml"
var logExt string = "log"
var configPath string = ""
var logPath string = ""
var logfile *os.File

func init() {
log.SetFlags(log.Ltime | log.Lshortfile)
filename, err := os.Executable()
if err != nil {
log.Fatal(err)
}
filename = strings.ReplaceAll(filepath.Base(filename), filepath.Ext(filename), "")

configPath = fmt.Sprintf("%s.%s", filename, configExt)
logPath = fmt.Sprintf("%s.%s", filename, logExt)

configPath = configFile
dirname, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}

if _, err := os.Stat(path.Join(dirname, configFile)); err == nil {
configPath = path.Join(dirname, configFile)
if _, err := os.Stat(path.Join(dirname, configExt)); err == nil {
configPath = path.Join(dirname, configPath)
logPath = path.Join(dirname, logPath)
}
if !IsDebug {
log.SetFlags(log.Ldate | log.Ltime)
f, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
log.SetOutput(f)
}
}

func main() {
if logfile != nil {
defer logfile.Close()
}

installSchedule := *flag.Bool("install", false, "# install to ")
flag.Parse()

Expand Down Expand Up @@ -75,6 +98,20 @@ func main() {
if err != nil {
log.Panic("WriteFile fail")
}
} else {
raw, err := os.ReadFile(configPath)
if err != nil {
log.Panic("ReadFile fail")
}

var configFile map[string]*DailyHoyolab

err = yaml.Unmarshal(raw, &configFile)
if err != nil {
log.Panic("yaml Marshal fail")
}

hoyo.Daily = configFile["config"]
}

for _, store := range kooky.FindAllCookieStores() {
Expand Down

0 comments on commit e0dccb2

Please sign in to comment.