1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-29 10:35:23 +00:00

Added useful config error panic. Added window title to panic window. (#879)

This commit is contained in:
Tim Sarbin 2020-10-28 21:42:03 -04:00 committed by GitHub
parent f98e1267fa
commit a9d832b539
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

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

View File

@ -17,6 +17,7 @@ func CreatePanicScreen(errorMessage string) *PanicScreen {
errorMessage: errorMessage,
}
ebiten.SetWindowTitle("OpenDiablo 2 - PANIC SCREEN")
ebiten.SetWindowResizable(true)
return result