This commit is contained in:
Evan Burkey 2025-04-13 13:39:56 -07:00
parent b3014466ac
commit fd18343b84
3 changed files with 35 additions and 7 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
WoWChatLog.txt
.idea
config.toml
*.csv
*.csv
gamboupload

10
Makefile Normal file
View File

@ -0,0 +1,10 @@
all: build
build:
go build
install: build
cp gamboupload /home/evan/.local/bin/gamboupload
clean:
rm gamboupload

29
main.go
View File

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