remove native UI elements, update README
This commit is contained in:
55
main.go
55
main.go
@ -25,9 +25,11 @@ func main() {
|
||||
var (
|
||||
helpFlag bool
|
||||
updateOnlyFlag bool
|
||||
forceFlag bool
|
||||
rerunConfig bool
|
||||
)
|
||||
flag.BoolVar(&helpFlag, "h", false, "Print help")
|
||||
flag.BoolVar(&forceFlag, "f", false, "Forces epochcli to update files even if they match the current version")
|
||||
flag.BoolVar(&updateOnlyFlag, "u", false, "Ignore EnableLauncher setting in config and only runs an update. Does nothing if EnableLauncher is false")
|
||||
flag.BoolVar(&rerunConfig, "c", false, "Runs config configuration step. Overrides the config file")
|
||||
flag.Parse()
|
||||
@ -47,14 +49,14 @@ func main() {
|
||||
log.Fatalf("WowDir in %s is still the default setting, exiting", cfgPath)
|
||||
}
|
||||
|
||||
updated, current, err := downloadUpdate(config)
|
||||
stats, err := downloadUpdate(config, forceFlag)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Updated %d files\n", updated)
|
||||
if current > 0 {
|
||||
fmt.Printf("%d files are already up to date\n", current)
|
||||
fmt.Printf("%d files updated\n", stats.updated)
|
||||
if stats.current > 0 {
|
||||
fmt.Printf("%d files are already up to date\n", stats.current)
|
||||
}
|
||||
|
||||
if updateOnlyFlag {
|
||||
@ -76,8 +78,13 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func downloadUpdate(config *Config) (int, int, error) {
|
||||
var updateCount, currentCount int
|
||||
type DownloadStats struct {
|
||||
updated int
|
||||
current int
|
||||
}
|
||||
|
||||
func downloadUpdate(config *Config, force bool) (DownloadStats, error) {
|
||||
var stats DownloadStats
|
||||
|
||||
manifest, err := getManifest()
|
||||
if err != nil {
|
||||
@ -94,17 +101,19 @@ func downloadUpdate(config *Config) (int, int, error) {
|
||||
os.MkdirAll(localDir, 0755)
|
||||
}
|
||||
|
||||
if _, err = os.Stat(localPath); err == nil {
|
||||
data, err := os.ReadFile(localPath)
|
||||
if err != nil {
|
||||
return updateCount, currentCount, err
|
||||
}
|
||||
hashBytes := md5.Sum(data)
|
||||
hash := hex.EncodeToString(hashBytes[:])
|
||||
if hash == file.Hash {
|
||||
fmt.Printf("File %s is up to date\n", localPath)
|
||||
currentCount += 1
|
||||
continue
|
||||
if !force {
|
||||
if _, err = os.Stat(localPath); err == nil {
|
||||
data, err := os.ReadFile(localPath)
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
hashBytes := md5.Sum(data)
|
||||
hash := hex.EncodeToString(hashBytes[:])
|
||||
if hash == file.Hash {
|
||||
fmt.Printf("File %s is up to date\n", localPath)
|
||||
stats.current += 1
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,26 +121,26 @@ func downloadUpdate(config *Config) (int, int, error) {
|
||||
|
||||
outFile, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
return updateCount, currentCount, err
|
||||
return stats, err
|
||||
}
|
||||
defer outFile.Close()
|
||||
|
||||
resp, err := http.Get(file.URL)
|
||||
if err != nil {
|
||||
return updateCount, currentCount, err
|
||||
return stats, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return updateCount, currentCount, fmt.Errorf("failed to download update from %s, status code: %d", file.URL, resp.StatusCode)
|
||||
return stats, fmt.Errorf("failed to download update from %s, status code: %d", file.URL, resp.StatusCode)
|
||||
}
|
||||
|
||||
_, err = io.Copy(outFile, resp.Body)
|
||||
if err != nil {
|
||||
return updateCount, currentCount, err
|
||||
return stats, err
|
||||
}
|
||||
|
||||
updateCount += 1
|
||||
stats.updated += 1
|
||||
}
|
||||
|
||||
return updateCount, currentCount, nil
|
||||
return stats, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user