Wine download finished for later on.

Going to start switching to another GUI library
This commit is contained in:
Belac Darkstorm
2017-04-04 01:23:17 -05:00
parent 9da352a315
commit 844a282fd7
3 changed files with 64 additions and 23 deletions
+5 -6
View File
@@ -31,29 +31,28 @@ var (
func main() { func main() {
updated := false updated := false
os.MkdirAll("PortableApps/LinuxPACom", 0777) os.MkdirAll("PortableApps/LinuxPACom", 0777)
stat := versionDL() stat, err := versionDL()
if stat { if stat {
res := getVersionFileInfo() res := getVersionFileInfo()
if res != "Error!" { if res != "Error!" {
stat = checkForUpdate(res) stat, err = checkForUpdate(res)
if stat { if stat {
downloadUpdate(res) downloadUpdate(res)
updated = true updated = true
} else { } else {
fmt.Println("Failed DL") fmt.Println(err)
} }
} else { } else {
fmt.Println("Failed Version File Info") fmt.Println(err)
} }
} else { } else {
fmt.Println("Failed Version DL") fmt.Println(err)
} }
if updated { if updated {
cmd := exec.Command("./LinuxPA") cmd := exec.Command("./LinuxPA")
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Start() cmd.Start()
fmt.Println("updated!")
} else { } else {
master = make(map[string][]app) master = make(map[string][]app)
linmaster = make(map[string][]app) linmaster = make(map[string][]app)
+17 -17
View File
@@ -2,7 +2,6 @@ package main
import ( import (
"bufio" "bufio"
"fmt"
"io" "io"
"net/http" "net/http"
"os" "os"
@@ -19,10 +18,10 @@ const (
//For some of the code //For some of the code
//Returns if success //Returns if success
func versionDL() bool { func versionDL() (bool, error) {
versionFile, err := os.Create("PortableApps/LinuxPACom/Version") versionFile, err := os.Create("PortableApps/LinuxPACom/Version")
if err != nil { if err != nil {
return false return false, err
} }
versionFile.Chmod(0777) versionFile.Chmod(0777)
check := http.Client{ check := http.Client{
@@ -33,13 +32,13 @@ func versionDL() bool {
} }
response, err := check.Get(versionURL) response, err := check.Get(versionURL)
if err != nil { if err != nil {
return false return false, err
} }
_, err = io.Copy(versionFile, response.Body) _, err = io.Copy(versionFile, response.Body)
if err != nil { if err != nil {
return false return false, err
} }
return true return true, nil
} }
func getVersionFileInfo() string { func getVersionFileInfo() string {
@@ -52,7 +51,7 @@ func getVersionFileInfo() string {
return string(out) return string(out)
} }
func checkForUpdate(new string) bool { func checkForUpdate(new string) (bool, error) {
curSlice := strings.Split(version, ".") curSlice := strings.Split(version, ".")
newSlice := strings.Split(new, ".") newSlice := strings.Split(new, ".")
curNums := make([]int, 4) curNums := make([]int, 4)
@@ -65,27 +64,28 @@ func checkForUpdate(new string) bool {
num, err = strconv.Atoi(newSlice[i]) num, err = strconv.Atoi(newSlice[i])
if err == nil { if err == nil {
newNums[i] = num newNums[i] = num
} else {
return false, err
} }
if newNums[i] > curNums[i] { 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) url := strings.Replace(downloadURL, "XXX", newVersion, -1)
err := os.Rename("LinuxPA", ".LinuxPA.old") err := os.Rename("LinuxPA", ".LinuxPA.old")
if err != nil { if err != nil {
fmt.Println(err) return false, err
return false
} }
fil, err := os.Create("LinuxPA") fil, err := os.Create("LinuxPA")
fil.Chmod(0777) fil.Chmod(0777)
defer fil.Close() defer fil.Close()
if err != nil { if err != nil {
os.Rename(".LinuxPA.old", "LinuxPA") os.Rename(".LinuxPA.old", "LinuxPA")
return false return false, err
} }
check := http.Client{ check := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error { CheckRedirect: func(r *http.Request, via []*http.Request) error {
@@ -94,13 +94,13 @@ func downloadUpdate(newVersion string) bool {
}, },
} }
re, err := check.Get(url) re, err := check.Get(url)
defer re.Body.Close()
if err != nil { if err != nil {
return false return false, err
} }
defer re.Body.Close()
_, err = io.Copy(fil, re.Body) _, err = io.Copy(fil, re.Body)
if err != nil { if err != nil {
return false return false, err
} }
return true return true, nil
} }
+42
View File
@@ -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
}