Finished work on AppImage desktop file extraction
This commit is contained in:
+56
-55
@@ -5,74 +5,75 @@ package appimg
|
|||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -I/usr/lib
|
#cgo CFLAGS: -I/usr/lib
|
||||||
#cgo LDFLAGS: -L/usr/lib/libappimage.so -lappimage
|
#cgo LDFLAGS: -L/usr/lib/libappimage.so -lappimage
|
||||||
#cgo pkg-config: glib-2.0
|
|
||||||
|
|
||||||
#include <appimage/appimage.h>
|
#include <appimage/appimage.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <glib.h>
|
|
||||||
#include <strings.h>
|
|
||||||
|
|
||||||
bool extract_desktop(char* appimageLoc,char* extractLoc){
|
int char_length(char** in){
|
||||||
char** files = appimage_list_files(appimageLoc);
|
|
||||||
g_autofree gchar *desktop_file = NULL;
|
|
||||||
gchar *extracted_desktop_file = extractLoc;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; files[i] != NULL ; i++) {
|
for (; in[i] != NULL ; i++);
|
||||||
// g_debug("AppImage file: %s", files[i]);
|
return i;
|
||||||
if (g_str_has_suffix (files[i],".desktop")) {
|
|
||||||
desktop_file = files[i];
|
|
||||||
g_debug("AppImage desktop file: %s", desktop_file);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(desktop_file == NULL) {
|
|
||||||
g_debug("AppImage desktop file not found");
|
|
||||||
appimage_string_list_free(files);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
appimage_extract_file_following_symlinks(appimageLoc, desktop_file,extracted_desktop_file);
|
|
||||||
appimage_string_list_free(files);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool extract_file(char* appimageLoc,char* filename,char* extractLoc){
|
|
||||||
char** files = appimage_list_files(appimageLoc);
|
|
||||||
g_autofree gchar *found_file = NULL;
|
|
||||||
gchar *extracted_file = extractLoc;
|
|
||||||
int i = 0;
|
|
||||||
for (; files[i] != NULL ; i++) {
|
|
||||||
g_debug("AppImage file: %s", files[i]);
|
|
||||||
if (strcmp(files[i],filename)==0) {
|
|
||||||
found_file = files[i];
|
|
||||||
g_debug("FileFound: %s", found_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(found_file == NULL) {
|
|
||||||
g_debug("filenotfound");
|
|
||||||
appimage_string_list_free(files);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
appimage_extract_file_following_symlinks(appimageLoc, found_file,extracted_file);
|
|
||||||
appimage_string_list_free(files);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDesktopFile(loc string) (*os.File, error) {
|
var (
|
||||||
os.Remove("/tmp/my.desktop")
|
//ErrNotAppImage return if the given location does not point to an AppImage
|
||||||
var locTmp *C.char = C.CString(loc)
|
ErrNotAppImage = errors.New("file is not an appimage")
|
||||||
defer C.free(unsafe.Pointer(locTmp))
|
)
|
||||||
var extractLoc *C.char = C.CString("/tmp/my.desktop")
|
|
||||||
defer C.free(unsafe.Pointer(extractLoc))
|
//Thanks to https://stackoverflow.com/questions/36188649/cgo-char-to-slice-string for char** to string slice code :)
|
||||||
var out C.bool = C.extract_desktop(locTmp, extractLoc)
|
|
||||||
if out == false {
|
//GetDesktopFile tries to find the desktop file inside the appimage at appimageLoc and extract it to extractLoc.
|
||||||
return nil, errors.New("Desktop File Not Found!")
|
//extractLoc is deleted first to provent conflicts.
|
||||||
|
func GetDesktopFile(appimageLoc string, extractLoc string) (*os.File, error) {
|
||||||
|
if !strings.HasSuffix(appimageLoc, ".AppImage") {
|
||||||
|
return nil, ErrNotAppImage
|
||||||
}
|
}
|
||||||
return os.Open("/tmp/my.desktop")
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/CalebQ42/LinuxPA/appimg"
|
||||||
|
|
||||||
"github.com/gotk3/gotk3/gtk"
|
"github.com/gotk3/gotk3/gtk"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "2.1.4.0"
|
version = "2.1.4.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -28,12 +29,18 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
forced := flag.Bool("force-update", false, "Force the update dialog to be shown")
|
_, err := appimg.GetDesktopFile("gimp.AppImage")
|
||||||
flag.Parse()
|
if err == nil {
|
||||||
os.MkdirAll("PortableApps/LinuxPACom", 0777)
|
os.Rename("/tmp/my.desktop", "PortableApps/stuff.desktop")
|
||||||
master = make(map[string][]app)
|
} else {
|
||||||
linmaster = make(map[string][]app)
|
println("error:", err)
|
||||||
uiStart(*forced)
|
}
|
||||||
|
// forced := flag.Bool("force-update", false, "Force the update dialog to be shown")
|
||||||
|
// flag.Parse()
|
||||||
|
// os.MkdirAll("PortableApps/LinuxPACom", 0777)
|
||||||
|
// master = make(map[string][]app)
|
||||||
|
// linmaster = make(map[string][]app)
|
||||||
|
// uiStart(*forced)
|
||||||
}
|
}
|
||||||
|
|
||||||
func uiStart(forced bool) {
|
func uiStart(forced bool) {
|
||||||
|
|||||||
Reference in New Issue
Block a user