diff --git a/appimg/CTesting.go b/appimg/CTesting.go deleted file mode 100644 index 364bd3a..0000000 --- a/appimg/CTesting.go +++ /dev/null @@ -1,79 +0,0 @@ -package appimg - -// Thanks to probono for the majority of this C code: https://discourse.appimage.org/t/accessing-appimage-desktop-file/173/4?u=calebq42 - -/* -#cgo CFLAGS: -I/usr/lib -#cgo LDFLAGS: -L/usr/lib/libappimage.so -lappimage - -#include -#include - -int char_length(char** in){ - int i = 0; - for (; in[i] != NULL ; i++); - return i; -} -*/ -import "C" -import ( - "errors" - "os" - "strings" - "unsafe" -) - -var ( - //ErrNotAppImage return if the given location does not point to an AppImage - ErrNotAppImage = errors.New("file is not an appimage") -) - -//Thanks to https://stackoverflow.com/questions/36188649/cgo-char-to-slice-string for char** to string slice code :) - -//GetDesktopFile tries to find the desktop file inside the appimage at appimageLoc and extract it to extractLoc. -//extractLoc is deleted first to provent conflicts. -func GetDesktopFile(appimageLoc string, extractLoc string) (*os.File, error) { - if !strings.HasSuffix(appimageLoc, ".AppImage") { - return nil, ErrNotAppImage - } - err := os.Remove(extractLoc) - if err != os.ErrNotExist { - return nil, err - } - cextractLoc := C.CString(extractLoc) - defer C.free(unsafe.Pointer(cextractLoc)) - cloc := C.CString(appimageLoc) - defer C.free(unsafe.Pointer(cloc)) - cfiles := C.appimage_list_files(cloc) - defer C.appimage_string_list_free(cfiles) - cfilesLength := C.char_length(cfiles) - tmpslice := (*[1 << 30]*C.char)(unsafe.Pointer(cfiles))[:cfilesLength:cfilesLength] - for _, v := range tmpslice { - tmp := C.GoString(v) - if strings.HasSuffix(tmp, ".desktop") { - C.appimage_extract_file_following_symlinks(cloc, v, cextractLoc) - break - } - } - return os.Open(extractLoc) -} - -//ExtractFile tries to extract the file at fileLoc to extractLoc from the appimage at appimageLoc. -//extractLoc is deleted first to provent conflicts. -func ExtractFile(appimageLoc string, fileLoc string, extractLoc string) (*os.File, error) { - if !strings.HasSuffix(appimageLoc, ".AppImage") { - return nil, ErrNotAppImage - } - err := os.Remove(extractLoc) - if err != os.ErrNotExist { - return nil, err - } - cextractLoc := C.CString(extractLoc) - defer C.free(unsafe.Pointer(cextractLoc)) - cloc := C.CString(appimageLoc) - defer C.free(unsafe.Pointer(cloc)) - cfileLoc := C.CString(fileLoc) - defer C.free(unsafe.Pointer(cfileLoc)) - C.appimage_extract_file_following_symlinks(cloc, cfileLoc, cextractLoc) - return os.Open(extractLoc) -} diff --git a/main.go b/main.go index 8366ce1..bfc2c5a 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "encoding/gob" "flag" "fmt" "os" @@ -14,17 +13,12 @@ const ( ) var ( - master map[string][]app - linmaster map[string][]app - cats []string - lin []string - wine bool - comEnbld bool - wineAvail bool - portableHide bool - betaUpdate bool - versionNewest = true - paDirs = true + master map[string][]app + linmaster map[string][]app + cats []string + lin []string + comEnbld bool + populated bool ) func main() { @@ -57,63 +51,6 @@ func uiStart(forced bool) { gtk.Main() } -func savePrefs() { - os.Remove("PortableApps/LinuxPACom/Prefs.gob") - fil, err := os.Create("PortableApps/LinuxPACom/Prefs.gob") - if err != nil { - return - } - enc := gob.NewEncoder(fil) - err = enc.Encode(wine) - if err != nil { - return - } - err = enc.Encode(portableHide) - if err != nil { - return - } - err = enc.Encode(versionNewest) - if err != nil { - return - } - err = enc.Encode(paDirs) - if err != nil { - return - } - err = enc.Encode(betaUpdate) - if err != nil { - return - } -} - -func loadPrefs() { - fil, err := os.Open("PortableApps/LinuxPACom/Prefs.gob") - if err != nil { - return - } - dec := gob.NewDecoder(fil) - err = dec.Decode(&wine) - if err != nil { - return - } - err = dec.Decode(&portableHide) - if err != nil { - return - } - err = dec.Decode(&versionNewest) - if err != nil { - return - } - err = dec.Decode(&paDirs) - if err != nil { - return - } - err = dec.Decode(&betaUpdate) - if err != nil { - return - } -} - func contains(arr []string, str string) bool { for _, v := range arr { if v == str { diff --git a/preferences.go b/preferences.go new file mode 100644 index 0000000..2729980 --- /dev/null +++ b/preferences.go @@ -0,0 +1,72 @@ +package main + +import ( + "encoding/gob" + "os" +) + +var ( + wine bool + wineAvail bool + portableHide bool + betaUpdate bool + versionNewest = true + paDirs = true +) + +func savePrefs() { + os.Remove("PortableApps/LinuxPACom/Prefs.gob") + fil, err := os.Create("PortableApps/LinuxPACom/Prefs.gob") + if err != nil { + return + } + enc := gob.NewEncoder(fil) + err = enc.Encode(wine) + if err != nil { + return + } + err = enc.Encode(portableHide) + if err != nil { + return + } + err = enc.Encode(versionNewest) + if err != nil { + return + } + err = enc.Encode(paDirs) + if err != nil { + return + } + err = enc.Encode(betaUpdate) + if err != nil { + return + } +} + +func loadPrefs() { + fil, err := os.Open("PortableApps/LinuxPACom/Prefs.gob") + if err != nil { + return + } + dec := gob.NewDecoder(fil) + err = dec.Decode(&wine) + if err != nil { + return + } + err = dec.Decode(&portableHide) + if err != nil { + return + } + err = dec.Decode(&versionNewest) + if err != nil { + return + } + err = dec.Decode(&paDirs) + if err != nil { + return + } + err = dec.Decode(&betaUpdate) + if err != nil { + return + } +} diff --git a/setup.go b/setup.go index e03c56f..fd2c3ce 100644 --- a/setup.go +++ b/setup.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "encoding/json" _ "image/png" "os" "os/exec" @@ -9,6 +10,7 @@ import ( "sort" "strings" + "github.com/CalebQ42/GoAppImage" "github.com/gotk3/gotk3/gdk" "github.com/gotk3/gotk3/gtk" ) @@ -64,28 +66,12 @@ func setup() { } } } + populated = true } 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" - } - if portableHide { - out.name = strings.TrimSuffix(out.name, "Portable") - } - out.icon = getIcon(fold) folder, _ := os.Open(fold) fis, _ := folder.Readdirnames(-1) for _, v := range fis { @@ -116,6 +102,36 @@ func processApp(fold string) (out app) { out.name += " (Wine)" out.wine = true } + out.icon = getIcon(fold) + if len(out.appimg) > 0 { + os.Mkdir(out.dir+"/.appimageconfig", 0777) + fil, err := os.Open(out.dir + "/.appimageconfig/info.json") + if err == os.ErrNotExist { + fil, _ = os.Create(out.dir + "/.appimageconfig/info.json") + ai := goappimage.NewAppImage(out.dir + "/" + out.appimg[0]) + ai.ExtractDesktop(out.dir + "/.appimageconfig/the.desktop") + //extract desktop and parse info then send to json + //also md5 so when updating happens it can update the desktop file + ai.Free() + } else { + //decode json, check if desktop needs to be updated + } + //Parse extracted desktop file + } + out.ini = findInfo(fold) + if out.ini != nil { + out.name = getName(out.ini) + out.cat = getCat(out.ini) + } + if out.name == "" { + out.name = strings.TrimPrefix(fold, "PortableApps/") + } + if out.cat == "" { + out.cat = "Other" + } + if portableHide { + out.name = strings.TrimSuffix(out.name, "Portable") + } return }