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
+13 -1
View File
@@ -4,6 +4,12 @@ import (
"github.com/nelsam/gxui" "github.com/nelsam/gxui"
"github.com/nelsam/gxui/drivers/gl" "github.com/nelsam/gxui/drivers/gl"
"github.com/nelsam/gxui/themes/dark" "github.com/nelsam/gxui/themes/dark"
"github.com/nelsam/gxui/themes/light"
)
const (
version = "0.1.1.1"
defIni = "[basic]\ntheme=dk"
) )
var ( var (
@@ -15,6 +21,7 @@ var (
lin []string lin []string
wine bool wine bool
comEnbld bool comEnbld bool
darkTheme = true
) )
func main() { func main() {
@@ -25,8 +32,13 @@ func main() {
func appMain(dri gxui.Driver) { func appMain(dri gxui.Driver) {
dr = dri dr = dri
th = dark.CreateTheme(dr)
setup() setup()
if darkTheme {
th = dark.CreateTheme(dr)
} else {
th = light.CreateTheme(dr)
}
th = dark.CreateTheme(dr)
ui() ui()
} }
+31 -1
View File
@@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"fmt"
"image" "image"
"image/draw" "image/draw"
_ "image/png" _ "image/png"
@@ -13,6 +14,8 @@ import (
"github.com/nelsam/gxui" "github.com/nelsam/gxui"
) )
const ()
func setup() { func setup() {
PortableAppsFold, err := os.Open("PortableApps") PortableAppsFold, err := os.Open("PortableApps")
if PAStat, _ := PortableAppsFold.Stat(); err != nil || !PAStat.IsDir() { if PAStat, _ := PortableAppsFold.Stat(); err != nil || !PAStat.IsDir() {
@@ -22,10 +25,37 @@ func setup() {
panic("Can't find PortableApps folder and can't create one!") panic("Can't find PortableApps folder and can't create one!")
} }
} }
if _, err = os.Open("PortableApps/LinuxPACom"); err != nil {
os.Mkdir("PortableApps/LinuxPACom", 0777)
}
fmt.Println(err)
_, err = os.Open("PortableApps/LinuxPACom/common.sh") _, err = os.Open("PortableApps/LinuxPACom/common.sh")
if err == nil { if err == nil {
comEnbld = true comEnbld = true
} }
fi, err := os.Open("PortableApps/LinuxPACom/Info.ini")
if err != nil {
fi, err = os.Create("PortableApps/LinuxPACom/Info.ini")
if err == nil {
wrt := bufio.NewWriter(fi)
wrt.WriteString(defIni)
wrt.Flush()
}
}
if err == nil {
rdr := bufio.NewReader(fi)
for err != nil {
ln, _, error := rdr.ReadLine()
err = error
str := string(ln)
if strings.HasPrefix(str, "theme=") {
str = strings.TrimPrefix(str, "theme=")
if str == "lt" {
darkTheme = false
}
}
}
}
PAFolds, _ := PortableAppsFold.Readdirnames(-1) PAFolds, _ := PortableAppsFold.Readdirnames(-1)
sort.Strings(PAFolds) sort.Strings(PAFolds)
for _, v := range PAFolds { for _, v := range PAFolds {
@@ -86,7 +116,7 @@ func processApp(fold string) (out app) {
btys := make([]byte, 4) btys := make([]byte, 4)
rdr := bufio.NewReader(tmp) rdr := bufio.NewReader(tmp)
rdr.Read(btys) rdr.Read(btys)
if (strings.Contains(strings.ToLower(string(btys)), "elf") && !strings.HasSuffix(strings.ToLower(v), ".so")) || strings.HasPrefix(strings.ToLower(string(btys)), "#!") { if (strings.Contains(strings.ToLower(string(btys)), "elf") && !strings.HasSuffix(strings.ToLower(v), ".so") && !strings.Contains(v, ".so.")) || strings.HasPrefix(strings.ToLower(string(btys)), "#!") {
out.ex = append(out.ex, v) out.ex = append(out.ex, v)
out.lin = append(out.lin, v) out.lin = append(out.lin, v)
} }
+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
}