remove unknown patches
This commit is contained in:
16
config.go
16
config.go
@ -12,10 +12,11 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
WowDir string
|
||||
LaunchCmd string
|
||||
WinePrefix string
|
||||
EnableLauncher bool
|
||||
WowDir string
|
||||
LaunchCmd string
|
||||
WinePrefix string
|
||||
EnableLauncher bool
|
||||
RemoveUnknownPatches bool
|
||||
}
|
||||
|
||||
const (
|
||||
@ -36,9 +37,10 @@ func setupConfig(rerun bool) (*Config, error) {
|
||||
cfgPath = filepath.Join(home, ".config", configDirName, configName)
|
||||
|
||||
newConfig := Config{
|
||||
WowDir: defaultWowPath,
|
||||
LaunchCmd: defaultLaunchCmd,
|
||||
EnableLauncher: false,
|
||||
WowDir: defaultWowPath,
|
||||
LaunchCmd: defaultLaunchCmd,
|
||||
EnableLauncher: false,
|
||||
RemoveUnknownPatches: true,
|
||||
}
|
||||
|
||||
_, statErr := os.Stat(cfgPath)
|
||||
|
37
main.go
37
main.go
@ -6,11 +6,13 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -175,5 +177,40 @@ func downloadUpdate(config *Config, force bool) (DownloadStats, error) {
|
||||
stats.updated += 1
|
||||
}
|
||||
|
||||
if config.RemoveUnknownPatches {
|
||||
patches := make([]string, 0)
|
||||
patchreg := regexp.MustCompile(`patch-[A-Za-z].MPQ`)
|
||||
|
||||
for _, file := range manifest.Files {
|
||||
if patchreg.MatchString(file.Path) {
|
||||
patches = append(patches, strings.Split(file.Path, "Data\\")[1])
|
||||
}
|
||||
}
|
||||
|
||||
err = filepath.WalkDir(filepath.Join(config.WowDir, "Data"), func(path string, d fs.DirEntry, err error) error {
|
||||
if !d.IsDir() && patchreg.MatchString(d.Name()) {
|
||||
del := true
|
||||
for _, patch := range patches {
|
||||
if patch == d.Name() {
|
||||
del = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if del {
|
||||
err = os.Remove(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Removed unknown patch", d.Name())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("failed to delete unknown patches: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user