".fap" extention in file browser and archive tab (#1812)
* Add .fap extention, and Applications tab * Using new icon, renaming tab to Apps * Change tabs order * Add first ugly implementation of in-app icons in archive browser * Starting using FAPLoader callback * Getting all metafata from fap * add app filename fallback * using fap_loader_item_callback in archive_list_item_cb * FAP-Loader: removed minimal allocation * Removed strange code Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include "gui/modules/file_browser_worker.h"
|
||||
#include <fap_loader/fap_loader_app.h>
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
@@ -351,16 +352,32 @@ void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
|
||||
ArchiveFile_t_clear(&item);
|
||||
}
|
||||
|
||||
static bool archive_get_fap_meta(FuriString* file_path, FuriString* fap_name, uint8_t** icon_ptr) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
bool success = false;
|
||||
if(fap_loader_load_name_and_icon(file_path, storage, icon_ptr, fap_name)) {
|
||||
success = true;
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return success;
|
||||
}
|
||||
|
||||
void archive_add_file_item(ArchiveBrowserView* browser, bool is_folder, const char* name) {
|
||||
furi_assert(browser);
|
||||
furi_assert(name);
|
||||
|
||||
ArchiveFile_t item;
|
||||
|
||||
ArchiveFile_t_init(&item);
|
||||
item.path = furi_string_alloc_set(name);
|
||||
archive_set_file_type(&item, furi_string_get_cstr(browser->path), is_folder, false);
|
||||
|
||||
furi_string_set(item.path, name);
|
||||
archive_set_file_type(&item, furi_string_get_cstr(browser->path), is_folder, false);
|
||||
if(item.type == ArchiveFileTypeApplication) {
|
||||
item.custom_icon_data = malloc(FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
if(!archive_get_fap_meta(item.path, item.custom_name, &item.custom_icon_data)) {
|
||||
free(item.custom_icon_data);
|
||||
item.custom_icon_data = NULL;
|
||||
}
|
||||
}
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_push_back(model->files, item);
|
||||
|
@@ -16,6 +16,7 @@ static const char* tab_default_paths[] = {
|
||||
[ArchiveTabInfrared] = ANY_PATH("infrared"),
|
||||
[ArchiveTabBadUsb] = ANY_PATH("badusb"),
|
||||
[ArchiveTabU2f] = "/app:u2f",
|
||||
[ArchiveTabApplications] = ANY_PATH("apps"),
|
||||
[ArchiveTabBrowser] = STORAGE_ANY_PATH_PREFIX,
|
||||
};
|
||||
|
||||
@@ -27,6 +28,7 @@ static const char* known_ext[] = {
|
||||
[ArchiveFileTypeInfrared] = ".ir",
|
||||
[ArchiveFileTypeBadUsb] = ".txt",
|
||||
[ArchiveFileTypeU2f] = "?",
|
||||
[ArchiveFileTypeApplication] = ".fap",
|
||||
[ArchiveFileTypeUpdateManifest] = ".fuf",
|
||||
[ArchiveFileTypeFolder] = "?",
|
||||
[ArchiveFileTypeUnknown] = "*",
|
||||
@@ -41,6 +43,7 @@ static const ArchiveFileTypeEnum known_type[] = {
|
||||
[ArchiveTabInfrared] = ArchiveFileTypeInfrared,
|
||||
[ArchiveTabBadUsb] = ArchiveFileTypeBadUsb,
|
||||
[ArchiveTabU2f] = ArchiveFileTypeU2f,
|
||||
[ArchiveTabApplications] = ArchiveFileTypeApplication,
|
||||
[ArchiveTabBrowser] = ArchiveFileTypeUnknown,
|
||||
};
|
||||
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <furi.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#define FAP_MANIFEST_MAX_ICON_SIZE 32
|
||||
|
||||
typedef enum {
|
||||
ArchiveFileTypeIButton,
|
||||
ArchiveFileTypeNFC,
|
||||
@@ -13,6 +15,7 @@ typedef enum {
|
||||
ArchiveFileTypeBadUsb,
|
||||
ArchiveFileTypeU2f,
|
||||
ArchiveFileTypeUpdateManifest,
|
||||
ArchiveFileTypeApplication,
|
||||
ArchiveFileTypeFolder,
|
||||
ArchiveFileTypeUnknown,
|
||||
ArchiveFileTypeLoading,
|
||||
@@ -21,33 +24,56 @@ typedef enum {
|
||||
typedef struct {
|
||||
FuriString* path;
|
||||
ArchiveFileTypeEnum type;
|
||||
uint8_t* custom_icon_data;
|
||||
FuriString* custom_name;
|
||||
bool fav;
|
||||
bool is_app;
|
||||
} ArchiveFile_t;
|
||||
|
||||
static void ArchiveFile_t_init(ArchiveFile_t* obj) {
|
||||
obj->type = ArchiveFileTypeUnknown;
|
||||
obj->is_app = false;
|
||||
obj->fav = false;
|
||||
obj->path = furi_string_alloc();
|
||||
obj->type = ArchiveFileTypeUnknown;
|
||||
obj->custom_icon_data = NULL;
|
||||
obj->custom_name = furi_string_alloc();
|
||||
obj->fav = false;
|
||||
obj->is_app = false;
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_init_set(ArchiveFile_t* obj, const ArchiveFile_t* src) {
|
||||
obj->type = src->type;
|
||||
obj->is_app = src->is_app;
|
||||
obj->fav = src->fav;
|
||||
obj->path = furi_string_alloc_set(src->path);
|
||||
obj->type = src->type;
|
||||
if(src->custom_icon_data) {
|
||||
obj->custom_icon_data = malloc(FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
memcpy(obj->custom_icon_data, src->custom_icon_data, FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
} else {
|
||||
obj->custom_icon_data = NULL;
|
||||
}
|
||||
obj->custom_name = furi_string_alloc_set(src->custom_name);
|
||||
obj->fav = src->fav;
|
||||
obj->is_app = src->is_app;
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_set(ArchiveFile_t* obj, const ArchiveFile_t* src) {
|
||||
obj->type = src->type;
|
||||
obj->is_app = src->is_app;
|
||||
obj->fav = src->fav;
|
||||
furi_string_set(obj->path, src->path);
|
||||
obj->type = src->type;
|
||||
if(src->custom_icon_data) {
|
||||
obj->custom_icon_data = malloc(FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
memcpy(obj->custom_icon_data, src->custom_icon_data, FAP_MANIFEST_MAX_ICON_SIZE);
|
||||
} else {
|
||||
obj->custom_icon_data = NULL;
|
||||
}
|
||||
furi_string_set(obj->custom_name, src->custom_name);
|
||||
obj->fav = src->fav;
|
||||
obj->is_app = src->is_app;
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_clear(ArchiveFile_t* obj) {
|
||||
furi_string_free(obj->path);
|
||||
if(obj->custom_icon_data) {
|
||||
free(obj->custom_icon_data);
|
||||
obj->custom_icon_data = NULL;
|
||||
}
|
||||
furi_string_free(obj->custom_name);
|
||||
}
|
||||
|
||||
ARRAY_DEF(
|
||||
|
Reference in New Issue
Block a user