diff --git a/appimg/Proc.go b/appimg/Proc.go deleted file mode 100644 index d667679..0000000 --- a/appimg/Proc.go +++ /dev/null @@ -1,60 +0,0 @@ -package appimg - -import "reflect" - -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.typ == "a" { - tmp.index[0] = i - tmp.index[1] = j - nd := fndend(tmp, in[j+1:]) - if !reflect.DeepEqual(nd, tag{}) { - tmp.Meat = in[j+1 : nd.index[0]] - out = append(out, tmp) - str := in[tmp.index[1]:nd.index[0]] - in = in[:i] + str + in[nd.index[1]+1:] - } - } - 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{} -} diff --git a/appimg/Tag.go b/appimg/Tag.go deleted file mode 100644 index 7d0a066..0000000 --- a/appimg/Tag.go +++ /dev/null @@ -1,115 +0,0 @@ -package appimg - -import "strings" - -type tag struct { - typ string - end bool - params map[string]string - index [2]int - Meat string -} - -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 - } - } -} diff --git a/appimg/appimg.go b/appimg/appimg.go deleted file mode 100644 index 8ef59be..0000000 --- a/appimg/appimg.go +++ /dev/null @@ -1,13 +0,0 @@ -package appimg - -type appimg struct { - full string - name string - version string -} - -func newApp(name string) appimg { - var out appimg - out.full = name - return out -} diff --git a/appimg/download.go b/appimg/download.go deleted file mode 100644 index cd813c1..0000000 --- a/appimg/download.go +++ /dev/null @@ -1,67 +0,0 @@ -package appimg - -import ( - "fmt" - "io" - "net/http" - "os" - "strings" - - "github.com/gotk3/gotk3/gtk" -) - -func downloadApp(parent *gtk.Window, ap appimg) { - parent.SetSensitive(false) - win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) - win.SetTransientFor(parent) - win.Connect("destroy", func() { - parent.SetSensitive(true) - }) - spn, _ := gtk.SpinnerNew() - spn.Start() - lbl, _ := gtk.LabelNew("Downloading " + ap.full + "...") - box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5) - box.SetMarginStart(10) - box.SetMarginEnd(10) - box.SetMarginTop(10) - box.SetMarginBottom(10) - box.Add(spn) - box.Add(lbl) - win.Add(box) - win.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT) - win.ShowAll() - win.Show() - go func(win *gtk.Window, ap appimg) { - defer win.Close() - check := http.Client{ - CheckRedirect: func(r *http.Request, via []*http.Request) error { - r.URL.Opaque = r.URL.Path - return nil - }, - } - resp, err := check.Get(urlBase + ap.full) - if err != nil { - fmt.Println(err) - return - } - defer resp.Body.Close() - name := strings.Split(ap.full, "-")[0] - var foldName string - if _, err = os.Open("PortableApps/" + name + "Portable"); err == nil { - foldName = "PortableApps/" + name + "Portable" - } else if _, err = os.Open("PortableApps/" + name); err == nil { - foldName = "PortableApps/" + name - } else { - os.Mkdir("PortableApps/"+name+"Portable", 0777) - foldName = "PortableApps/" + name + "Portable" - } - os.Remove(foldName + "/" + ap.full) - fil, err := os.Create(foldName + "/" + ap.full) - if err != nil { - fmt.Println(err) - return - } - io.Copy(fil, resp.Body) - fil.Chmod(0777) - }(win, ap) -} diff --git a/appimg/installui.go b/appimg/installui.go deleted file mode 100644 index 69bbfae..0000000 --- a/appimg/installui.go +++ /dev/null @@ -1,144 +0,0 @@ -//Package appimg is for downloading new AppImages for LinuxPA -package appimg - -import ( - "fmt" - "io/ioutil" - "net/http" - "sort" - "strings" - - "github.com/gotk3/gotk3/glib" - "github.com/gotk3/gotk3/gtk" -) - -const ( - urlBase = "https://dl.bintray.com/probono/AppImages/" -) - -//ShowUI shows the list of possible AppImages to be downloaded in a gtk.Window -func ShowUI(newestVersionOnly bool, clsFunc func()) { - win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) - win.Connect("destroy", func() { - clsFunc() - }) - apps := make([]appimg, 0) - win.SetSizeRequest(400, 400) - box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5) - appList, _ := gtk.ListBoxNew() - apch := make(chan appimg) - appList.SetHExpand(true) - appList.SetVExpand(true) - vScrollCat, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0) - hScrollCat, _ := gtk.AdjustmentNew(0, 0, 0, 0, 0, 0) - lst, _ := gtk.ScrolledWindowNew(hScrollCat, vScrollCat) - lst.SetSizeRequest(170, 500) - lst.Add(appList) - box.Add(lst) - win.Add(box) - appList.Connect("row-activated", func() { - if appList.GetSelectedRow().GetIndex() >= 0 { - downloadApp(win, apps[appList.GetSelectedRow().GetIndex()]) - } - }) - win.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT) - win.ShowAll() - win.Show() - getList(win, apch) - 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 { - glib.IdleAdd(func(list *gtk.ListBox, i appimg) { - lbl, _ := gtk.LabelNew(i.full) - list.Add(lbl) - apps = append(apps, i) - lbl.Show() - }, list, i) - } - } - }(win, apch, appList) -} - -func getList(parent *gtk.Window, apch chan appimg) { - win, _ := gtk.WindowNew(gtk.WINDOW_POPUP) - win.SetTransientFor(parent) - win.SetDestroyWithParent(true) - win.Connect("destroy", func() { - parent.SetSensitive(true) - }) - parent.SetSensitive(false) - spin, _ := gtk.SpinnerNew() - spin.Start() - txt, _ := gtk.LabelNew("Getting List...") - box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5) - box.SetMarginBottom(10) - box.SetMarginEnd(10) - box.SetMarginStart(10) - box.SetMarginTop(10) - box.Add(spin) - box.Add(txt) - win.Add(box) - win.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT) - win.ShowAll() - win.Show() - go func(win *gtk.Window, apch chan appimg) { - check := http.Client{ - CheckRedirect: func(r *http.Request, via []*http.Request) error { - r.URL.Opaque = r.URL.Path - return nil - }, - } - resp, err := check.Get(urlBase) - if err != nil { - fmt.Println(err) - close(apch) - win.Close() - return - } - defer resp.Body.Close() - btys, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Println(err) - close(apch) - win.Close() - return - } - tgs := convert(string(btys)) - for _, v := range tgs { - if strings.HasSuffix(strings.ToLower(v.Meat), ".appimage") { - apch <- newApp(v.Meat) - } - } - close(apch) - win.Close() - }(win, apch) -} diff --git a/appimg/removeLetters.go b/appimg/removeLetters.go deleted file mode 100644 index 4a3b566..0000000 --- a/appimg/removeLetters.go +++ /dev/null @@ -1,12 +0,0 @@ -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 -} diff --git a/appimg/version.go b/appimg/version.go deleted file mode 100644 index 6ac873d..0000000 --- a/appimg/version.go +++ /dev/null @@ -1,33 +0,0 @@ -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 -}