2024-10-27 16:21:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2024-10-30 18:22:03 +00:00
|
|
|
"github.com/adhocore/jsonc"
|
2024-10-27 16:21:28 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
ImageFilters
|
2024-10-30 18:22:03 +00:00
|
|
|
ImagesDir string
|
|
|
|
Duration int
|
|
|
|
Cache string
|
2024-10-27 16:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (config *Config) load() {
|
2024-10-30 20:36:10 +00:00
|
|
|
homeDir, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("could not get home directory!", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
configRaw, err := os.ReadFile(homeDir + "/.config/gopaper/config.jsonc")
|
2024-10-27 16:21:28 +00:00
|
|
|
if err != nil {
|
2024-10-30 18:22:03 +00:00
|
|
|
log.Fatal("Couldn't open config file!\n", err)
|
2024-10-27 16:21:28 +00:00
|
|
|
}
|
2024-10-30 18:22:03 +00:00
|
|
|
j := jsonc.New()
|
|
|
|
configRaw = j.Strip(configRaw)
|
2024-10-27 16:21:28 +00:00
|
|
|
err = json.Unmarshal(configRaw, &config)
|
|
|
|
if err != nil {
|
2024-10-30 18:22:03 +00:00
|
|
|
log.Fatal("Couldn't unmarshal config!\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Cache = homeDir + "/" + config.Cache + "/"
|
|
|
|
//TODO: make directories if they don't
|
|
|
|
config.ImagesDir = homeDir + "/" + config.ImagesDir + "/"
|
2024-10-27 16:21:28 +00:00
|
|
|
}
|