upgraded config creation
This commit is contained in:
53
main.go
53
main.go
@ -25,9 +25,11 @@ func main() {
|
||||
var (
|
||||
helpFlag bool
|
||||
updateOnlyFlag bool
|
||||
rerunConfig bool
|
||||
)
|
||||
flag.BoolVar(&helpFlag, "h", false, "Print help")
|
||||
flag.BoolVar(&updateOnlyFlag, "u", false, "Only update the client, do not launch")
|
||||
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()
|
||||
|
||||
if helpFlag {
|
||||
@ -36,7 +38,7 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
config, err := setupConfig()
|
||||
config, err := setupConfig(rerunConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -45,33 +47,37 @@ func main() {
|
||||
log.Fatalf("WowDir in %s is still the default setting, exiting", cfgPath)
|
||||
}
|
||||
|
||||
count, err := downloadUpdate(config)
|
||||
updated, current, err := downloadUpdate(config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Updated %d files\n", count)
|
||||
fmt.Printf("Updated %d files\n", updated)
|
||||
if current > 0 {
|
||||
fmt.Printf("%d files are already up to date\n", current)
|
||||
}
|
||||
|
||||
if updateOnlyFlag {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if config.LaunchCmd == defaultLaunchCmd {
|
||||
log.Fatalf("LaunchCmd in %s is still the default setting, exiting\n", cfgPath)
|
||||
}
|
||||
if config.EnableLauncher {
|
||||
if config.LaunchCmd == defaultLaunchCmd {
|
||||
log.Fatalf("LaunchCmd in %s is still the default setting, exiting\n", cfgPath)
|
||||
}
|
||||
|
||||
fmt.Printf("Starting Epoch....\n", count)
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
exec.Command("open", config.LaunchCmd).Run()
|
||||
case "linux":
|
||||
exec.Command(config.LaunchCmd).Run()
|
||||
fmt.Println("Starting Epoch...")
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
exec.Command("open", config.LaunchCmd).Run()
|
||||
case "linux":
|
||||
exec.Command(config.LaunchCmd).Run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func downloadUpdate(config *Config) (int, error) {
|
||||
var c int
|
||||
func downloadUpdate(config *Config) (int, int, error) {
|
||||
var updateCount, currentCount int
|
||||
|
||||
manifest, err := getManifest()
|
||||
if err != nil {
|
||||
@ -91,11 +97,12 @@ func downloadUpdate(config *Config) (int, error) {
|
||||
if _, err = os.Stat(localPath); err == nil {
|
||||
data, err := os.ReadFile(localPath)
|
||||
if err != nil {
|
||||
return c, err
|
||||
return updateCount, currentCount, err
|
||||
}
|
||||
hashBytes := md5.Sum(data)
|
||||
hash := hex.EncodeToString(hashBytes[:])
|
||||
if hash == file.Hash {
|
||||
currentCount += 1
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -104,26 +111,26 @@ func downloadUpdate(config *Config) (int, error) {
|
||||
|
||||
outFile, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
return c, err
|
||||
return updateCount, currentCount, err
|
||||
}
|
||||
defer outFile.Close()
|
||||
|
||||
resp, err := http.Get(file.URL)
|
||||
if err != nil {
|
||||
return c, err
|
||||
return updateCount, currentCount, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return c, fmt.Errorf("failed to download update from %s, status code: %d", file.URL, resp.StatusCode)
|
||||
return updateCount, currentCount, 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 c, err
|
||||
return updateCount, currentCount, err
|
||||
}
|
||||
|
||||
c += 1
|
||||
updateCount += 1
|
||||
}
|
||||
|
||||
return c, nil
|
||||
return updateCount, currentCount, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user