From 587962840a368f95fc95ac6742f9fc22c4dce5f2 Mon Sep 17 00:00:00 2001 From: Unbewohnte <65883674+Unbewohnte@users.noreply.github.com> Date: Mon, 3 May 2021 19:58:27 +0300 Subject: [PATCH] Delete paths.go --- manager/paths.go | 82 ------------------------------------------------ 1 file changed, 82 deletions(-) delete mode 100644 manager/paths.go diff --git a/manager/paths.go b/manager/paths.go deleted file mode 100644 index 4269855..0000000 --- a/manager/paths.go +++ /dev/null @@ -1,82 +0,0 @@ -package manager - -import ( - "errors" - "fmt" - "os" - "path/filepath" - - "github.com/Unbewohnte/OBM/util" -) - -// filepath.Joins the main osu directory with its songs folder -func getSongsDir(baseOsuDir string) (string, error) { - songsDir := filepath.Join(baseOsuDir, "Songs") - - stat, err := os.Stat(songsDir) - if err != nil { - return "", errors.New(fmt.Sprintf("Could not process the given path : %s", err)) - } - if !stat.IsDir() { - return "", errors.New("Given Osu! directory is not a directory !") - } - - return songsDir, nil -} - -// checks for .osu files in given path and returns all found instances -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)) - } - - var diffs []string - for _, file := range files { - filename := file.Name() - if util.IsBeatmap(filename) { - diffs = append(diffs, filename) - } - } - return diffs, nil -} - -// constructs a `Beatmap` struct and returns it -func newBeatmap(name, path string, diffs []string) Beatmap { - return Beatmap{ - Name: name, - Path: path, - Diffs: diffs, - } -} - -// returns an array of beatmaps from given base Osu! directory -func GetBeatmaps(baseOsuDir string) ([]Beatmap, error) { - songsDir, err := getSongsDir(baseOsuDir) - if err != nil { - return nil, err - } - contents, err := os.ReadDir(songsDir) - if err != nil { - return nil, errors.New(fmt.Sprintf("Could not read a directory : %s", err)) - } - - var beatmaps []Beatmap - // looping through all folders in yourOsuDir/Songs/ directory - for _, file := range contents { - if file.IsDir() { - // retrieving all necessary data for creating a new instance of a beatmap - beatmapName := file.Name() - pathToBeatmap := filepath.Join(songsDir, beatmapName) - diffs, err := getDiffs(pathToBeatmap) - if err != nil { - continue - } - newBeatmap := newBeatmap(beatmapName, pathToBeatmap, diffs) - - beatmaps = append(beatmaps, newBeatmap) - } - } - - return beatmaps, nil -}