Skip to content

Commit

Permalink
Merge pull request OpenDiablo2#1098 from willroberts/windows-path-sup…
Browse files Browse the repository at this point in the history
…port

Use filepath instead of path for Windows support
  • Loading branch information
essial committed Mar 24, 2021
2 parents 6c00b32 + d1c1e8b commit 236a091
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions d2common/d2fileformats/d2mpq/mpq.go
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -201,5 +200,5 @@ func openIgnoreCase(mpqPath string) (*os.File, error) {
}
}

return os.Open(path.Join(mpqDir, mpqName)) //nolint:gosec // Will fix later
return os.Open(filepath.Join(mpqDir, mpqName)) //nolint:gosec // Will fix later
}
3 changes: 1 addition & 2 deletions d2core/d2config/d2config.go
Expand Up @@ -3,7 +3,6 @@ package d2config
import (
"encoding/json"
"os"
"path"
"path/filepath"
)

Expand All @@ -24,7 +23,7 @@ type Configuration struct {

// Save saves the configuration object to disk
func (c *Configuration) Save() error {
configDir := path.Dir(c.path)
configDir := filepath.Dir(c.path)
if err := os.MkdirAll(configDir, 0750); err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions d2core/d2config/default_directories.go
Expand Up @@ -2,7 +2,7 @@ package d2config

import (
"os"
"path"
"path/filepath"
)

const (
Expand All @@ -13,13 +13,13 @@ const (
// DefaultConfigPath returns the absolute path for the default config file location
func DefaultConfigPath() string {
if configDir, err := os.UserConfigDir(); err == nil {
return path.Join(configDir, od2ConfigDirName, od2ConfigFileName)
return filepath.Join(configDir, od2ConfigDirName, od2ConfigFileName)
}

return LocalConfigPath()
}

// LocalConfigPath returns the absolute path to the directory of the OpenDiablo2 executable
func LocalConfigPath() string {
return path.Join(path.Dir(os.Args[0]), od2ConfigFileName)
return filepath.Join(filepath.Dir(os.Args[0]), od2ConfigFileName)
}
4 changes: 2 additions & 2 deletions d2core/d2config/defaults.go
Expand Up @@ -2,7 +2,7 @@ package d2config

import (
"os/user"
"path"
"path/filepath"
"runtime"
)

Expand Down Expand Up @@ -47,7 +47,7 @@ func DefaultConfig() *Configuration {
config.MpqPath = "/Applications/Diablo II/"
case "linux":
if usr, err := user.Current(); err == nil {
config.MpqPath = path.Join(usr.HomeDir, ".wine/drive_c/Program Files (x86)/Diablo II")
config.MpqPath = filepath.Join(usr.HomeDir, ".wine", "drive_c", "Program Files (x86)", "Diablo II")
}
}

Expand Down
9 changes: 4 additions & 5 deletions d2core/d2hero/hero_state_factory.go
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -82,7 +81,7 @@ func (f *HeroStateFactory) GetAllHeroStates() ([]*HeroState, error) {
continue
}

gameState := f.LoadHeroState(path.Join(basePath, file.Name()))
gameState := f.LoadHeroState(filepath.Join(basePath, file.Name()))
if gameState == nil || gameState.HeroType == d2enum.HeroNone {

} else if gameState.Stats == nil || gameState.Skills == nil {
Expand Down Expand Up @@ -224,15 +223,15 @@ func (f *HeroStateFactory) getGameBaseSavePath() (string, error) {
return "", err
}

return path.Join(configDir, "OpenDiablo2/Saves"), nil
return filepath.Join(configDir, "OpenDiablo2", "Saves"), nil
}

func (f *HeroStateFactory) getFirstFreeFileName() string {
i := 0
basePath, _ := f.getGameBaseSavePath()

for {
filePath := path.Join(basePath, strconv.Itoa(i)+".od2")
filePath := filepath.Join(basePath, strconv.Itoa(i)+".od2")
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return filePath
}
Expand All @@ -246,7 +245,7 @@ func (f *HeroStateFactory) Save(state *HeroState) error {
state.FilePath = f.getFirstFreeFileName()
}

if err := os.MkdirAll(path.Dir(state.FilePath), mkdirPermission); err != nil {
if err := os.MkdirAll(filepath.Dir(state.FilePath), mkdirPermission); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions d2game/d2gamescreen/credits.go
Expand Up @@ -3,7 +3,7 @@ package d2gamescreen
import (
"bufio"
"os"
"path"
"path/filepath"
"strings"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
Expand Down Expand Up @@ -72,7 +72,7 @@ type Credits struct {

// LoadContributors loads the contributors data from file
func (v *Credits) LoadContributors() []string {
file, err := os.Open(path.Join("./", "CONTRIBUTORS"))
file, err := os.Open(filepath.Join(".", "CONTRIBUTORS"))
if err != nil || file == nil {
v.Warning("CONTRIBUTORS file is missing")
return []string{"MISSING CONTRIBUTOR FILES!"}
Expand Down

0 comments on commit 236a091

Please sign in to comment.