Browse Source

Tidied a bit, changed go.mod

main
parent
commit
76b489b424
  1. 3
      .gitignore
  2. 2
      Makefile
  3. 16
      flags.go
  4. 3
      go.mod
  5. 64
      src/OBM.go
  6. 3
      src/go.mod
  7. 0
      src/logger/logger.go
  8. 1
      src/logs/logs.log
  9. 2
      src/manager/beatmap.go
  10. 2
      src/manager/parse.go
  11. 2
      src/manager/remove.go
  12. 4
      src/manager/replace.go
  13. 4
      src/manager/retrieve.go
  14. 0
      src/manager/search.go
  15. 4
      src/settings/settings.go
  16. 0
      src/settings/structure.go
  17. 0
      src/util/background.go
  18. 0
      src/util/checks.go
  19. 0
      src/util/copy.go
  20. 52
      worker.go

3
.gitignore vendored

@ -0,0 +1,3 @@
settings.json
OBM
logs

2
Makefile

@ -0,0 +1,2 @@
all:
cd src && go build && mv OBM ..

16
flags.go

@ -1,16 +0,0 @@
package main
import (
"flag"
)
var (
orderMessage string = "Order: Replace -> Retrieve -> Remove\n"
)
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`)
showOrder = flag.Bool("showOrder", false, "Prints an order in which functions are performed on a beatmap")
)

3
go.mod

@ -1,3 +0,0 @@
module unbewohnte.xyz/Unbewohnte/OBM
go 1.16

64
OBM.go → src/OBM.go

@ -7,12 +7,68 @@ import (
"sync" "sync"
"time" "time"
"unbewohnte.xyz/Unbewohnte/OBM/logger" "unbewohnte/OBM/logger"
"unbewohnte.xyz/Unbewohnte/OBM/manager" "unbewohnte/OBM/manager"
"unbewohnte.xyz/Unbewohnte/OBM/settings" "unbewohnte/OBM/settings"
"unbewohnte.xyz/Unbewohnte/OBM/util" "unbewohnte/OBM/util"
) )
const orderMessage string = "Order: Replace -> Retrieve -> Remove\n"
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`)
showOrder = flag.Bool("showOrder", false, "Prints an order in which functions are performed on a beatmap")
)
// a basic implementation of a concurrent worker
func worker(jobs <-chan job, results chan result, WG *sync.WaitGroup) {
defer WG.Done()
for job := range jobs {
var successful, failed uint = 0, 0
// the order is: Replace->Retrieve->Remove (if all 3 options are enabled)
if job.replacementImagePath != "" {
s, f := job.beatmap.ReplaceBackgrounds(job.replacementImagePath)
successful += s
failed += f
}
if job.retrievementPath != "" {
s, f := job.beatmap.RetrieveBackgrounds(job.retrievementPath)
successful += s
failed += f
}
if job.remove == true {
s, f := job.beatmap.RemoveBackgrounds()
successful += s
failed += f
}
results <- result{
beatmapName: job.beatmap.Name,
numberOfDiffs: uint(len(job.beatmap.Diffs)),
successful: successful,
failed: failed,
}
}
}
// the `starter` that `glues` workers and jobs together
func workerPool(jobs chan job, results chan result, numOfWorkers int, WG *sync.WaitGroup) {
// check if there are less jobs than workers
if numOfWorkers > len(jobs) {
numOfWorkers = len(jobs)
}
// replacing backgrounds for each beatmap concurrently
for i := 0; i < numOfWorkers; i++ {
WG.Add(1)
go worker(jobs, results, WG)
}
}
type result struct { type result struct {
beatmapName string beatmapName string
numberOfDiffs uint numberOfDiffs uint

3
src/go.mod

@ -0,0 +1,3 @@
module unbewohnte/OBM
go 1.16

0
logger/logger.go → src/logger/logger.go

1
src/logs/logs.log

@ -0,0 +1 @@
INFO: 2022/08/14 18:24:01 Successfully created new settings file

2
manager/beatmap.go → src/manager/beatmap.go

@ -5,7 +5,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"unbewohnte.xyz/Unbewohnte/OBM/util" "unbewohnte/OBM/util"
) )
// the main beatmap struct, contains necessary data for functions // the main beatmap struct, contains necessary data for functions

2
manager/parse.go → src/manager/parse.go

@ -6,7 +6,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"unbewohnte.xyz/Unbewohnte/OBM/util" "unbewohnte/OBM/util"
) )
// parses given .osu file and returns the filename of its background // parses given .osu file and returns the filename of its background

2
manager/remove.go → src/manager/remove.go

@ -5,7 +5,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"unbewohnte.xyz/Unbewohnte/OBM/logger" "unbewohnte/OBM/logger"
) )
// parses each difficulty for background info, removes found backgrounds // parses each difficulty for background info, removes found backgrounds

4
manager/replace.go → src/manager/replace.go

@ -5,8 +5,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"unbewohnte.xyz/Unbewohnte/OBM/logger" "unbewohnte/OBM/logger"
"unbewohnte.xyz/Unbewohnte/OBM/util" "unbewohnte/OBM/util"
) )
// parses each beatmap`s .osu file for background info; // parses each beatmap`s .osu file for background info;

4
manager/retrieve.go → src/manager/retrieve.go

@ -5,8 +5,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"unbewohnte.xyz/Unbewohnte/OBM/logger" "unbewohnte/OBM/logger"
"unbewohnte.xyz/Unbewohnte/OBM/util" "unbewohnte/OBM/util"
) )
// retrieves backgrounds from given beatmap folder (same as in `ReplaceBackgrounds`) and copies them to the retrievement path // retrieves backgrounds from given beatmap folder (same as in `ReplaceBackgrounds`) and copies them to the retrievement path

0
manager/search.go → src/manager/search.go

4
settings/settings.go → src/settings/settings.go

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"os" "os"
"unbewohnte.xyz/Unbewohnte/OBM/logger" "unbewohnte/OBM/logger"
"unbewohnte.xyz/Unbewohnte/OBM/util" "unbewohnte/OBM/util"
) )
const ( const (

0
settings/structure.go → src/settings/structure.go

0
util/background.go → src/util/background.go

0
util/checks.go → src/util/checks.go

0
util/copy.go → src/util/copy.go

52
worker.go

@ -1,52 +0,0 @@
package main
import (
"sync"
)
// a basic implementation of a concurrent worker
func worker(jobs <-chan job, results chan result, WG *sync.WaitGroup) {
defer WG.Done()
for job := range jobs {
var successful, failed uint = 0, 0
// the order is: Replace->Retrieve->Remove (if all 3 options are enabled)
if job.replacementImagePath != "" {
s, f := job.beatmap.ReplaceBackgrounds(job.replacementImagePath)
successful += s
failed += f
}
if job.retrievementPath != "" {
s, f := job.beatmap.RetrieveBackgrounds(job.retrievementPath)
successful += s
failed += f
}
if job.remove == true {
s, f := job.beatmap.RemoveBackgrounds()
successful += s
failed += f
}
results <- result{
beatmapName: job.beatmap.Name,
numberOfDiffs: uint(len(job.beatmap.Diffs)),
successful: successful,
failed: failed,
}
}
}
// the `starter` that `glues` workers and jobs together
func workerPool(jobs chan job, results chan result, numOfWorkers int, WG *sync.WaitGroup) {
// check if there are less jobs than workers
if numOfWorkers > len(jobs) {
numOfWorkers = len(jobs)
}
// replacing backgrounds for each beatmap concurrently
for i := 0; i < numOfWorkers; i++ {
WG.Add(1)
go worker(jobs, results, WG)
}
}
Loading…
Cancel
Save