diff --git a/config.go b/config.go new file mode 100644 index 0000000..a42ddc7 --- /dev/null +++ b/config.go @@ -0,0 +1,58 @@ +package main + +import ( + "log" + "os" + + "github.com/bigkevmcd/go-configparser" +) + +var ( + Config *configparser.ConfigParser + ConfigFile string = "BeadImager.conf" +) + +func ReadConfig() { + log.Printf("Reading config file: %s\n", ConfigFile) + Config, _ = configparser.Parse(UserPath + Sep + ConfigFile) + ConfigBrand, _ = Config.Get("pallette", "brand") + ConfigSerie, _ = Config.Get("pallette", "serie") + ConfigPegboard, _ = Config.Get("pallette", "pegboard") + ConfigScale, _ = Config.Get("canvas", "scale") + ConfigShowGrid, _ = Config.Get("canvas", "showgrid") + ConfogGridColor, _ = Config.Get("canvas", "gridcolor") + ConfigShowBeads, _ = Config.Get("canvas", "showbeads") + ConfigBackgroundColor, _ = Config.Get("canvas", "backgroundcolor") +} + +func CheckConfigFile() bool { + log.Printf("Checking for config file: %s\n", ConfigFile) + if _, err := os.Stat(UserPath + Sep + ConfigFile); os.IsNotExist(err) { + return false + } + return true +} + +func CreateDefaultConfig() { + log.Printf("Creating default config file: %s\n", ConfigFile) + os.Create(UserPath + Sep + ConfigFile) + Config = configparser.New() + Config.AddSection("pallette") + Config.Set("pallette", "brand", "Hama") + Config.Set("pallette", "serie", "Midi") + Config.Set("pallette", "pegboard", "Large 29x29") + Config.AddSection("canvas") + Config.Set("canvas", "scale", "100") + Config.Set("canvas", "showgrid", "true") + Config.Set("canvas", "gridcolor", "#00ff00") + Config.Set("canvas", "showbeads", "false") + Config.Set("canvas", "backgroundcolor", "#ffffff") + Config.SaveWithDelimiter(UserPath+Sep+ConfigFile, "=") +} + +func SetConfigScale(s string) { + log.Printf("Setting scale to: %s\n", s) + Config, _ := configparser.Parse(UserPath + Sep + ConfigFile) + Config.Set("canvas", "scale", s) + Config.SaveWithDelimiter(UserPath+Sep+ConfigFile, "=") +} diff --git a/go.mod b/go.mod index a983e0c..4c38a1e 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require github.com/lxn/walk v0.0.0-20210112085537-c389da54e794 require ( github.com/akavel/rsrc v0.10.2 // indirect + github.com/bigkevmcd/go-configparser v0.0.0-20221013105652-718c0b41a604 // indirect github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect golang.org/x/sys v0.3.0 // indirect gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect diff --git a/go.sum b/go.sum index fbaab0b..09f9442 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw= github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= +github.com/bigkevmcd/go-configparser v0.0.0-20221013105652-718c0b41a604 h1:AOnJt6zGZgcaCc3Yi2WGjrTyjYAfoRzWN6QP8vPoDj4= +github.com/bigkevmcd/go-configparser v0.0.0-20221013105652-718c0b41a604/go.mod h1:zqqfbfnDeSdRs1WihmMjSbhb2Ptw8Jbus831xoqiIec= github.com/lxn/walk v0.0.0-20210112085537-c389da54e794 h1:NVRJ0Uy0SOFcXSKLsS65OmI1sgCCfiDUPj+cwnH7GZw= github.com/lxn/walk v0.0.0-20210112085537-c389da54e794/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ= github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc= diff --git a/main.go b/main.go index 3bf442b..50897f5 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ type MyMainWindow struct { const ( AppName string = "BeadImager" - Version string = "0.0.26" + Version string = "0.0.27" CopyRight string = "©2022 Jan Lerking" STD_MESS string = "Ready" LogFile string = "BeadImager.log" @@ -36,7 +36,15 @@ const ( ) var ( - UserPath string + UserPath string + ConfigBrand string + ConfigSerie string + ConfigPegboard string + ConfigScale string + ConfigShowGrid string + ConfogGridColor string + ConfigShowBeads string + ConfigBackgroundColor string ) func main() { @@ -48,6 +56,16 @@ func main() { homeDir := currentUser.HomeDir UserPath = homeDir + Sep + "BeadImager" InitLogFile() + if !CheckConfigFile() { + CreateDefaultConfig() + ReadConfig() + log.Println("Config file created") + } else { + ReadConfig() + log.Println("Brand: ", ConfigBrand) + log.Println("Serie: ", ConfigSerie) + log.Println("Pegboard: ", ConfigPegboard) + } walk.AppendToWalkInit(func() { walk.FocusEffect, _ = walk.NewBorderGlowEffect(walk.RGB(0, 63, 255)) @@ -84,6 +102,7 @@ func main() { mw.serie_model = CreateSeriesList(mw) mw.serie_combo.SetModel(mw.serie_model) mw.serie_combo.SetEnabled(true) + mw.brand_combo.SetText(ConfigBrand) } brand_trigged = true }, diff --git a/pallettes/pallette.xml b/pallettes/pallette.xml index 1c9b939..1abc7e4 100644 --- a/pallettes/pallette.xml +++ b/pallettes/pallette.xml @@ -15,7 +15,7 @@ 60 - Big 29x29 + Large 29x29 29 29