From fd18343b84e6241087395e8cc87b8cc7b4c2bdc3 Mon Sep 17 00:00:00 2001 From: Evan Burkey Date: Sun, 13 Apr 2025 13:39:56 -0700 Subject: [PATCH] bugfix --- .gitignore | 3 ++- Makefile | 10 ++++++++++ main.go | 29 +++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 34fcb54..8663634 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ WoWChatLog.txt .idea config.toml -*.csv \ No newline at end of file +*.csv +gamboupload \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2740390 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: build + +build: + go build + +install: build + cp gamboupload /home/evan/.local/bin/gamboupload + +clean: + rm gamboupload diff --git a/main.go b/main.go index 135e9b0..a509dbd 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,8 @@ import ( "github.com/sqweek/dialog" "log" "os" + "path/filepath" + "runtime" ) type Config struct { @@ -17,23 +19,38 @@ type Config struct { var config Config +func getConfigPath() string { + if runtime.GOOS == "windows" { + return "config.toml" + } + + xdg := os.Getenv("XDG_CONFIG_HOME") + if xdg == "" { + log.Fatal("$XDG_CONFIG_HOME not set") + } + + os.MkdirAll(filepath.Join(xdg, "gambosite"), 0755) + return filepath.Join(xdg, "gambosite", "config.toml") +} + func setupConfig() { - if _, statErr := os.Stat("config.toml"); os.IsNotExist(statErr) { - path, err := dialog.File().Title("Select your WoWChatLog.txt").Load() + cfgPath := getConfigPath() + + if _, statErr := os.Stat(cfgPath); os.IsNotExist(statErr) { + chatlogPath, err := dialog.File().Title("Select your WoWChatLog.txt").Load() if err != nil { if errors.Is(err, dialog.ErrCancelled) { log.Fatalf("Cancelled dialog box, exiting") } - } else { log.Fatal(err) } newConfig := &Config{ - Log: path, + Log: chatlogPath, Apikey: "12345", } - file, err := os.Create("config.toml") + file, err := os.Create(cfgPath) if err != nil { log.Fatal(err) } @@ -45,7 +62,7 @@ func setupConfig() { } } - _, err := toml.DecodeFile("config.toml", &config) + _, err := toml.DecodeFile(cfgPath, &config) if err != nil { log.Fatal(err) }