Browse Source

Added support for -beatmap flag

main
Unbewohnte 3 years ago committed by GitHub
parent
commit
7a2dbbf7ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      OBM.go
  2. 26
      README.md
  3. 11
      flags.go
  4. 17
      manager/beatmap.go

22
OBM.go

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"sync" "sync"
@ -36,8 +37,10 @@ func init() {
logger.LogInfo("Successfully created new settings file") logger.LogInfo("Successfully created new settings file")
os.Exit(0) os.Exit(0)
} }
logger.LogInfo("Found settings file") logger.LogInfo("Found settings file")
// parse for `-beatmap` argument
flag.Parse()
return return
} }
@ -48,7 +51,7 @@ func main() {
SETTINGS := settings.Get() SETTINGS := settings.Get()
// creating black image // creating black image if enabled
if SETTINGS.CreateBlackBGImage.Enabled { if SETTINGS.CreateBlackBGImage.Enabled {
err := util.CreateBlackBG(SETTINGS.CreateBlackBGImage.Width, SETTINGS.CreateBlackBGImage.Height) err := util.CreateBlackBG(SETTINGS.CreateBlackBGImage.Width, SETTINGS.CreateBlackBGImage.Height)
if err == nil { if err == nil {
@ -58,12 +61,27 @@ func main() {
} }
} }
// get an array of all beatmaps
beatmaps, err := manager.GetBeatmaps(SETTINGS.OsuDir) beatmaps, err := manager.GetBeatmaps(SETTINGS.OsuDir)
if err != nil { if err != nil {
logger.LogError(true, "Error getting beatmaps: ", err) logger.LogError(true, "Error getting beatmaps: ", err)
} }
logger.LogInfo(fmt.Sprintf("Found %d beatmaps", len(beatmaps))) logger.LogInfo(fmt.Sprintf("Found %d beatmaps", len(beatmaps)))
// If `cmdlnBeatmap` is specified - do the magic only for found beatmaps
if *cmdlnBeatmap != "" {
logger.LogInfo(fmt.Sprintf("Trying to locate \"%s\"...", *cmdlnBeatmap))
found, n := manager.Search(beatmaps, *cmdlnBeatmap)
logger.LogInfo(fmt.Sprintf("Checked %d beatmaps. Found %d instance(s)", n, len(found)))
// if found nothing - exit
if len(found) == 0 {
os.Exit(0)
}
// replace all beatmaps with found ones
beatmaps = found
}
// creating jobs for workers // creating jobs for workers
jobs := make(chan job, len(beatmaps)) jobs := make(chan job, len(beatmaps))
for _, beatmap := range beatmaps { for _, beatmap := range beatmaps {

26
README.md

@ -1,6 +1,6 @@
# OBM (Osu!-background-manager) # OBM (Osu!-Background-Manager)
## This utility will help you with replacement and retrievement of Osu!`s beatmap backgrounds and more in the future ## This utility will help you with replacement and retrievement of Osu!`s beatmap backgrounds
**Use at your own risk !** **Use at your own risk !**
There is no way to return removed original backgrounds unless you delete all beatmaps and reimport newly downloaded versions of them again. There is no way to return removed original backgrounds unless you delete all beatmaps and reimport newly downloaded versions of them again.
@ -11,28 +11,40 @@ There is no way to return removed original backgrounds unless you delete all bea
### From source (You`ll need [Go](https://golang.org/dl/) installed) ### From source (You`ll need [Go](https://golang.org/dl/) installed)
1. `git clone https://github.com/Unbewohnte/OBM.git` or download and unzip the archive 1. `git clone https://github.com/Unbewohnte/OBM.git` or download and unzip the archive
2. cd into the directory 2. `cd` into the directory
3. `go build` 3. `go build`
### From release ### From release
1. go to the [releases](https://github.com/Unbewohnte/OBM/releases) page 1. go to the [releases](https://github.com/Unbewohnte/OBM/releases) page
2. choose your OS and download the archive 2. choose your OS and download the archive
3. cd to the location of the downloaded version 3. `cd` to the location of the downloaded version
4. unzip (`7z x **archive_name**`) - for 7z archives 4. unzip (`7z x **archive_name**`) - for 7z archives
--- ---
## Usage ## Usage
To run - `./OBM` in terminal (on Unix) || `OBM` in command line (on Windows)
### First run ### First run
1. The program will generate a settings.json file if it is not already in the directory when you run it 1. The program will generate a settings.json file if it is not already in the directory when you run it
2. Paste your Osu! filepath in the "pathToOsu" field (this field is required) 2. Paste your Osu! filepath in the "pathToOsu" field
3. Enable/Disable needed features, providing valid filepaths to them 3. Enable/Disable needed features, providing valid filepaths to them
4. Additionally you can disable the "createBlackBackgoundImage" by replacing **true** with **false** or change the number of workers 4. Additionally you can disable the "createBlackBackgoundImage" by replacing **true** with **false** or change the number of workers
5. Run the program once again
### After ### After
1. Start the utility again. If it has found the settings file - it will perform the magic 1. Start the utility again. If it has found the settings file - it will perform the magic according to provided rules
### Flags (starting from version 1.3.4)
Right now there is one argument that you can specify before running the program - "beatmap"
#### Examples
1. `./OBM -beatmap=""` - the same as just `./OBM`. It will affect **all** of your beatmaps
2. `./OBM -beatmap="Demetori"` - this will search for beatmaps with names that contain "Demetori" and will work only with them
3. `./OBM -beatmap=Demetori` - the same as before, but without "" (look at 4 - 5 for nuances)
4. `./OBM -beatmap=raise my sword` - NOTE that this will make the program look only for word "raise", but not for the whole sequence
5. `./OBM -beatmap="raise my sword"` - this is the valid option for 4 (You need to use "" in case of a multi-word name)
The search is case-insensitive, so for example `./OBM -beatmap="Road of Resistance"` and `./OBM -beatmap="ROAD of rEsIsTaNcE"` will get you the same results
--- ---

11
flags.go

@ -0,0 +1,11 @@
package main
import (
"flag"
)
var (
cmdlnBeatmap = flag.String("beatmap", "", `Specifies a certain beatmap.
If set to non "" - the program will search for given name and perform the magic
provided in settings if successful`)
)

17
manager/beatmap.go

@ -186,3 +186,20 @@ func (BEATMAP *Beatmap) RetrieveBackgrounds(retrievementPath string) (successful
} }
return successful, failed return successful, failed
} }
// Search tries to locate instances of beatmaps with the provided name (or part of the name);
// returns a slice of found beatmaps and a number of searched beatmaps
func Search(beatmaps []Beatmap, name string) ([]Beatmap, uint64) {
var instances []Beatmap
var searched uint64 = 0
// to make a search case-insensitive
name = strings.ToLower(name)
for _, beatmap := range beatmaps {
if strings.Contains(strings.ToLower(beatmap.Name), name) {
instances = append(instances, beatmap)
}
searched++
}
return instances, searched
}

Loading…
Cancel
Save