From 222b916002ca9e07fcc54cc718269d3a424b3165 Mon Sep 17 00:00:00 2001 From: Will Roberts Date: Tue, 23 Mar 2021 23:08:32 -0400 Subject: [PATCH 1/3] Use filepath instead of path for Windows support --- d2core/d2config/d2config.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/d2core/d2config/d2config.go b/d2core/d2config/d2config.go index de17fc27..de142964 100644 --- a/d2core/d2config/d2config.go +++ b/d2core/d2config/d2config.go @@ -3,7 +3,6 @@ package d2config import ( "encoding/json" "os" - "path" "path/filepath" ) @@ -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 } From b18a70cef90485686dc9c3a5505e0be9e2defd26 Mon Sep 17 00:00:00 2001 From: Will Roberts Date: Tue, 23 Mar 2021 23:18:19 -0400 Subject: [PATCH 2/3] Updates more instances of path->filepath --- d2common/d2fileformats/d2mpq/mpq.go | 3 +-- d2core/d2config/default_directories.go | 6 +++--- d2core/d2config/defaults.go | 4 ++-- d2core/d2hero/hero_state_factory.go | 9 ++++----- d2game/d2gamescreen/credits.go | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/d2common/d2fileformats/d2mpq/mpq.go b/d2common/d2fileformats/d2mpq/mpq.go index 59f3a8b1..2e191b4f 100644 --- a/d2common/d2fileformats/d2mpq/mpq.go +++ b/d2common/d2fileformats/d2mpq/mpq.go @@ -6,7 +6,6 @@ import ( "fmt" "io/ioutil" "os" - "path" "path/filepath" "runtime" "strings" @@ -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 } diff --git a/d2core/d2config/default_directories.go b/d2core/d2config/default_directories.go index 0c09859a..1dd158ae 100644 --- a/d2core/d2config/default_directories.go +++ b/d2core/d2config/default_directories.go @@ -2,7 +2,7 @@ package d2config import ( "os" - "path" + "path/filepath" ) const ( @@ -16,7 +16,7 @@ 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() @@ -24,5 +24,5 @@ func DefaultConfigPath() string { // 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) } diff --git a/d2core/d2config/defaults.go b/d2core/d2config/defaults.go index 7e8a539b..cc9ad911 100644 --- a/d2core/d2config/defaults.go +++ b/d2core/d2config/defaults.go @@ -2,7 +2,7 @@ package d2config import ( "os/user" - "path" + "path/filepath" "runtime" ) @@ -60,7 +60,7 @@ func DefaultConfig() *Configuration { } 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") } } diff --git a/d2core/d2hero/hero_state_factory.go b/d2core/d2hero/hero_state_factory.go index 10ad1bd2..2bf5446a 100644 --- a/d2core/d2hero/hero_state_factory.go +++ b/d2core/d2hero/hero_state_factory.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "os" - "path" "path/filepath" "strconv" "strings" @@ -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 { @@ -224,7 +223,7 @@ 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 { @@ -232,7 +231,7 @@ func (f *HeroStateFactory) getFirstFreeFileName() string { 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 } @@ -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 } diff --git a/d2game/d2gamescreen/credits.go b/d2game/d2gamescreen/credits.go index d94b4720..5a881912 100644 --- a/d2game/d2gamescreen/credits.go +++ b/d2game/d2gamescreen/credits.go @@ -3,7 +3,7 @@ package d2gamescreen import ( "bufio" "os" - "path" + "path/filepath" "strings" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" @@ -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!"} From d1c1e8bd263b846270070c69f2bb391d53a61ba2 Mon Sep 17 00:00:00 2001 From: Will Roberts Date: Tue, 23 Mar 2021 23:30:00 -0400 Subject: [PATCH 3/3] No forward slashes in filepath.Join to satisfy golangci-lint --- d2core/d2config/defaults.go | 2 +- d2core/d2hero/hero_state_factory.go | 2 +- d2game/d2gamescreen/credits.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/d2core/d2config/defaults.go b/d2core/d2config/defaults.go index cc9ad911..ce6fa305 100644 --- a/d2core/d2config/defaults.go +++ b/d2core/d2config/defaults.go @@ -60,7 +60,7 @@ func DefaultConfig() *Configuration { } case "linux": if usr, err := user.Current(); err == nil { - config.MpqPath = filepath.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") } } diff --git a/d2core/d2hero/hero_state_factory.go b/d2core/d2hero/hero_state_factory.go index 2bf5446a..97708b95 100644 --- a/d2core/d2hero/hero_state_factory.go +++ b/d2core/d2hero/hero_state_factory.go @@ -223,7 +223,7 @@ func (f *HeroStateFactory) getGameBaseSavePath() (string, error) { return "", err } - return filepath.Join(configDir, "OpenDiablo2/Saves"), nil + return filepath.Join(configDir, "OpenDiablo2", "Saves"), nil } func (f *HeroStateFactory) getFirstFreeFileName() string { diff --git a/d2game/d2gamescreen/credits.go b/d2game/d2gamescreen/credits.go index 5a881912..85c96095 100644 --- a/d2game/d2gamescreen/credits.go +++ b/d2game/d2gamescreen/credits.go @@ -72,7 +72,7 @@ type Credits struct { // LoadContributors loads the contributors data from file func (v *Credits) LoadContributors() []string { - file, err := os.Open(filepath.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!"}