Ready to test then bug fix :)

Also, I'm ALIVE!!!!
This commit is contained in:
Belac Darkstorm
2017-04-03 09:17:49 -05:00
parent 8441a8b752
commit 5d5cedec58
2 changed files with 72 additions and 8 deletions
+70 -5
View File
@@ -1,17 +1,18 @@
package main
import (
"bufio"
"fmt"
"io"
"net/http"
"os"
)
var (
updateNeeded = false
"strconv"
"strings"
)
const (
versionURL = "https://www.dropbox.com/s/a0xizzo0a4vsfqt/Version?dl=1"
versionURL = "https://www.dropbox.com/s/a0xizzo0a4vsfqt/Version?dl=1"
downloadURL = "https://github.com/CalebQ42/LinuxPA/releases/download/vXXX/LinuxPA"
)
//Thanks to https://www.socketloop.com/tutorials/golang-download-file-example
@@ -26,6 +27,7 @@ func versionDL() bool {
return false
}
}
defer versionFile.Close()
check := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
@@ -33,6 +35,7 @@ func versionDL() bool {
},
}
response, err := check.Get(versionURL)
defer response.Body.Close()
if err != nil {
return false
}
@@ -42,3 +45,65 @@ func versionDL() bool {
}
return true
}
func getVersionFileInfo() string {
fil, err := os.Open("PortableApps/LinuxPACom/Version")
if err != nil {
return "Error!"
}
rdr := bufio.NewReader(fil)
out, _, _ := rdr.ReadLine()
return string(out)
}
func checkForUpdate(cur string, new string) bool {
curSlice := strings.Split(cur, ".")
newSlice := strings.Split(new, ".")
curNums := make([]int, 4)
newNums := make([]int, 4)
for i, v := range curSlice {
num, err := strconv.Atoi(v)
if err == nil {
curNums[i] = num
}
num, err = strconv.Atoi(newSlice[i])
if err == nil {
newNums[i] = num
}
if newNums[i] > curNums[i] {
return true
}
}
return false
}
func downloadUpdate(newVersion string) bool {
url := strings.Replace(downloadURL, "XXX", newVersion, -1)
err := os.Rename("LinuxPA", ".LinuxPA.old")
if err != nil {
fmt.Println(err)
return false
}
fil, err := os.Create("LinuxPA")
defer fil.Close()
if err != nil {
os.Rename(".LinuxPA.old", "LinuxPA")
return false
}
check := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
}
re, err := check.Get(url)
defer re.Body.Close()
if err != nil {
return false
}
_, err = io.Copy(fil, re.Body)
if err != nil {
return false
}
return true
}