mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-07-01 11:25:26 +00: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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config holds the configuration from config.json
|
// Config holds the configuration from config.json
|
||||||
|
@ -58,6 +60,10 @@ func (c *Configuration) Load() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := verifyMpqFileReferences(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +71,10 @@ func (c *Configuration) Load() error {
|
||||||
|
|
||||||
Config = defaultConfig()
|
Config = defaultConfig()
|
||||||
|
|
||||||
|
if err := verifyMpqFileReferences(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return Config.Save()
|
return Config.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,3 +116,29 @@ func defaultConfigPath() string {
|
||||||
func localConfigPath() string {
|
func localConfigPath() string {
|
||||||
return path.Join(path.Dir(os.Args[0]), "config.json")
|
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,
|
errorMessage: errorMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ebiten.SetWindowTitle("OpenDiablo 2 - PANIC SCREEN")
|
||||||
ebiten.SetWindowResizable(true)
|
ebiten.SetWindowResizable(true)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in New Issue
Block a user