From 844a282fd77ac022231eacf17289dc31f87655fc Mon Sep 17 00:00:00 2001 From: Belac Darkstorm Date: Tue, 4 Apr 2017 01:23:17 -0500 Subject: [PATCH] Wine download finished for later on. Going to start switching to another GUI library --- main.go | 11 +++++------ update.go | 34 +++++++++++++++++----------------- wine.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 wine.go diff --git a/main.go b/main.go index 4f3e0da..f7e64ed 100644 --- a/main.go +++ b/main.go @@ -31,29 +31,28 @@ var ( func main() { updated := false os.MkdirAll("PortableApps/LinuxPACom", 0777) - stat := versionDL() + stat, err := versionDL() if stat { res := getVersionFileInfo() if res != "Error!" { - stat = checkForUpdate(res) + stat, err = checkForUpdate(res) if stat { downloadUpdate(res) updated = true } else { - fmt.Println("Failed DL") + fmt.Println(err) } } else { - fmt.Println("Failed Version File Info") + fmt.Println(err) } } else { - fmt.Println("Failed Version DL") + fmt.Println(err) } if updated { cmd := exec.Command("./LinuxPA") cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Start() - fmt.Println("updated!") } else { master = make(map[string][]app) linmaster = make(map[string][]app) diff --git a/update.go b/update.go index 9e7b531..ed57ce4 100644 --- a/update.go +++ b/update.go @@ -2,7 +2,6 @@ package main import ( "bufio" - "fmt" "io" "net/http" "os" @@ -19,10 +18,10 @@ const ( //For some of the code //Returns if success -func versionDL() bool { +func versionDL() (bool, error) { versionFile, err := os.Create("PortableApps/LinuxPACom/Version") if err != nil { - return false + return false, err } versionFile.Chmod(0777) check := http.Client{ @@ -33,13 +32,13 @@ func versionDL() bool { } response, err := check.Get(versionURL) if err != nil { - return false + return false, err } _, err = io.Copy(versionFile, response.Body) if err != nil { - return false + return false, err } - return true + return true, nil } func getVersionFileInfo() string { @@ -52,7 +51,7 @@ func getVersionFileInfo() string { return string(out) } -func checkForUpdate(new string) bool { +func checkForUpdate(new string) (bool, error) { curSlice := strings.Split(version, ".") newSlice := strings.Split(new, ".") curNums := make([]int, 4) @@ -65,27 +64,28 @@ func checkForUpdate(new string) bool { num, err = strconv.Atoi(newSlice[i]) if err == nil { newNums[i] = num + } else { + return false, err } if newNums[i] > curNums[i] { - return true + return true, nil } } - return false + return false, nil } -func downloadUpdate(newVersion string) bool { +func downloadUpdate(newVersion string) (bool, error) { url := strings.Replace(downloadURL, "XXX", newVersion, -1) err := os.Rename("LinuxPA", ".LinuxPA.old") if err != nil { - fmt.Println(err) - return false + return false, err } fil, err := os.Create("LinuxPA") fil.Chmod(0777) defer fil.Close() if err != nil { os.Rename(".LinuxPA.old", "LinuxPA") - return false + return false, err } check := http.Client{ CheckRedirect: func(r *http.Request, via []*http.Request) error { @@ -94,13 +94,13 @@ func downloadUpdate(newVersion string) bool { }, } re, err := check.Get(url) - defer re.Body.Close() if err != nil { - return false + return false, err } + defer re.Body.Close() _, err = io.Copy(fil, re.Body) if err != nil { - return false + return false, err } - return true + return true, nil } diff --git a/wine.go b/wine.go new file mode 100644 index 0000000..52c64f8 --- /dev/null +++ b/wine.go @@ -0,0 +1,42 @@ +package main + +import ( + "io" + "net/http" + "os" + + "github.com/mholt/archiver" +) + +const ( + wineURL = "https://www.playonlinux.com/wine/binaries/linux-amd64/PlayOnLinux-wine-2.5-linux-amd64.pol" +) + +func downloadWine() (bool, error) { + wineTar, err := os.Create("PortableApps/LinuxPACom/wine2.5.tar.bz2") + if err != nil { + return false, err + } + wineTar.Chmod(0777) + defer wineTar.Close() + check := http.Client{ + CheckRedirect: func(r *http.Request, via []*http.Request) error { + r.URL.Opaque = r.URL.Path + return nil + }, + } + resp, err := check.Get(wineURL) + if err != nil { + return false, err + } + defer resp.Body.Close() + _, err = io.Copy(wineTar, resp.Body) + if err != nil { + return false, err + } + err = archiver.TarBz2.Open("PortableApps/LinuxPACom/wine2.5.tar.bz2", "PortableApps/LinuxPACom/Wine") + if err != nil { + return false, err + } + return true, nil +}