mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-12 12:26:31 -05:00
Automatically use wine prefix base path with default config on linux
This commit is contained in:
parent
9fc416e8e2
commit
dd403cb0eb
@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -19,6 +20,7 @@ import (
|
||||
"github.com/essial/OpenDiablo2/UI"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
// EngineConfig defines the configuration for the engine, loaded from config.json
|
||||
@ -36,7 +38,7 @@ type EngineConfig struct {
|
||||
|
||||
// Engine is the core OpenDiablo2 engine
|
||||
type Engine struct {
|
||||
Settings EngineConfig // Engine configuration settings from json file
|
||||
Settings *EngineConfig // Engine configuration settings from json file
|
||||
Files map[string]string // Map that defines which files are in which MPQs
|
||||
Palettes map[Palettes.Palette]Common.Palette // Color palettes
|
||||
SoundEntries map[string]Sound.SoundEntry // Sound configurations
|
||||
@ -74,7 +76,7 @@ func CreateEngine() *Engine {
|
||||
}
|
||||
|
||||
func (v *Engine) loadConfigurationFile() {
|
||||
log.Println("loading configuration file")
|
||||
log.Println("Loading configuration file")
|
||||
configJSON, err := ioutil.ReadFile("config.json")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -85,7 +87,20 @@ func (v *Engine) loadConfigurationFile() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
v.Settings = config
|
||||
v.Settings = &config
|
||||
// Path fixup for wine-installed diablo 2 in linux
|
||||
if v.Settings.MpqPath[0] != '/' {
|
||||
if _, err := os.Stat(v.Settings.MpqPath); os.IsNotExist(err) {
|
||||
homeDir, _ := homedir.Dir()
|
||||
newPath := strings.ReplaceAll(v.Settings.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) {
|
||||
log.Printf("Detected linux wine installation, path updated to wine prefix path.")
|
||||
v.Settings.MpqPath = newPath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Engine) mapMpqFiles() {
|
||||
|
1
go.mod
1
go.mod
@ -5,4 +5,5 @@ go 1.13
|
||||
require (
|
||||
github.com/JoshVarga/blast v0.0.0-20180421040937-681c804fb9f0
|
||||
github.com/hajimehoshi/ebiten v1.9.3
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -24,6 +24,8 @@ github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2Q
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd h1:nLIcFw7GiqKXUS7HiChg6OAYWgASB2H97dZKd1GhDSs=
|
||||
golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
|
Loading…
Reference in New Issue
Block a user