remove unknown patches
This commit is contained in:
@ -16,6 +16,7 @@ type Config struct {
|
|||||||
LaunchCmd string
|
LaunchCmd string
|
||||||
WinePrefix string
|
WinePrefix string
|
||||||
EnableLauncher bool
|
EnableLauncher bool
|
||||||
|
RemoveUnknownPatches bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -39,6 +40,7 @@ func setupConfig(rerun bool) (*Config, error) {
|
|||||||
WowDir: defaultWowPath,
|
WowDir: defaultWowPath,
|
||||||
LaunchCmd: defaultLaunchCmd,
|
LaunchCmd: defaultLaunchCmd,
|
||||||
EnableLauncher: false,
|
EnableLauncher: false,
|
||||||
|
RemoveUnknownPatches: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, statErr := os.Stat(cfgPath)
|
_, statErr := os.Stat(cfgPath)
|
||||||
|
37
main.go
37
main.go
@ -6,11 +6,13 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -175,5 +177,40 @@ func downloadUpdate(config *Config, force bool) (DownloadStats, error) {
|
|||||||
stats.updated += 1
|
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
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user