Ready to test then bug fix :)
Also, I'm ALIVE!!!!
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user