Getting ready for AppImage downloading

This commit is contained in:
Belac Darkstorm
2017-04-08 20:06:50 -05:00
parent d7410bb88f
commit 01556c1eb0
6 changed files with 236 additions and 27 deletions
+21 -1
View File
@@ -25,10 +25,17 @@ func (a *app) getTreeIter(store *gtk.TreeStore) *gtk.TreeIter {
store.SetValue(it, 0, a.icon) store.SetValue(it, 0, a.icon)
store.SetValue(it, 1, a.name) store.SetValue(it, 1, a.name)
if len(a.ex) > 1 { if len(a.ex) > 1 {
if wine {
for _, v := range a.ex { for _, v := range a.ex {
i := store.Append(it) i := store.Append(it)
store.SetValue(i, 1, v) store.SetValue(i, 1, v)
} }
} else {
for _, v := range a.lin {
i := store.Append(it)
store.SetValue(i, 1, v)
}
}
} }
return it return it
} }
@@ -38,7 +45,11 @@ func (a *app) launch() {
if wine { if wine {
var cmd *exec.Cmd var cmd *exec.Cmd
if !contains(a.lin, a.ex[0]) { if !contains(a.lin, a.ex[0]) {
if comEnbld {
cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; wine \""+a.ex[0]+"\"")
} else {
cmd = exec.Command("/bin/sh", "-c", "cd \""+a.dir+"\"; wine \""+a.ex[0]+"\"") cmd = exec.Command("/bin/sh", "-c", "cd \""+a.dir+"\"; wine \""+a.ex[0]+"\"")
}
} else { } else {
if comEnbld { if comEnbld {
cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; \"./"+a.ex[0]+"\"") cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; \"./"+a.ex[0]+"\"")
@@ -64,7 +75,11 @@ func (a *app) launch() {
if wine { if wine {
var cmd *exec.Cmd var cmd *exec.Cmd
if len(a.lin) == 0 { if len(a.lin) == 0 {
if comEnbld {
cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; wine \""+a.ex[0]+"\"")
} else {
cmd = exec.Command("/bin/sh", "-c", "cd \""+a.dir+"\"; wine \""+a.ex[0]+"\"") cmd = exec.Command("/bin/sh", "-c", "cd \""+a.dir+"\"; wine \""+a.ex[0]+"\"")
}
} else { } else {
var ind int var ind int
for i, v := range a.lin { for i, v := range a.lin {
@@ -109,7 +124,11 @@ func (a *app) launchSub(sub int) {
if wine { if wine {
var cmd *exec.Cmd var cmd *exec.Cmd
if !contains(a.lin, a.ex[sub]) { if !contains(a.lin, a.ex[sub]) {
if comEnbld {
cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; wine \""+a.ex[sub]+"\"")
} else {
cmd = exec.Command("/bin/sh", "-c", "cd \""+a.dir+"\"; wine \""+a.ex[sub]+"\"") cmd = exec.Command("/bin/sh", "-c", "cd \""+a.dir+"\"; wine \""+a.ex[sub]+"\"")
}
} else { } else {
if comEnbld { if comEnbld {
cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; \"./"+a.ex[sub]+"\"") cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; \"./"+a.ex[sub]+"\"")
@@ -120,7 +139,7 @@ func (a *app) launchSub(sub int) {
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.Start() cmd.Start()
} } else {
var cmd *exec.Cmd var cmd *exec.Cmd
if comEnbld { if comEnbld {
cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; \"./"+a.ex[sub]+"\"") cmd = exec.Command("/bin/sh", "-c", ". PortableApps/LinuxPACom/common.sh || exit 1;cd \""+a.dir+"\"; \"./"+a.ex[sub]+"\"")
@@ -131,3 +150,4 @@ func (a *app) launchSub(sub int) {
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.Start() cmd.Start()
} }
}
+60
View File
@@ -0,0 +1,60 @@
//Package appimg is to download and update AppImages for LinuxPA.
//Converted from github.com/CalebQ42/bbConvert
package appimg
import "reflect"
//Convert converts the input string. Only returns <a> tags
func Convert(in string) (out []Tag) {
for i := 0; i < len(in); i++ {
v := in[i]
if v == '<' {
for j := i; j < len(in); j++ {
val := in[j]
if val == '>' {
var tmp Tag
tmp.process(in[i+1 : j+1])
if !tmp.end {
tmp.index[0] = i
tmp.index[1] = j
nd := fndend(tmp, in[j+1:])
if !reflect.DeepEqual(nd, Tag{}) && tmp.typ == "a" {
out = append(out, tmp)
}
}
break
}
}
}
}
return
}
func fndend(fnt Tag, area string) Tag {
var count int
for i, v := range area {
if v == '<' {
for j, val := range area[i:] {
if val == '>' {
var tmp Tag
tmp.process(area[i+1 : i+j+1])
if tmp.typ == fnt.typ {
if tmp.end {
if count == 0 {
tmp.index[0] = fnt.index[1] + 1 + i
tmp.index[1] = fnt.index[1] + j + i + 1
return tmp
}
count--
break
} else {
count++
break
}
}
}
}
}
}
return Tag{}
}
+117
View File
@@ -0,0 +1,117 @@
package appimg
import "strings"
//Tag is a bbCode tag that is properly processed.
type Tag struct {
typ string
end bool
params map[string]string
index [2]int
}
//Value returns the value of a parameter of the bbCode tag. Starting parameters
//is under "starting". Parameter names are always in lowercase
func (t *Tag) Value(param string) string {
return t.params[param]
}
func (t *Tag) setValue(param, value string) {
if t.params == nil {
t.params = make(map[string]string)
}
t.params[strings.TrimSpace(strings.ToLower(param))] = strings.TrimSpace(value)
}
func (t *Tag) process(bbtag string) {
if strings.HasPrefix(bbtag, "/") {
t.end = true
t.typ = strings.ToLower(strings.TrimPrefix(bbtag[:len(bbtag)-1], "/"))
return
}
for i, v := range bbtag {
if v == '=' || v == ' ' || v == '>' {
t.typ = strings.ToLower(bbtag[:i])
switch v {
case '=':
if qt := bbtag[i+1]; qt == '\'' || qt == '"' {
for j := i + 2; j < len(bbtag); j++ {
if bbtag[j] == qt {
t.setValue("starting", bbtag[i+2:j])
bbtag = bbtag[j+1:]
break
} else if bbtag[j] == '>' {
t.setValue("starting", bbtag[i+2:j])
return
}
}
} else {
for j := i + 1; j < len(bbtag); j++ {
if bbtag[j] == '>' {
t.setValue("starting", bbtag[i+1:j])
return
} else if bbtag[j] == ' ' {
t.setValue("starting", bbtag[i+1:j])
bbtag = bbtag[j+1:]
break
}
}
}
case '>':
return
case ' ':
bbtag = bbtag[i:]
}
break
}
}
t.processFurther(bbtag)
}
func (t *Tag) processFurther(further string) {
further = strings.TrimSpace(further)
for i := 0; i < len(further); i++ {
switch further[i] {
case ' ':
t.setValue(strings.ToLower(further[:i]), further[:i])
further = strings.TrimSpace(further[i:])
i = -1
case '=':
if qt := further[i+1]; qt == '\'' || qt == '"' {
outloopqt:
for j := i + 2; j < len(further); j++ {
switch further[j] {
case '>':
t.setValue(strings.ToLower(further[:i]), further[i+2:j])
return
case qt:
t.setValue(strings.ToLower(further[:i]), further[i+2:j])
further = strings.TrimSpace(further[j+1:])
i = -1
break outloopqt
}
}
} else {
outloop:
for j := i + 1; j < len(further); j++ {
switch further[j] {
case '>':
t.setValue(strings.ToLower(further[:i]), further[i+1:j])
return
case ' ':
t.setValue(strings.ToLower(further[:i]), further[i+1:j])
further = strings.TrimSpace(further[j:])
i = -1
break outloop
}
}
}
case '>':
if i != 0 {
t.setValue(strings.ToLower(further[:i]), further[:i])
return
}
return
}
}
}
+8
View File
@@ -22,6 +22,9 @@ func setup() {
} else if err == nil { } else if err == nil {
wineAvail = true wineAvail = true
} }
if !wineAvail {
wine = false
}
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() {
os.Mkdir("PortableApps", 0777) os.Mkdir("PortableApps", 0777)
@@ -119,6 +122,8 @@ func getCat(ini *os.File) string {
if strings.HasPrefix(string(line), "Category=") { if strings.HasPrefix(string(line), "Category=") {
ret = strings.TrimPrefix(string(line), "Category=") ret = strings.TrimPrefix(string(line), "Category=")
break break
} else if strings.HasPrefix(string(line), "category=") {
ret = strings.TrimPrefix(string(line), "category=")
} }
} }
rdr.Reset(ini) rdr.Reset(ini)
@@ -132,6 +137,9 @@ func getName(ini *os.File) string {
if strings.HasPrefix(string(line), "Name=") { if strings.HasPrefix(string(line), "Name=") {
ret = strings.TrimPrefix(string(line), "Name=") ret = strings.TrimPrefix(string(line), "Name=")
break break
} else if strings.HasPrefix(string(line), "name=") {
ret = strings.TrimPrefix(string(line), "name=")
break
} }
} }
rdr.Reset(ini) rdr.Reset(ini)
+9 -5
View File
@@ -1,6 +1,8 @@
package main package main
import ( import (
"fmt"
"github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk" "github.com/gotk3/gotk3/gtk"
) )
@@ -54,14 +56,16 @@ func ui(win *gtk.Window) {
wineCheck.SetSensitive(false) wineCheck.SetSensitive(false)
wineCheck.SetTooltipText("Download wine to run windows apps") wineCheck.SetTooltipText("Download wine to run windows apps")
} }
wineCheck.SetActive(wine)
wineCheck.Connect("toggled", func() { wineCheck.Connect("toggled", func() {
wine = wineCheck.GetActive() wine = wineCheck.GetActive()
for i := range ls { for i := range ls {
catList.Remove(catList.GetRowAtIndex(i)) fmt.Println(len(ls) - i)
catList.Remove(catList.GetRowAtIndex(len(ls) - i - 1))
} }
ls = getCatRows() ls = getCatRows()
for i, v := range ls { for _, v := range ls {
catList.Insert(v, i) catList.Add(v)
} }
catList.ShowAll() catList.ShowAll()
}) })
@@ -69,8 +73,8 @@ func ui(win *gtk.Window) {
topLvl.Add(lrBox) topLvl.Add(lrBox)
topLvl.PackEnd(botBox, false, true, 0) topLvl.PackEnd(botBox, false, true, 0)
win.Add(topLvl) win.Add(topLvl)
for i, v := range ls { for _, v := range ls {
catList.Insert(v, i) catList.Add(v)
} }
catList.Connect("row-selected", func() { catList.Connect("row-selected", func() {
store.Clear() store.Clear()
+8 -8
View File
@@ -19,6 +19,11 @@ const (
func downloadWine(parent *gtk.Window, cb chan bool) { func downloadWine(parent *gtk.Window, cb chan bool) {
win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
win.SetTransientFor(parent) win.SetTransientFor(parent)
win.SetDestroyWithParent(true)
win.Connect("destroy", func() {
parent.SetSensitive(true)
})
parent.SetSensitive(false)
spin, _ := gtk.SpinnerNew() spin, _ := gtk.SpinnerNew()
spin.Start() spin.Start()
txt, _ := gtk.LabelNew("Downloading Wine") txt, _ := gtk.LabelNew("Downloading Wine")
@@ -33,7 +38,7 @@ func downloadWine(parent *gtk.Window, cb chan bool) {
win.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT) win.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
win.ShowAll() win.ShowAll()
win.Show() win.Show()
go func(win *gtk.Window) { go func(win *gtk.Window, txt *gtk.Label) {
defer win.Close() defer win.Close()
wineTar, err := os.Create("PortableApps/LinuxPACom/wine2.5.tar.bz2") wineTar, err := os.Create("PortableApps/LinuxPACom/wine2.5.tar.bz2")
if err != nil { if err != nil {
@@ -41,7 +46,6 @@ func downloadWine(parent *gtk.Window, cb chan bool) {
cb <- false cb <- false
return return
} }
wineTar.Chmod(0777)
defer wineTar.Close() defer wineTar.Close()
check := http.Client{ check := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error { CheckRedirect: func(r *http.Request, via []*http.Request) error {
@@ -55,6 +59,7 @@ func downloadWine(parent *gtk.Window, cb chan bool) {
cb <- false cb <- false
return return
} }
os.RemoveAll("PortableApps/LinuxPACom/Wine")
defer resp.Body.Close() defer resp.Body.Close()
_, err = io.Copy(wineTar, resp.Body) _, err = io.Copy(wineTar, resp.Body)
if err != nil { if err != nil {
@@ -63,14 +68,12 @@ func downloadWine(parent *gtk.Window, cb chan bool) {
return return
} }
txt.SetText("Extracting Wine") txt.SetText("Extracting Wine")
os.RemoveAll("PortableApps/LinuxPACom/Wine")
err = archiver.TarBz2.Open("PortableApps/LinuxPACom/wine2.5.tar.bz2", "PortableApps/LinuxPACom/Wine") err = archiver.TarBz2.Open("PortableApps/LinuxPACom/wine2.5.tar.bz2", "PortableApps/LinuxPACom/Wine")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
cb <- false cb <- false
return return
} }
os.Remove("PortableApps/LinuxPACom/wine2.5.tar.bz2")
fil, err := os.Open("PortableApps/LinuxPACom/common.sh") fil, err := os.Open("PortableApps/LinuxPACom/common.sh")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@@ -83,19 +86,16 @@ func downloadWine(parent *gtk.Window, cb chan bool) {
cb <- false cb <- false
return return
} }
fmt.Println("Hello")
if !strings.Contains(string(tmp), "export PATH=$PWD/PortableApps/LinuxPACom/Wine/wineversion/2.5/bin:$PATH") { if !strings.Contains(string(tmp), "export PATH=$PWD/PortableApps/LinuxPACom/Wine/wineversion/2.5/bin:$PATH") {
tmp = append(tmp, []byte("\nexport PATH=$PWD/PortableApps/LinuxPACom/Wine/wineversion/2.5/bin:$PATH")...) tmp = append(tmp, []byte("\nexport PATH=$PWD/PortableApps/LinuxPACom/Wine/wineversion/2.5/bin:$PATH")...)
ioutil.WriteFile("PortableApps/LinuxPACom/common.sh", tmp, 0777) ioutil.WriteFile("PortableApps/LinuxPACom/common.sh", tmp, 0777)
fmt.Println("Hello2")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
cb <- false cb <- false
return return
} }
} }
fmt.Println("HelloT")
cb <- true cb <- true
return return
}(win) }(win, txt)
} }