mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-12 04:17:25 -05:00
Added useful config error panic. Added window title to panic window. (#879)
This commit is contained in:
parent
f98e1267fa
commit
a9d832b539
@ -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
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ func CreatePanicScreen(errorMessage string) *PanicScreen {
|
||||
errorMessage: errorMessage,
|
||||
}
|
||||
|
||||
ebiten.SetWindowTitle("OpenDiablo 2 - PANIC SCREEN")
|
||||
ebiten.SetWindowResizable(true)
|
||||
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user