From ac1dfb61488dd6874ac6a37659d5bd83ea431710 Mon Sep 17 00:00:00 2001 From: Vilsol Date: Sun, 5 Jun 2022 04:56:46 +0300 Subject: [PATCH] path -> filepath --- cli/installations.go | 23 +++++++++++------------ cli/platforms.go | 14 +++++++------- cli/profiles.go | 10 +++++----- cmd/root.go | 3 +-- tea/scenes/main_menu.go | 8 ++++++-- tea/scenes/new_installation.go | 12 ++++++------ utils/io.go | 10 +++++----- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/cli/installations.go b/cli/installations.go index 87231aa..39ebe44 100644 --- a/cli/installations.go +++ b/cli/installations.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "os" - "path" "path/filepath" "regexp" "strings" @@ -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) { @@ -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") @@ -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") @@ -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") @@ -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") @@ -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) { @@ -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") } @@ -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") } } @@ -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) } @@ -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) { @@ -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) { diff --git a/cli/platforms.go b/cli/platforms.go index 831d7ff..a3f28a9 100644 --- a/cli/platforms.go +++ b/cli/platforms.go @@ -1,6 +1,6 @@ package cli -import "path" +import "path/filepath" type Platform struct { VersionPath string @@ -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"), }, } diff --git a/cli/profiles.go b/cli/profiles.go index e6bc855..7841dda 100644 --- a/cli/profiles.go +++ b/cli/profiles.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "os" - "path" + "path/filepath" "strings" "github.com/pkg/errors" @@ -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) { @@ -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) @@ -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") diff --git a/cmd/root.go b/cmd/root.go index 58d19f3..cbae1bf 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,7 +3,6 @@ package cmd import ( "io" "os" - "path" "path/filepath" "runtime" "time" @@ -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) } diff --git a/tea/scenes/main_menu.go b/tea/scenes/main_menu.go index 5d0f007..182ab14 100644 --- a/tea/scenes/main_menu.go +++ b/tea/scenes/main_menu.go @@ -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() diff --git a/tea/scenes/new_installation.go b/tea/scenes/new_installation.go index d12b829..082f176 100644 --- a/tea/scenes/new_installation.go +++ b/tea/scenes/new_installation.go @@ -2,7 +2,7 @@ package scenes import ( "os" - "path" + "path/filepath" "time" "github.com/charmbracelet/bubbles/key" @@ -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)) @@ -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()) } @@ -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) } } diff --git a/utils/io.go b/utils/io.go index cffba70..97472d9 100644 --- a/utils/io.go +++ b/utils/io.go @@ -8,7 +8,7 @@ import ( "io" "net/http" "os" - "path" + "path/filepath" "github.com/pkg/errors" "github.com/spf13/viper" @@ -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 { @@ -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) }