From 8f8f3d571fc702fd31c1008c8ec056c3741b3e35 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 30 Sep 2018 11:30:17 +0200 Subject: updater: windows fixes - fix .part rename - add press enter pause to panics --- tools/updater/download.go | 6 ++---- tools/updater/main.go | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/updater/download.go b/tools/updater/download.go index 2adfe41..8c9de9a 100644 --- a/tools/updater/download.go +++ b/tools/updater/download.go @@ -83,8 +83,6 @@ func downloadFile(path string, url string) error { } fmt.Printf("\n") - //fmt.Printf("\r%s", strings.Repeat(" ", 40)) - os.Rename(path+".part", path) - //fmt.Printf("\r[%s] complete\n", path) - return nil + output.Close() + return os.Rename(path+".part", path) } diff --git a/tools/updater/main.go b/tools/updater/main.go index deaad87..baef1f1 100644 --- a/tools/updater/main.go +++ b/tools/updater/main.go @@ -5,10 +5,20 @@ import ( "flag" "fmt" "net/http" + "os" "runtime" "strings" ) +func fail(err error) { + fmt.Printf("An error has occurred:\n%s\n", err.Error()) + if runtime.GOOS == "windows" { + fmt.Print("Press 'Enter' to continue...") + fmt.Scanln() + } + os.Exit(-1) +} + func main() { helpFlag := flag.Bool("help", false, "Show help information") verboseFlag := flag.Bool("verbose", false, "Print more information") @@ -34,7 +44,7 @@ func main() { response, err := http.Get(manifestPath) if err != nil { - panic(err) + fail(err) } else if response.StatusCode != 200 { fmt.Printf("Could not get manifest: %s\n", response.Status) return @@ -50,14 +60,16 @@ func main() { checksum := s[0] if same, err := checkFile(filepath, checksum); err != nil { - panic(err) + fail(err) } else { if *verboseFlag { fmt.Printf("[%s]: %t\n", filepath, same) } if !same && !*dryRunFlag { - downloadFile(filepath, repoPath+filepath) + if err := downloadFile(filepath, repoPath+filepath); err != nil { + fail(err) + } } } } -- cgit v1.2.1