Browse Source

Little fix

main
Unbewohnte 3 years ago
parent
commit
88f50f8724
  1. 9
      manager/beatmap.go
  2. 6
      manager/parse.go
  3. 11
      settings/settings.go

9
manager/beatmap.go

@ -1,7 +1,6 @@
package manager package manager
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -22,10 +21,10 @@ func getSongsDir(baseOsuDir string) (string, error) {
stat, err := os.Stat(songsDir) stat, err := os.Stat(songsDir)
if err != nil { if err != nil {
return "", errors.New(fmt.Sprintf("Could not process the given path : %s", err)) return "", fmt.Errorf("could not process the given path : %s", err)
} }
if !stat.IsDir() { if !stat.IsDir() {
return "", errors.New("Given Osu! directory is not a directory !") return "", fmt.Errorf("given Osu! directory is not a directory")
} }
return songsDir, nil return songsDir, nil
@ -35,7 +34,7 @@ func getSongsDir(baseOsuDir string) (string, error) {
func getDiffs(path string) ([]string, error) { func getDiffs(path string) ([]string, error) {
files, err := os.ReadDir(path) files, err := os.ReadDir(path)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Could not read a directory : %s", err)) return nil, fmt.Errorf("could not read a directory : %s", err)
} }
var diffs []string var diffs []string
@ -65,7 +64,7 @@ func GetBeatmaps(baseOsuDir string) ([]Beatmap, error) {
} }
contents, err := os.ReadDir(songsDir) contents, err := os.ReadDir(songsDir)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Could not read a directory : %s", err)) return nil, fmt.Errorf("could not read a directory : %s", err)
} }
var beatmaps []Beatmap var beatmaps []Beatmap

6
manager/parse.go

@ -1,7 +1,7 @@
package manager package manager
import ( import (
"errors" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -24,13 +24,13 @@ func (BEATMAP *Beatmap) GetBackgroundName(diff string) (string, error) {
// get index of "[Events]" (this is where BG filename is stored) // get index of "[Events]" (this is where BG filename is stored)
eventsIndex := strings.Index(beatmapContents, "[Events]") eventsIndex := strings.Index(beatmapContents, "[Events]")
if eventsIndex == -1 { if eventsIndex == -1 {
return "", errors.New("Could not retrieve index of \"[Events]\"") return "", fmt.Errorf("could not retrieve index of \"[Events]\"")
} }
// get index of [TimingPoints] (this tag is right after the previous "[Events]" tag, // get index of [TimingPoints] (this tag is right after the previous "[Events]" tag,
// so we can grab the whole "[Events]" tag contents) // so we can grab the whole "[Events]" tag contents)
timingPointsIndex := strings.Index(beatmapContents, "[TimingPoints]") timingPointsIndex := strings.Index(beatmapContents, "[TimingPoints]")
if timingPointsIndex == -1 { if timingPointsIndex == -1 {
return "", errors.New("Could not retrieve index of \"[TimingPoints]\"") return "", fmt.Errorf("could not retrieve index of \"[TimingPoints]\"")
} }
contentBetween := strings.Split(beatmapContents[eventsIndex:timingPointsIndex], ",") contentBetween := strings.Split(beatmapContents[eventsIndex:timingPointsIndex], ",")

11
settings/settings.go

@ -2,7 +2,6 @@ package settings
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
@ -18,7 +17,7 @@ const (
func DoesExist() (bool, error) { func DoesExist() (bool, error) {
files, err := os.ReadDir(".") files, err := os.ReadDir(".")
if err != nil { if err != nil {
return false, errors.New(fmt.Sprintf("Unable to read current directory %s", err)) return false, fmt.Errorf("wasn`t able to read current directory %s", err)
} }
for _, file := range files { for _, file := range files {
@ -42,8 +41,9 @@ func Create() error {
file, err := os.Create(settingsFilename) file, err := os.Create(settingsFilename)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Unable to create settings file : %s", err)) return fmt.Errorf("could not create settings file : %s", err)
} }
defer file.Close()
// marshaling default settings // marshaling default settings
settingsJson, err := json.MarshalIndent(Settings{ settingsJson, err := json.MarshalIndent(Settings{
@ -67,11 +67,10 @@ func Create() error {
Workers: 100, Workers: 100,
}, "", " ") }, "", " ")
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("Could not marshal settings into file : %s", err)) return fmt.Errorf("could not marshal settings into file : %s", err)
} }
file.Write(settingsJson) file.Write(settingsJson)
file.Close()
return nil return nil
} }
@ -90,7 +89,7 @@ func Get() Settings {
} }
// if all features are disabled // if all features are disabled
if !settings.BackgroundReplacement.Enabled && !settings.BackgroundRetrievement.Enabled { if !settings.BackgroundReplacement.Enabled && !settings.BackgroundRetrievement.Enabled && !settings.BackgroundRemovement.Enabled {
logger.LogInfo("No features enabled. Exiting...") logger.LogInfo("No features enabled. Exiting...")
os.Exit(0) os.Exit(0)
} }

Loading…
Cancel
Save