You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
4 years ago
|
package manager
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
|
||
|
"github.com/Unbewohnte/OBM/logger"
|
||
|
"github.com/Unbewohnte/OBM/util"
|
||
|
)
|
||
|
|
||
|
// parses each beatmap`s .osu file for background info;
|
||
|
// removes original background and replaces it with copied version of given image
|
||
|
func (BEATMAP *Beatmap) ReplaceBackgrounds(replacementImgPath string) (successful, failed uint) {
|
||
|
// looping through each .osu file of a beatmap
|
||
|
for _, diff := range BEATMAP.Diffs {
|
||
|
background, err := BEATMAP.GetBackgroundName(diff)
|
||
|
if err != nil || background == "" {
|
||
|
logger.LogError(false, fmt.Sprintf("BEATMAP: %s: Error getting background filename: %s", diff, err))
|
||
|
failed++
|
||
|
continue
|
||
|
}
|
||
|
// remove old bg (if there is no background file - no need to worry)
|
||
|
os.Remove(filepath.Join(BEATMAP.Path, background))
|
||
|
|
||
|
// copy given picture, thus replacing background
|
||
|
err = util.CopyFile(replacementImgPath, filepath.Join(BEATMAP.Path, background))
|
||
|
if err != nil {
|
||
|
logger.LogError(false, fmt.Sprintf("BEATMAP: %s: Could not copy: %s", diff, err))
|
||
|
failed++
|
||
|
continue
|
||
|
}
|
||
|
successful++
|
||
|
}
|
||
|
return successful, failed
|
||
|
}
|