Browse Source

Added field to settings.json

main 1.1.0
Unbewohnte 4 years ago committed by GitHub
parent
commit
6ca3a661cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      backgroundchanger.go

16
backgroundchanger.go

@ -17,9 +17,7 @@ import (
var ( var (
// used as a flag if the program executed for "the first time" // used as a flag if the program executed for "the first time"
settingsFileExisted bool = false settingsFileExisted bool = false
WG sync.WaitGroup
WG sync.WaitGroup
maxWorkers uint = 50
) )
const ( const (
@ -31,6 +29,7 @@ type Settings struct {
OsuDir string `json:"pathToOsu"` OsuDir string `json:"pathToOsu"`
ReplacementImagePath string `json:"pathToimage"` ReplacementImagePath string `json:"pathToimage"`
CreateBlackBGImage bool `json:"createBlackBackgoundImage"` CreateBlackBGImage bool `json:"createBlackBackgoundImage"`
MaxWorkers uint `json:"maxConcurrentWorkers"`
} }
// creates directory for logs and sets output to file // creates directory for logs and sets output to file
@ -67,6 +66,7 @@ func createSettingsFile() {
OsuDir: "", OsuDir: "",
ReplacementImagePath: "", ReplacementImagePath: "",
CreateBlackBGImage: true, CreateBlackBGImage: true,
MaxWorkers: 50,
} }
jsonEncodedSettings, err := json.MarshalIndent(settings, "", " ") jsonEncodedSettings, err := json.MarshalIndent(settings, "", " ")
if err != nil { if err != nil {
@ -104,6 +104,10 @@ func getSettings() Settings {
if err != nil { if err != nil {
log.Fatal("ERROR: Error unmarshalling json file : ", err) log.Fatal("ERROR: Error unmarshalling json file : ", err)
} }
if settings.MaxWorkers <= 0 {
log.Println("`maxConcurrentWorkers` is set to 0 or less. Replaced with 1")
settings.MaxWorkers = 1
}
return settings return settings
} }
@ -305,13 +309,13 @@ func main() {
log.Printf("Found %d song folders", len(songPaths)) log.Printf("Found %d song folders", len(songPaths))
// check if there is less job than workers // check if there is less job than workers
if int(maxWorkers) > len(songPaths) { if int(settings.MaxWorkers) > len(songPaths) {
maxWorkers = uint(len(songPaths)) settings.MaxWorkers = uint(len(songPaths))
} }
// replacing backgrounds for each beatmap concurrently // replacing backgrounds for each beatmap concurrently
var successful, failed uint64 = 0, 0 var successful, failed uint64 = 0, 0
for i := 0; i < int(maxWorkers); i++ { for i := 0; i < int(settings.MaxWorkers); i++ {
WG.Add(1) WG.Add(1)
go worker(songPaths, replacementImage, &successful, &failed, &WG) go worker(songPaths, replacementImage, &successful, &failed, &WG)
} }

Loading…
Cancel
Save