From 8441a8b752b836b55f9e20d96179741f94e6c7f9 Mon Sep 17 00:00:00 2001 From: Belac Darkstorm Date: Mon, 3 Apr 2017 08:23:25 -0500 Subject: [PATCH] Working on an auto-update mechanism --- main.go | 14 +++++++++++++- setup.go | 32 +++++++++++++++++++++++++++++++- update.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 update.go diff --git a/main.go b/main.go index 47f1791..535e6ee 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,12 @@ import ( "github.com/nelsam/gxui" "github.com/nelsam/gxui/drivers/gl" "github.com/nelsam/gxui/themes/dark" + "github.com/nelsam/gxui/themes/light" +) + +const ( + version = "0.1.1.1" + defIni = "[basic]\ntheme=dk" ) var ( @@ -15,6 +21,7 @@ var ( lin []string wine bool comEnbld bool + darkTheme = true ) func main() { @@ -25,8 +32,13 @@ func main() { func appMain(dri gxui.Driver) { dr = dri - th = dark.CreateTheme(dr) setup() + if darkTheme { + th = dark.CreateTheme(dr) + } else { + th = light.CreateTheme(dr) + } + th = dark.CreateTheme(dr) ui() } diff --git a/setup.go b/setup.go index 76f9bec..8290ad2 100644 --- a/setup.go +++ b/setup.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "fmt" "image" "image/draw" _ "image/png" @@ -13,6 +14,8 @@ import ( "github.com/nelsam/gxui" ) +const () + func setup() { PortableAppsFold, err := os.Open("PortableApps") 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!") } } + if _, err = os.Open("PortableApps/LinuxPACom"); err != nil { + os.Mkdir("PortableApps/LinuxPACom", 0777) + } + fmt.Println(err) _, err = os.Open("PortableApps/LinuxPACom/common.sh") if err == nil { 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) sort.Strings(PAFolds) for _, v := range PAFolds { @@ -86,7 +116,7 @@ func processApp(fold string) (out app) { btys := make([]byte, 4) rdr := bufio.NewReader(tmp) 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.lin = append(out.lin, v) } diff --git a/update.go b/update.go new file mode 100644 index 0000000..d413201 --- /dev/null +++ b/update.go @@ -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 +}