Better download list parsing
This commit is contained in:
+3
-1
@@ -1,11 +1,13 @@
|
|||||||
package appimg
|
package appimg
|
||||||
|
|
||||||
type appimg struct {
|
type appimg struct {
|
||||||
|
full string
|
||||||
name string
|
name string
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApp(name string) appimg {
|
func newApp(name string) appimg {
|
||||||
var out appimg
|
var out appimg
|
||||||
out.name = name
|
out.full = name
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-5
@@ -19,7 +19,7 @@ func downloadApp(parent *gtk.Window, ap appimg) {
|
|||||||
})
|
})
|
||||||
spn, _ := gtk.SpinnerNew()
|
spn, _ := gtk.SpinnerNew()
|
||||||
spn.Start()
|
spn.Start()
|
||||||
lbl, _ := gtk.LabelNew("Downloading " + ap.name + "...")
|
lbl, _ := gtk.LabelNew("Downloading " + ap.full + "...")
|
||||||
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5)
|
box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5)
|
||||||
box.SetMarginStart(10)
|
box.SetMarginStart(10)
|
||||||
box.SetMarginEnd(10)
|
box.SetMarginEnd(10)
|
||||||
@@ -39,13 +39,13 @@ func downloadApp(parent *gtk.Window, ap appimg) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resp, err := check.Get(urlBase + ap.name)
|
resp, err := check.Get(urlBase + ap.full)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
name := strings.Split(ap.name, "-")[0]
|
name := strings.Split(ap.full, "-")[0]
|
||||||
var foldName string
|
var foldName string
|
||||||
if _, err = os.Open("PortableApps/" + name + "Portable"); err == nil {
|
if _, err = os.Open("PortableApps/" + name + "Portable"); err == nil {
|
||||||
foldName = "PortableApps/" + name + "Portable"
|
foldName = "PortableApps/" + name + "Portable"
|
||||||
@@ -55,12 +55,13 @@ func downloadApp(parent *gtk.Window, ap appimg) {
|
|||||||
os.Mkdir("PortableApps/"+name+"Portable", 0777)
|
os.Mkdir("PortableApps/"+name+"Portable", 0777)
|
||||||
foldName = "PortableApps/" + name
|
foldName = "PortableApps/" + name
|
||||||
}
|
}
|
||||||
fil, err := os.Create(foldName + "/" + ap.name)
|
os.Remove(foldName + "/" + ap.full)
|
||||||
|
fil, err := os.Create(foldName + "/" + ap.full)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
io.Copy(fil, resp.Body)
|
io.Copy(fil, resp.Body)
|
||||||
_ = fil.Chmod(0777)
|
fil.Chmod(0777)
|
||||||
}(win, ap)
|
}(win, ap)
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-2
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gotk3/gotk3/glib"
|
"github.com/gotk3/gotk3/glib"
|
||||||
@@ -16,7 +17,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//ShowUI shows the list of possible AppImages to be downloaded in a gtk.Window
|
//ShowUI shows the list of possible AppImages to be downloaded in a gtk.Window
|
||||||
func ShowUI(clsFunc func()) {
|
func ShowUI(newestVersionOnly bool, clsFunc func()) {
|
||||||
win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
|
win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
|
||||||
win.Connect("destroy", func() {
|
win.Connect("destroy", func() {
|
||||||
clsFunc()
|
clsFunc()
|
||||||
@@ -45,14 +46,45 @@ func ShowUI(clsFunc func()) {
|
|||||||
win.Show()
|
win.Show()
|
||||||
getList(win, apch)
|
getList(win, apch)
|
||||||
go func(win *gtk.Window, apch chan appimg, list *gtk.ListBox) {
|
go func(win *gtk.Window, apch chan appimg, list *gtk.ListBox) {
|
||||||
|
if newestVersionOnly {
|
||||||
|
imgs := make([]appimg, 0)
|
||||||
|
a := make(map[string][]appimg)
|
||||||
|
names := make([]string, 0)
|
||||||
|
for i := range apch {
|
||||||
|
imgs = append(imgs, i)
|
||||||
|
}
|
||||||
|
for i, v := range imgs {
|
||||||
|
sp := strings.Split(v.full, "-")
|
||||||
|
if len(sp) >= 2 {
|
||||||
|
vers := sp[1]
|
||||||
|
removeLetters(vers)
|
||||||
|
imgs[i].version = vers
|
||||||
|
imgs[i].name = sp[0]
|
||||||
|
if _, ok := a[imgs[i].name]; !ok {
|
||||||
|
names = append(names, imgs[i].name)
|
||||||
|
}
|
||||||
|
a[imgs[i].name] = append(a[imgs[i].name], imgs[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(names)
|
||||||
|
for _, name := range names {
|
||||||
|
glib.IdleAdd(func(name string, list *gtk.ListBox, i appimg) {
|
||||||
|
lbl, _ := gtk.LabelNew(name)
|
||||||
|
list.Add(lbl)
|
||||||
|
apps = append(apps, i)
|
||||||
|
lbl.Show()
|
||||||
|
}, name, list, a[name][compareVersions(a[name])])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for i := range apch {
|
for i := range apch {
|
||||||
glib.IdleAdd(func(list *gtk.ListBox, i appimg) {
|
glib.IdleAdd(func(list *gtk.ListBox, i appimg) {
|
||||||
lbl, _ := gtk.LabelNew(i.name)
|
lbl, _ := gtk.LabelNew(i.full)
|
||||||
list.Add(lbl)
|
list.Add(lbl)
|
||||||
apps = append(apps, i)
|
apps = append(apps, i)
|
||||||
lbl.Show()
|
lbl.Show()
|
||||||
}, list, i)
|
}, list, i)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}(win, apch, appList)
|
}(win, apch, appList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package appimg
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func removeLetters(vers string) string {
|
||||||
|
vers = strings.ToLower(vers)
|
||||||
|
letters := []string{"abcdefghijklmnopqrstuvwxyz"}
|
||||||
|
for _, v := range letters {
|
||||||
|
vers = strings.Replace(vers, v, "", -1)
|
||||||
|
}
|
||||||
|
return vers
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package appimg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func compareVersions(imgs []appimg) int {
|
||||||
|
for i := range imgs {
|
||||||
|
imgs[i].version = removeLetters(imgs[i].version)
|
||||||
|
}
|
||||||
|
highest := 0
|
||||||
|
higharr := strings.Split(imgs[0].version, ".")
|
||||||
|
for i := 0; i < len(imgs); i++ {
|
||||||
|
if i != highest {
|
||||||
|
varr := strings.Split(imgs[i].version, ".")
|
||||||
|
if len(higharr) < len(varr) {
|
||||||
|
for j := 0; j < len(higharr); j++ {
|
||||||
|
h, _ := strconv.Atoi(higharr[j])
|
||||||
|
c, _ := strconv.Atoi(varr[j])
|
||||||
|
if h > c {
|
||||||
|
break
|
||||||
|
} else if c > h {
|
||||||
|
highest = i
|
||||||
|
higharr = varr
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highest
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "2.1.0.5"
|
version = "2.1.1.0"
|
||||||
defIni = ""
|
defIni = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ var (
|
|||||||
comEnbld bool
|
comEnbld bool
|
||||||
wineAvail bool
|
wineAvail bool
|
||||||
portableHide bool
|
portableHide bool
|
||||||
|
versionNewest = true
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -53,16 +54,24 @@ func uiStart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func savePrefs() {
|
func savePrefs() {
|
||||||
fil, err := os.Open("PortableApps/LinuxPACom/Prefs.gob")
|
os.Remove("PortableApps/LinuxPACom/Prefs.gob")
|
||||||
if os.IsNotExist(err) {
|
fil, err := os.Create("PortableApps/LinuxPACom/Prefs.gob")
|
||||||
fil, err = os.Create("PortableApps/LinuxPACom/Prefs.gob")
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
enc := gob.NewEncoder(fil)
|
enc := gob.NewEncoder(fil)
|
||||||
enc.Encode(wine)
|
err = enc.Encode(wine)
|
||||||
enc.Encode(portableHide)
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = enc.Encode(portableHide)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = enc.Encode(versionNewest)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadPrefs() {
|
func loadPrefs() {
|
||||||
@@ -71,8 +80,18 @@ func loadPrefs() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
dec := gob.NewDecoder(fil)
|
dec := gob.NewDecoder(fil)
|
||||||
dec.Decode(&wine)
|
err = dec.Decode(&wine)
|
||||||
dec.Decode(&portableHide)
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = dec.Decode(&portableHide)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = dec.Decode(&versionNewest)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(arr []string, str string) bool {
|
func contains(arr []string, str string) bool {
|
||||||
|
|||||||
+26
-2
@@ -3,7 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/gotk3/gotk3/glib"
|
||||||
"github.com/gotk3/gotk3/gtk"
|
"github.com/gotk3/gotk3/gtk"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ func settingsUI(parent *gtk.Window, onExit func()) {
|
|||||||
gnrl.SetMarginTop(10)
|
gnrl.SetMarginTop(10)
|
||||||
gnrl.SetMarginBottom(10)
|
gnrl.SetMarginBottom(10)
|
||||||
dlWine, _ := gtk.ButtonNewWithLabel("Download Wine")
|
dlWine, _ := gtk.ButtonNewWithLabel("Download Wine")
|
||||||
|
wineCheck, _ := gtk.CheckButtonNewWithLabel("Show Windows apps (Wine)")
|
||||||
wineLbl, _ := gtk.LabelNew("PortableApps/LinuxPACom/Wine present")
|
wineLbl, _ := gtk.LabelNew("PortableApps/LinuxPACom/Wine present")
|
||||||
dlWine.Connect("clicked", func() {
|
dlWine.Connect("clicked", func() {
|
||||||
cb := make(chan bool)
|
cb := make(chan bool)
|
||||||
@@ -36,6 +39,22 @@ func settingsUI(parent *gtk.Window, onExit func()) {
|
|||||||
setupTxt(comBuf)
|
setupTxt(comBuf)
|
||||||
wineLbl.Show()
|
wineLbl.Show()
|
||||||
}
|
}
|
||||||
|
if _, err := os.Open("PortableApps/LinuxPACom/Wine"); os.IsNotExist(err) {
|
||||||
|
if _, errd := exec.LookPath("wine"); errd == nil {
|
||||||
|
wineAvail = true
|
||||||
|
}
|
||||||
|
} else if err == nil {
|
||||||
|
wineAvail = true
|
||||||
|
}
|
||||||
|
glib.IdleAdd(func() {
|
||||||
|
if !wineAvail {
|
||||||
|
wineCheck.SetSensitive(false)
|
||||||
|
wineCheck.SetTooltipText("Download wine to run windows apps")
|
||||||
|
} else {
|
||||||
|
wineCheck.SetSensitive(true)
|
||||||
|
wineCheck.SetTooltipText("")
|
||||||
|
}
|
||||||
|
})
|
||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
if !comEnbld {
|
if !comEnbld {
|
||||||
@@ -51,7 +70,7 @@ func settingsUI(parent *gtk.Window, onExit func()) {
|
|||||||
lin = make([]string, 0)
|
lin = make([]string, 0)
|
||||||
setup()
|
setup()
|
||||||
})
|
})
|
||||||
wineCheck, _ := gtk.CheckButtonNewWithLabel("Show Windows apps (Wine)")
|
pthdCheck.SetActive(portableHide)
|
||||||
if !wineAvail {
|
if !wineAvail {
|
||||||
wineCheck.SetSensitive(false)
|
wineCheck.SetSensitive(false)
|
||||||
wineCheck.SetTooltipText("Download wine to run windows apps")
|
wineCheck.SetTooltipText("Download wine to run windows apps")
|
||||||
@@ -60,11 +79,16 @@ func settingsUI(parent *gtk.Window, onExit func()) {
|
|||||||
wineCheck.Connect("toggled", func() {
|
wineCheck.Connect("toggled", func() {
|
||||||
wine = wineCheck.GetActive()
|
wine = wineCheck.GetActive()
|
||||||
})
|
})
|
||||||
pthdCheck.SetActive(portableHide)
|
versCheck, _ := gtk.CheckButtonNewWithLabel("Only show newest app version in downloads (A bit iffy ATM)")
|
||||||
|
versCheck.SetActive(versionNewest)
|
||||||
|
versCheck.Connect("toggled", func() {
|
||||||
|
versionNewest = versCheck.GetActive()
|
||||||
|
})
|
||||||
gnrl.Add(wineLbl)
|
gnrl.Add(wineLbl)
|
||||||
gnrl.Add(dlWine)
|
gnrl.Add(dlWine)
|
||||||
gnrl.Add(pthdCheck)
|
gnrl.Add(pthdCheck)
|
||||||
gnrl.Add(wineCheck)
|
gnrl.Add(wineCheck)
|
||||||
|
gnrl.Add(versCheck)
|
||||||
ntbk.AppendPage(gnrl, getLabel("General"))
|
ntbk.AppendPage(gnrl, getLabel("General"))
|
||||||
com, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5)
|
com, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5)
|
||||||
com.SetMarginStart(10)
|
com.SetMarginStart(10)
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func ui(win *gtk.Window) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
dnl.Connect("clicked", func() {
|
dnl.Connect("clicked", func() {
|
||||||
appimg.ShowUI(func() {
|
appimg.ShowUI(versionNewest, func() {
|
||||||
master = make(map[string][]app)
|
master = make(map[string][]app)
|
||||||
linmaster = make(map[string][]app)
|
linmaster = make(map[string][]app)
|
||||||
cats = make([]string, 0)
|
cats = make([]string, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user