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
import (
"errors"
"fmt"
"os"
"path/filepath"
@ -22,10 +21,10 @@ func getSongsDir(baseOsuDir string) (string, error) {
stat, err := os.Stat(songsDir)
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() {
return "", errors.New("Given Osu! directory is not a directory !")
return "", fmt.Errorf("given Osu! directory is not a directory")
}
return songsDir, nil
@ -35,7 +34,7 @@ func getSongsDir(baseOsuDir string) (string, error) {
func getDiffs(path string) ([]string, error) {
files, err := os.ReadDir(path)
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
@ -65,7 +64,7 @@ func GetBeatmaps(baseOsuDir string) ([]Beatmap, error) {
}
contents, err := os.ReadDir(songsDir)
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

6
manager/parse.go

@ -1,7 +1,7 @@
package manager
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
@ -24,13 +24,13 @@ func (BEATMAP *Beatmap) GetBackgroundName(diff string) (string, error) {
// get index of "[Events]" (this is where BG filename is stored)
eventsIndex := strings.Index(beatmapContents, "[Events]")
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,
// so we can grab the whole "[Events]" tag contents)
timingPointsIndex := strings.Index(beatmapContents, "[TimingPoints]")
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], ",")

11
settings/settings.go

@ -2,7 +2,6 @@ package settings
import (
"encoding/json"
"errors"
"fmt"
"os"
@ -18,7 +17,7 @@ const (
func DoesExist() (bool, error) {
files, err := os.ReadDir(".")
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 {
@ -42,8 +41,9 @@ func Create() error {
file, err := os.Create(settingsFilename)
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
settingsJson, err := json.MarshalIndent(Settings{
@ -67,11 +67,10 @@ func Create() error {
Workers: 100,
}, "", " ")
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.Close()
return nil
}
@ -90,7 +89,7 @@ func Get() Settings {
}
// 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...")
os.Exit(0)
}

Loading…
Cancel
Save