1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-10 01:40:43 +00:00

Add OSX support for path fixups. (#251)

This commit is contained in:
Tim Sarbin 2019-12-14 00:15:52 -05:00 committed by GitHub
parent a194913609
commit 4eeac5c1d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 10 deletions

View File

@ -20,5 +20,18 @@
"d2sfx.mpq",
"d2video.mpq",
"d2speech.mpq"
]
],
"MpqMacLoadOrder": [
"Diablo II Patch",
"Diablo II Expansion Data",
"Diablo II Expansion Movies",
"Diablo II Expansion Music",
"Diablo II Expansion Speech",
"Diablo II Game Data",
"Diablo II Graphics",
"Diablo II Movies",
"Diablo II Music",
"Diablo II Sounds",
"Diablo II Speech"
]
}

View File

@ -6,6 +6,7 @@ import (
"log"
"os"
"path"
"runtime"
"strings"
"github.com/mitchellh/go-homedir"
@ -22,6 +23,7 @@ type Configuration struct {
VsyncEnabled bool
MpqPath string
MpqLoadOrder []string
MpqMacLoadOrder []string
SfxVolume float64
BgmVolume float64
}
@ -39,17 +41,26 @@ func LoadConfiguration() *Configuration {
if err != nil {
log.Fatal(err)
}
// Path fixup for wine-installed diablo 2 in linux
if config.MpqPath[0] != '/' {
if _, err := os.Stat(config.MpqPath); os.IsNotExist(err) {
homeDir, _ := homedir.Dir()
newPath := strings.ReplaceAll(config.MpqPath, `C:\`, homeDir+"/.wine/drive_c/")
newPath = strings.ReplaceAll(newPath, "C:/", homeDir+"/.wine/drive_c/")
newPath = strings.ReplaceAll(newPath, `\`, "/")
if _, err := os.Stat(newPath); !os.IsNotExist(err) {
config.MpqPath = newPath
if runtime.GOOS == "darwin" {
if config.MpqPath[0] != '/' {
config.MpqPath = "/Applications/Diablo II/"
}
config.MpqLoadOrder = config.MpqMacLoadOrder
} else {
// Path fixup for wine-installed diablo 2 in linux
if config.MpqPath[0] != '/' {
if _, err := os.Stat(config.MpqPath); os.IsNotExist(err) {
homeDir, _ := homedir.Dir()
newPath := strings.ReplaceAll(config.MpqPath, `C:\`, homeDir+"/.wine/drive_c/")
newPath = strings.ReplaceAll(newPath, "C:/", homeDir+"/.wine/drive_c/")
newPath = strings.ReplaceAll(newPath, `\`, "/")
if _, err := os.Stat(newPath); !os.IsNotExist(err) {
config.MpqPath = newPath
}
}
}
}
return &config
}