Working on an auto-update mechanism

This commit is contained in:
Belac Darkstorm
2017-04-03 08:23:25 -05:00
parent d64d88e0a5
commit 8441a8b752
3 changed files with 88 additions and 2 deletions
+44
View File
@@ -0,0 +1,44 @@
package main
import (
"io"
"net/http"
"os"
)
var (
updateNeeded = false
)
const (
versionURL = "https://www.dropbox.com/s/a0xizzo0a4vsfqt/Version?dl=1"
)
//Thanks to https://www.socketloop.com/tutorials/golang-download-file-example
//For some of the code
//Returns if success
func versionDL() bool {
versionFile, err := os.Open("PortableApps/LinuxPACom/Version")
if err != nil {
versionFile, err = os.Create("PortableApps/LinuxPACom/Version")
if err != nil {
return false
}
}
check := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
}
response, err := check.Get(versionURL)
if err != nil {
return false
}
_, err = io.Copy(versionFile, response.Body)
if err != nil {
return false
}
return true
}