From a9d832b53940401cf3d5bffd07a55fbe22d5cd3b Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Wed, 28 Oct 2020 21:42:03 -0400 Subject: [PATCH] Added useful config error panic. Added window title to panic window. (#879) --- d2core/d2config/d2config.go | 36 +++++++++++++++++++ d2core/d2render/ebiten/ebiten_panic_screen.go | 1 + 2 files changed, 37 insertions(+) diff --git a/d2core/d2config/d2config.go b/d2core/d2config/d2config.go index 8e78e2c2..67f2ad37 100644 --- a/d2core/d2config/d2config.go +++ b/d2core/d2config/d2config.go @@ -2,9 +2,11 @@ package d2config import ( "encoding/json" + "errors" "log" "os" "path" + "strings" ) // Config holds the configuration from config.json @@ -58,6 +60,10 @@ func (c *Configuration) Load() error { return err } + if err := verifyMpqFileReferences(); err != nil { + return err + } + return nil } @@ -65,6 +71,10 @@ func (c *Configuration) Load() error { Config = defaultConfig() + if err := verifyMpqFileReferences(); err != nil { + return err + } + return Config.Save() } @@ -106,3 +116,29 @@ func defaultConfigPath() string { func localConfigPath() string { return path.Join(path.Dir(os.Args[0]), "config.json") } + +func verifyMpqFileReferences() error { + badFiles := []string{} + + for fileIdx := range Config.MpqLoadOrder { + actualPath := path.Join(Config.MpqPath, Config.MpqLoadOrder[fileIdx]) + info, err := os.Stat(actualPath) + + if !os.IsNotExist(err) { + continue + } + + if info != nil && !info.IsDir() { + continue + } + + badFiles = append(badFiles, actualPath) + } + + if len(badFiles) > 0 { + return errors.New("The following MPQ file(s) could not be found:\n" + strings.Join(badFiles, "\n") + + "\n\nPlease check your configuration file located at:\n" + defaultConfigPath()) + } + + return nil +} diff --git a/d2core/d2render/ebiten/ebiten_panic_screen.go b/d2core/d2render/ebiten/ebiten_panic_screen.go index 079b490e..467690ce 100644 --- a/d2core/d2render/ebiten/ebiten_panic_screen.go +++ b/d2core/d2render/ebiten/ebiten_panic_screen.go @@ -17,6 +17,7 @@ func CreatePanicScreen(errorMessage string) *PanicScreen { errorMessage: errorMessage, } + ebiten.SetWindowTitle("OpenDiablo 2 - PANIC SCREEN") ebiten.SetWindowResizable(true) return result