Skip to content

Commit

Permalink
path -> filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Jun 5, 2022
1 parent 4e9d5b0 commit ac1dfb6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
23 changes: 11 additions & 12 deletions cli/installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -39,7 +38,7 @@ type Installation struct {
func InitInstallations() (*Installations, error) {
localDir := viper.GetString("local-dir")

installationsFile := path.Join(localDir, viper.GetString("installations-file"))
installationsFile := filepath.Join(localDir, viper.GetString("installations-file"))
_, err := os.Stat(installationsFile)
if err != nil {
if !os.IsNotExist(err) {
Expand Down Expand Up @@ -90,7 +89,7 @@ func (i *Installations) Save() error {
return nil
}

installationsFile := path.Join(viper.GetString("local-dir"), viper.GetString("installations-file"))
installationsFile := filepath.Join(viper.GetString("local-dir"), viper.GetString("installations-file"))

log.Info().Str("path", installationsFile).Msg("saving installations")

Expand Down Expand Up @@ -192,7 +191,7 @@ func (i *Installation) Validate(ctx *GlobalContext) error {

foundExecutable := false

_, err := os.Stat(path.Join(i.Path, "FactoryGame.exe"))
_, err := os.Stat(filepath.Join(i.Path, "FactoryGame.exe"))
if err != nil {
if !os.IsNotExist(err) {
return errors.Wrap(err, "failed reading FactoryGame.exe")
Expand All @@ -201,7 +200,7 @@ func (i *Installation) Validate(ctx *GlobalContext) error {
foundExecutable = true
}

_, err = os.Stat(path.Join(i.Path, "FactoryServer.sh"))
_, err = os.Stat(filepath.Join(i.Path, "FactoryServer.sh"))
if err != nil {
if !os.IsNotExist(err) {
return errors.Wrap(err, "failed reading FactoryServer.sh")
Expand All @@ -210,7 +209,7 @@ func (i *Installation) Validate(ctx *GlobalContext) error {
foundExecutable = true
}

_, err = os.Stat(path.Join(i.Path, "FactoryServer.exe"))
_, err = os.Stat(filepath.Join(i.Path, "FactoryServer.exe"))
if err != nil {
if !os.IsNotExist(err) {
return errors.Wrap(err, "failed reading FactoryServer.exe")
Expand Down Expand Up @@ -244,7 +243,7 @@ func (i *Installation) LockFilePath(ctx *GlobalContext) (string, error) {
lockFileName = lockFileCleaner.ReplaceAllLiteralString(lockFileName, "-")
lockFileName = strings.ToLower(lockFileName) + "-lock.json"

return path.Join(i.Path, platform.LockfilePath, lockFileName), nil
return filepath.Join(i.Path, platform.LockfilePath, lockFileName), nil
}

func (i *Installation) LockFile(ctx *GlobalContext) (*LockFile, error) {
Expand Down Expand Up @@ -317,7 +316,7 @@ func (i *Installation) Install(ctx *GlobalContext, updates chan InstallUpdate) e
return errors.Wrap(err, "could not resolve mods")
}

modsDirectory := path.Join(i.Path, "FactoryGame", "Mods")
modsDirectory := filepath.Join(i.Path, "FactoryGame", "Mods")
if err := os.MkdirAll(modsDirectory, 0777); err != nil {
return errors.Wrap(err, "failed creating Mods directory")
}
Expand All @@ -330,7 +329,7 @@ func (i *Installation) Install(ctx *GlobalContext, updates chan InstallUpdate) e
for _, entry := range dir {
if entry.IsDir() {
if _, ok := lockfile[entry.Name()]; !ok {
if err := os.RemoveAll(path.Join(modsDirectory, entry.Name())); err != nil {
if err := os.RemoveAll(filepath.Join(modsDirectory, entry.Name())); err != nil {
return errors.Wrap(err, "failed to delete mod directory")
}
}
Expand Down Expand Up @@ -385,7 +384,7 @@ func (i *Installation) Install(ctx *GlobalContext, updates chan InstallUpdate) e
downloading = false

log.Info().Str("mod_reference", modReference).Str("version", version.Version).Str("link", version.Link).Msg("extracting mod")
if err := utils.ExtractMod(reader, size, path.Join(modsDirectory, modReference), genericUpdates); err != nil {
if err := utils.ExtractMod(reader, size, filepath.Join(modsDirectory, modReference), genericUpdates); err != nil {
return errors.Wrap(err, "could not extract "+modReference)
}

Expand Down Expand Up @@ -444,7 +443,7 @@ func (i *Installation) GetGameVersion(ctx *GlobalContext) (int, error) {
return 0, err
}

fullPath := path.Join(i.Path, platform.VersionPath)
fullPath := filepath.Join(i.Path, platform.VersionPath)
file, err := os.ReadFile(fullPath)
if err != nil {
if os.IsNotExist(err) {
Expand All @@ -467,7 +466,7 @@ func (i *Installation) GetPlatform(ctx *GlobalContext) (*Platform, error) {
}

for _, platform := range platforms {
fullPath := path.Join(i.Path, platform.VersionPath)
fullPath := filepath.Join(i.Path, platform.VersionPath)
_, err := os.Stat(fullPath)
if err != nil {
if os.IsNotExist(err) {
Expand Down
14 changes: 7 additions & 7 deletions cli/platforms.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cli

import "path"
import "path/filepath"

type Platform struct {
VersionPath string
Expand All @@ -9,15 +9,15 @@ type Platform struct {

var platforms = []Platform{
{
VersionPath: path.Join("Engine", "Binaries", "Linux", "UE4Server-Linux-Shipping.version"),
LockfilePath: path.Join("FactoryGame", "Mods"),
VersionPath: filepath.Join("Engine", "Binaries", "Linux", "UE4Server-Linux-Shipping.version"),
LockfilePath: filepath.Join("FactoryGame", "Mods"),
},
{
VersionPath: path.Join("Engine", "Binaries", "Win64", "UE4Server-Win64-Shipping.version"),
LockfilePath: path.Join("FactoryGame", "Mods"),
VersionPath: filepath.Join("Engine", "Binaries", "Win64", "UE4Server-Win64-Shipping.version"),
LockfilePath: filepath.Join("FactoryGame", "Mods"),
},
{
VersionPath: path.Join("Engine", "Binaries", "Win64", "FactoryGame-Win64-Shipping.version"),
LockfilePath: path.Join("FactoryGame", "Mods"),
VersionPath: filepath.Join("Engine", "Binaries", "Win64", "FactoryGame-Win64-Shipping.version"),
LockfilePath: filepath.Join("FactoryGame", "Mods"),
},
}
10 changes: 5 additions & 5 deletions cli/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -54,7 +54,7 @@ type ProfileMod struct {
func InitProfiles() (*Profiles, error) {
localDir := viper.GetString("local-dir")

profilesFile := path.Join(localDir, viper.GetString("profiles-file"))
profilesFile := filepath.Join(localDir, viper.GetString("profiles-file"))
_, err := os.Stat(profilesFile)
if err != nil {
if !os.IsNotExist(err) {
Expand All @@ -78,14 +78,14 @@ func InitProfiles() (*Profiles, error) {
}

// Import profiles from SMM if already exists
smmProfilesDir := path.Join(viper.GetString("base-local-dir"), "SatisfactoryModManager", "profiles")
smmProfilesDir := filepath.Join(viper.GetString("base-local-dir"), "SatisfactoryModManager", "profiles")
_, err = os.Stat(smmProfilesDir)
if err == nil {
dir, err := os.ReadDir(smmProfilesDir)
if err == nil {
for _, entry := range dir {
if entry.IsDir() {
manifestFile := path.Join(smmProfilesDir, entry.Name(), "manifest.json")
manifestFile := filepath.Join(smmProfilesDir, entry.Name(), "manifest.json")
_, err := os.Stat(manifestFile)
if err == nil {
manifestBytes, err := os.ReadFile(manifestFile)
Expand Down Expand Up @@ -169,7 +169,7 @@ func (p *Profiles) Save() error {
return nil
}

profilesFile := path.Join(viper.GetString("local-dir"), viper.GetString("profiles-file"))
profilesFile := filepath.Join(viper.GetString("local-dir"), viper.GetString("profiles-file"))

log.Info().Str("path", profilesFile).Msg("saving profiles")

Expand Down
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"io"
"os"
"path"
"path/filepath"
"runtime"
"time"
Expand Down Expand Up @@ -96,7 +95,7 @@ func init() {
case "windows":
baseLocalDir = os.Getenv("APPDATA")
case "linux":
baseLocalDir = path.Join(os.Getenv("HOME"), ".local", "share")
baseLocalDir = filepath.Join(os.Getenv("HOME"), ".local", "share")
default:
panic("unsupported platform: " + runtime.GOOS)
}
Expand Down
8 changes: 6 additions & 2 deletions tea/scenes/main_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ func (m mainMenu) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m mainMenu) View() string {
banner := lipgloss.NewStyle().Margin(2, 0, 0, 2).Render(m.banner)
header := m.root.View()

header := lipgloss.JoinVertical(lipgloss.Left, banner, m.root.View())
banner := lipgloss.NewStyle().Margin(2, 0, 0, 2).Render(m.banner)
totalHeight := m.root.Height() + len(m.list.Items()) + lipgloss.Height(banner) + 4
if totalHeight < m.root.Size().Height {
header = lipgloss.JoinVertical(lipgloss.Left, banner, m.root.View())
}

if m.error != nil {
err := (*m.error).View()
Expand Down
12 changes: 6 additions & 6 deletions tea/scenes/new_installation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scenes

import (
"os"
"path"
"path/filepath"
"time"

"github.com/charmbracelet/bubbles/key"
Expand Down Expand Up @@ -101,9 +101,9 @@ func (m newInstallation) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
newPath := ""
_, err := os.ReadDir(m.input.Value())
if err == nil {
newPath = path.Join(m.input.Value(), newDir)
newPath = filepath.Join(m.input.Value(), newDir)
} else {
newPath = path.Join(path.Dir(m.input.Value()), newDir)
newPath = filepath.Join(filepath.Dir(m.input.Value()), newDir)
}

m.input.SetValue(newPath + string(os.PathSeparator))
Expand Down Expand Up @@ -150,7 +150,7 @@ func (m newInstallation) View() string {
}

if len(m.dirList.Items()) > 0 {
m.dirList.SetSize(m.dirList.Width(), m.root.Size().Height-lipgloss.Height(mandatory))
m.dirList.SetSize(m.dirList.Width(), m.root.Size().Height-lipgloss.Height(mandatory)-1)

return lipgloss.JoinVertical(lipgloss.Left, mandatory, m.dirList.View())
}
Expand All @@ -162,9 +162,9 @@ func getDirItems(inputValue string) []list.Item {
filter := ""
dir, err := os.ReadDir(inputValue)
if err != nil {
dir, err = os.ReadDir(path.Dir(inputValue))
dir, err = os.ReadDir(filepath.Dir(inputValue))
if err == nil {
filter = path.Base(inputValue)
filter = filepath.Base(inputValue)
}
}

Expand Down
10 changes: 5 additions & 5 deletions utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"
"net/http"
"os"
"path"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/viper"
Expand Down Expand Up @@ -46,14 +46,14 @@ type GenericUpdate struct {
}

func DownloadOrCache(cacheKey string, hash string, url string, updates chan GenericUpdate) (r io.ReaderAt, size int64, err error) {
downloadCache := path.Join(viper.GetString("cache-dir"), "downloadCache")
downloadCache := filepath.Join(viper.GetString("cache-dir"), "downloadCache")
if err := os.MkdirAll(downloadCache, 0777); err != nil {
if !os.IsExist(err) {
return nil, 0, errors.Wrap(err, "failed creating download cache")
}
}

location := path.Join(downloadCache, cacheKey)
location := filepath.Join(downloadCache, cacheKey)

stat, err := os.Stat(location)
if err == nil {
Expand Down Expand Up @@ -162,9 +162,9 @@ func ExtractMod(f io.ReaderAt, size int64, location string, updates chan Generic

for i, file := range reader.File {
if !file.FileInfo().IsDir() {
outFileLocation := path.Join(location, file.Name)
outFileLocation := filepath.Join(location, file.Name)

if err := os.MkdirAll(path.Dir(outFileLocation), 0777); err != nil {
if err := os.MkdirAll(filepath.Dir(outFileLocation), 0777); err != nil {
return errors.Wrap(err, "failed to create mod directory: "+location)
}

Expand Down

0 comments on commit ac1dfb6

Please sign in to comment.