From 3111705cae6f79b4e02b64700767da1f83218728 Mon Sep 17 00:00:00 2001 From: Belac Date: Sun, 3 Jun 2018 02:48:40 -0500 Subject: [PATCH] Removed legacy gxui --- gxui (legacy)/main.go | 82 --------------- gxui (legacy)/setup.go | 208 --------------------------------------- gxui (legacy)/strList.go | 65 ------------ gxui (legacy)/ui.go | 66 ------------- 4 files changed, 421 deletions(-) delete mode 100644 gxui (legacy)/main.go delete mode 100644 gxui (legacy)/setup.go delete mode 100644 gxui (legacy)/strList.go delete mode 100644 gxui (legacy)/ui.go diff --git a/gxui (legacy)/main.go b/gxui (legacy)/main.go deleted file mode 100644 index 14cdb34..0000000 --- a/gxui (legacy)/main.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "fmt" - "os" - "os/exec" - - "github.com/nelsam/gxui" - "github.com/nelsam/gxui/drivers/gl" - "github.com/nelsam/gxui/themes/dark" - "github.com/nelsam/gxui/themes/light" -) - -const ( - version = "1.1.0.0" - defIni = "[basic]\ntheme=dk" -) - -var ( - dr gxui.Driver - th gxui.Theme - master map[string][]app - linmaster map[string][]app - cats []string - lin []string - wine bool - comEnbld bool - darkTheme = true -) - -func main() { - updated := false - os.MkdirAll("PortableApps/LinuxPACom", 0777) - stat, err := versionDL() - if stat { - res := getVersionFileInfo() - if res != "Error!" { - stat, err = checkForUpdate(res) - if stat { - downloadUpdate(res) - updated = true - } else { - fmt.Println(err) - } - } else { - fmt.Println("Failed Version File Info") - } - } else { - fmt.Println(err) - } - if updated { - cmd := exec.Command("./LinuxPA") - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Start() - } else { - master = make(map[string][]app) - linmaster = make(map[string][]app) - gl.StartDriver(appMain) - } -} - -func appMain(dri gxui.Driver) { - dr = dri - setup() - if darkTheme { - th = dark.CreateTheme(dr) - } else { - th = light.CreateTheme(dr) - } - th = dark.CreateTheme(dr) - ui() -} - -func contains(arr []string, str string) bool { - for _, v := range arr { - if v == str { - return true - } - } - return false -} diff --git a/gxui (legacy)/setup.go b/gxui (legacy)/setup.go deleted file mode 100644 index 0874dd2..0000000 --- a/gxui (legacy)/setup.go +++ /dev/null @@ -1,208 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "image" - "image/draw" - _ "image/png" - "os" - "reflect" - "sort" - "strings" - - "github.com/nelsam/gxui" -) - -func setup() { - PortableAppsFold, err := os.Open("PortableApps") - if PAStat, _ := PortableAppsFold.Stat(); err != nil || !PAStat.IsDir() { - os.Mkdir("PortableApps", 0777) - PortableAppsFold, err = os.Open("PortableApps") - if err != nil { - 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 { - fold, _ := os.Open("PortableApps/" + v) - if stat, _ := fold.Stat(); stat.IsDir() && stat.Name() != "PortableApps.com" && stat.Name() != "LinuxPACom" { - ap := processApp("PortableApps/" + v) - if !reflect.DeepEqual(ap, app{}) { - if _, ok := master[ap.cat]; !ok { - cats = append(cats, ap.cat) - sort.Strings(cats) - } - if len(ap.lin) != 0 { - if _, ok := linmaster[ap.cat]; !ok { - lin = append(lin, ap.cat) - sort.Strings(lin) - } - } - master[ap.cat] = append(master[ap.cat], ap) - if len(ap.lin) != 0 { - linmaster[ap.cat] = append(linmaster[ap.cat], ap) - } - } - } - } -} - -func processApp(fold string) (out app) { - wd, _ := os.Getwd() - out.dir = wd + "/" + fold - out.ini = findInfo(fold) - if out.ini != nil { - out.name = getName(out.ini) - out.ini = findInfo(fold) - out.cat = getCat(out.ini) - out.ini = findInfo(fold) - } - if out.name == "" { - out.name = strings.TrimPrefix(fold, "PortableApps/") - } - if out.cat == "" { - out.cat = "Other" - } - out.icon = getIcon(fold) - folder, _ := os.Open(fold) - fis, _ := folder.Readdirnames(-1) - for _, v := range fis { - tmp, _ := os.Open(fold + "/" + v) - if stat, _ := tmp.Stat(); stat.IsDir() { - continue - } - if strings.HasSuffix(strings.ToLower(v), ".appimage") { - out.appimg = append(out.appimg, v) - out.ex = append(out.ex, v) - out.lin = append(out.lin, v) - } else if strings.HasSuffix(strings.ToLower(v), ".exe") { - out.ex = append(out.ex, v) - } else { - 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.Contains(v, ".so.")) || strings.HasPrefix(strings.ToLower(string(btys)), "#!") { - out.ex = append(out.ex, v) - out.lin = append(out.lin, v) - } - } - } - if len(out.ex) == 0 { - return app{} - } - if len(out.lin) == 0 { - out.name += " (Wine)" - } - return -} - -func getCat(ini *os.File) string { - rdr := bufio.NewReader(ini) - var ret string - for line, _, err := rdr.ReadLine(); err == nil; line, _, err = rdr.ReadLine() { - if strings.HasPrefix(string(line), "Category=") { - ret = strings.TrimPrefix(string(line), "Category=") - break - } - } - rdr.Reset(ini) - return ret -} - -func getName(ini *os.File) string { - rdr := bufio.NewReader(ini) - var ret string - for line, _, err := rdr.ReadLine(); err == nil; line, _, err = rdr.ReadLine() { - if strings.HasPrefix(string(line), "Name=") { - ret = strings.TrimPrefix(string(line), "Name=") - break - } - } - rdr.Reset(ini) - return ret -} - -func getIcon(fold string) gxui.Texture { - var pic *os.File - if folder, err := os.Open(fold + "/App/AppInfo"); err == nil { - fis, _ := folder.Readdir(-1) - var pics []string - for _, v := range fis { - if !v.IsDir() && strings.HasSuffix(strings.ToLower(v.Name()), ".png") && strings.HasPrefix(strings.ToLower(v.Name()), "appicon_") { - pics = append(pics, v.Name()) - } - } - sort.Strings(pics) - if len(pics) > 1 { - var ind int - if !contains(pics, "appicon_32.png") { - ind = len(pics) - 1 - } else { - ind = sort.SearchStrings(pics, "appicon_32.png") - } - pic, _ = os.Open(fold + "/App/AppInfo/" + pics[ind]) - } - } else if fi, err := os.Open(fold + "/appicon.png"); err == nil { - pic = fi - } else { - return nil - } - img, _, err := image.Decode(pic) - if err != nil { - return nil - } - rgba := image.NewRGBA(img.Bounds()) - draw.Draw(rgba, img.Bounds(), img, image.ZP, draw.Src) - ret := dr.CreateTexture(rgba, 1) - return ret -} - -func findInfo(fold string) *os.File { - tmp, err := os.Open(fold + "/App/AppInfo") - if err == nil { - fis, _ := tmp.Readdirnames(-1) - for _, v := range fis { - if strings.ToLower(v) == "appinfo.ini" { - tmp, _ := os.Open(fold + "/App/AppInfo/" + v) - return tmp - } - } - } - if fi, err := os.Open(fold + "/appinfo.ini"); err == nil { - return fi - } - return nil -} diff --git a/gxui (legacy)/strList.go b/gxui (legacy)/strList.go deleted file mode 100644 index 35a1e19..0000000 --- a/gxui (legacy)/strList.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "github.com/nelsam/gxui" - "github.com/nelsam/gxui/math" -) - -//StrList TODO -type StrList struct { - gxui.AdapterBase - strs []string -} - -//AddString TODO -func (s *StrList) AddString(add string) { - s.strs = append(s.strs, add) - s.DataChanged(false) -} - -//Remove TODO -func (s *StrList) Remove(index int) { - s.strs = append(s.strs[:index], s.strs[index+1:]...) - s.DataChanged(false) -} - -//SetStrings TODO -func (s *StrList) SetStrings(strs []string) { - s.strs = strs - s.DataChanged(false) -} - -//Count TODO -func (s *StrList) Count() int { - return len(s.strs) -} - -//ItemAt TODO -func (s *StrList) ItemAt(index int) gxui.AdapterItem { - return s.strs[index] -} - -//ItemIndex TODO -func (s *StrList) ItemIndex(item gxui.AdapterItem) int { - for i, v := range s.strs { - if v == item { - return i - } - } - return -1 -} - -//Create TODO -func (s *StrList) Create(th gxui.Theme, index int) gxui.Control { - box := th.CreateLinearLayout() - box.SetDirection(gxui.LeftToRight) - lbl := th.CreateLabel() - lbl.SetText(s.strs[index]) - box.AddChild(lbl) - return box -} - -//Size TODO -func (s *StrList) Size(gxui.Theme) math.Size { - return math.Size{W: math.MaxSize.W, H: 20} -} diff --git a/gxui (legacy)/ui.go b/gxui (legacy)/ui.go deleted file mode 100644 index 8c83a87..0000000 --- a/gxui (legacy)/ui.go +++ /dev/null @@ -1,66 +0,0 @@ -package main - -import ( - "os" - "os/exec" - - "github.com/nelsam/gxui" -) - -func ui() { - catListAdap := &StrList{} - appListAdap := &catAdap{} - catListAdap.SetStrings(lin) - win := th.CreateWindow(500, 500, "LinuxPA") - top := th.CreateLinearLayout() - top.SetDirection(gxui.BottomToTop) - splBox := th.CreateLinearLayout() - spl := th.CreateSplitterLayout() - spl.SetOrientation(gxui.Horizontal) - catList := th.CreateList() - catList.SetAdapter(catListAdap) - catList.OnSelectionChanged(func(it gxui.AdapterItem) { - appListAdap.setCat(it.(string)) - }) - appList := th.CreateTree() - appList.SetAdapter(appListAdap) - spl.AddChild(catList) - spl.AddChild(appList) - splBox.AddChild(spl) - butBox := th.CreateLinearLayout() - butBox.SetDirection(gxui.LeftToRight) - if _, err := exec.LookPath("wine"); err == nil { - wineBut := th.CreateButton() - wineBut.SetType(gxui.ToggleButton) - wineBut.SetChecked(wine) - wineBut.SetText("Show Windows Apps") - wineBut.OnClick(func(gxui.MouseEvent) { - wine = wineBut.IsChecked() - appListAdap.refresh() - if wineBut.IsChecked() { - catListAdap.SetStrings(cats) - wineBut.SetText("Hide Windows Apps") - } else { - catListAdap.SetStrings(lin) - wineBut.SetText("Show Windows Apps") - } - }) - _, err := os.Open("Start.exe") - if err == nil { - pa := th.CreateButton() - pa.SetText("Open PortableApps Launcher") - pa.OnClick(func(gxui.MouseEvent) { - cmd := exec.Command("wine", "Start.exe") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Start() - }) - butBox.AddChild(pa) - } - butBox.AddChild(wineBut) - } - top.AddChild(butBox) - top.AddChild(splBox) - win.AddChild(top) - win.OnClose(dr.Terminate) -}