diff --git a/main.go b/main.go index 7068cf8f..bba9aa80 100644 --- a/main.go +++ b/main.go @@ -52,11 +52,9 @@ func runLoop(vid *video.Video) { func main() { var GLVersion uint - var fullscreen bool flag.StringVar(&state.Global.CorePath, "L", "", "Path to the libretro core") flag.BoolVar(&state.Global.Verbose, "v", false, "Verbose logs") flag.UintVar(&GLVersion, "glver", 32, "OpenGL version") - flag.BoolVar(&fullscreen, "fullscreen", false, "Force starting in full screen mode") flag.Parse() args := flag.Args() @@ -71,11 +69,6 @@ func main() { log.Println("[Settings]: Using default settings") } - if fullscreen { - settings.Current.VideoFullscreen = fullscreen - settings.Save() - } - if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } diff --git a/settings/settings.go b/settings/settings.go index c2398d1e..2e9e60f4 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -45,12 +45,17 @@ var Defaults = defaultSettings() // If the settings file doesn't exists, it will return an error and // set all the settings to their default value. func Load() error { + defer Save() + + usr, _ := user.Current() + // Set default values for settings Current = Defaults - usr, err := user.Current() - if err != nil { - return err + // If /etc/ludo.json exists, override the defaults + if _, err := os.Stat("/etc/ludo.json"); !os.IsNotExist(err) { + b, _ := ioutil.ReadFile("/etc/ludo.json") + json.Unmarshal(b, &Current) } b, err := ioutil.ReadFile(usr.HomeDir + "/.ludo/settings.json") @@ -59,8 +64,6 @@ func Load() error { } err = json.Unmarshal(b, &Current) - Save() - return err } @@ -68,6 +71,8 @@ func Load() error { func Save() error { usr, _ := user.Current() + os.MkdirAll(usr.HomeDir+"/.ludo", os.ModePerm) + b, _ := json.MarshalIndent(Current, "", " ") f, err := os.Create(usr.HomeDir + "/.ludo/settings.json") if err != nil {