[FL-2627] Flipper applications: SDK, build and debug system (#1387)
* Added support for running applications from SD card (FAPs - Flipper Application Packages) * Added plugin_dist target for fbt to build FAPs * All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default * Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them * Added debugging support for FAPs with fbt debug & VSCode * Added public firmware API with automated versioning Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
84
applications/main/archive/helpers/archive_apps.c
Normal file
84
applications/main/archive/helpers/archive_apps.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "archive_files.h"
|
||||
#include "archive_apps.h"
|
||||
#include "archive_browser.h"
|
||||
|
||||
static const char* known_apps[] = {
|
||||
[ArchiveAppTypeU2f] = "u2f",
|
||||
};
|
||||
|
||||
ArchiveAppTypeEnum archive_get_app_type(const char* path) {
|
||||
const char* app_name = strchr(path, ':');
|
||||
if(app_name == NULL) {
|
||||
return ArchiveAppTypeUnknown;
|
||||
}
|
||||
app_name++;
|
||||
|
||||
for(size_t i = 0; i < COUNT_OF(known_apps); i++) {
|
||||
if(strncmp(app_name, known_apps[i], strlen(known_apps[i])) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return ArchiveAppTypeUnknown;
|
||||
}
|
||||
|
||||
bool archive_app_is_available(void* context, const char* path) {
|
||||
UNUSED(context);
|
||||
furi_assert(path);
|
||||
|
||||
ArchiveAppTypeEnum app = archive_get_app_type(path);
|
||||
|
||||
if(app == ArchiveAppTypeU2f) {
|
||||
bool file_exists = false;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
if(storage_file_exists(storage, ANY_PATH("u2f/key.u2f"))) {
|
||||
file_exists = storage_file_exists(storage, ANY_PATH("u2f/cnt.u2f"));
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return file_exists;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool archive_app_read_dir(void* context, const char* path) {
|
||||
furi_assert(context);
|
||||
furi_assert(path);
|
||||
ArchiveBrowserView* browser = context;
|
||||
|
||||
archive_file_array_rm_all(browser);
|
||||
|
||||
ArchiveAppTypeEnum app = archive_get_app_type(path);
|
||||
|
||||
if(app == ArchiveAppTypeU2f) {
|
||||
archive_add_app_item(browser, "/app:u2f/U2F Token");
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void archive_app_delete_file(void* context, const char* path) {
|
||||
furi_assert(context);
|
||||
furi_assert(path);
|
||||
ArchiveBrowserView* browser = context;
|
||||
|
||||
ArchiveAppTypeEnum app = archive_get_app_type(path);
|
||||
bool res = false;
|
||||
|
||||
if(app == ArchiveAppTypeU2f) {
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
res = (storage_common_remove(fs_api, ANY_PATH("u2f/key.u2f")) == FSE_OK);
|
||||
res |= (storage_common_remove(fs_api, ANY_PATH("u2f/cnt.u2f")) == FSE_OK);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(archive_is_favorite("/app:u2f/U2F Token")) {
|
||||
archive_favorites_delete("/app:u2f/U2F Token");
|
||||
}
|
||||
}
|
||||
|
||||
if(res) {
|
||||
archive_file_array_rm_selected(browser);
|
||||
}
|
||||
}
|
21
applications/main/archive/helpers/archive_apps.h
Normal file
21
applications/main/archive/helpers/archive_apps.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
ArchiveAppTypeU2f,
|
||||
ArchiveAppTypeUnknown,
|
||||
ArchiveAppsTotal,
|
||||
} ArchiveAppTypeEnum;
|
||||
|
||||
static const ArchiveFileTypeEnum app_file_types[] = {
|
||||
[ArchiveAppTypeU2f] = ArchiveFileTypeU2f,
|
||||
[ArchiveAppTypeUnknown] = ArchiveFileTypeUnknown,
|
||||
};
|
||||
|
||||
static inline ArchiveFileTypeEnum archive_get_app_filetype(ArchiveAppTypeEnum app) {
|
||||
return app_file_types[app];
|
||||
}
|
||||
|
||||
ArchiveAppTypeEnum archive_get_app_type(const char* path);
|
||||
bool archive_app_is_available(void* context, const char* path);
|
||||
bool archive_app_read_dir(void* context, const char* path);
|
||||
void archive_app_delete_file(void* context, const char* path);
|
506
applications/main/archive/helpers/archive_browser.c
Normal file
506
applications/main/archive/helpers/archive_browser.c
Normal file
@@ -0,0 +1,506 @@
|
||||
#include <archive/views/archive_browser_view.h>
|
||||
#include "archive_files.h"
|
||||
#include "archive_apps.h"
|
||||
#include "archive_browser.h"
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include "gui/modules/file_browser_worker.h"
|
||||
#include "m-string.h"
|
||||
#include <math.h>
|
||||
|
||||
static void
|
||||
archive_folder_open_cb(void* context, uint32_t item_cnt, int32_t file_idx, bool is_root) {
|
||||
furi_assert(context);
|
||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||
|
||||
int32_t load_offset = 0;
|
||||
browser->is_root = is_root;
|
||||
ArchiveTabEnum tab = archive_get_tab(browser);
|
||||
|
||||
if((item_cnt == 0) && (archive_is_home(browser)) && (tab != ArchiveTabBrowser)) {
|
||||
archive_switch_tab(browser, browser->last_tab_switch_dir);
|
||||
} else if(!string_start_with_str_p(browser->path, "/app:")) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_reset(model->files);
|
||||
model->item_cnt = item_cnt;
|
||||
model->item_idx = (file_idx > 0) ? file_idx : 0;
|
||||
load_offset =
|
||||
CLAMP(model->item_idx - FILE_LIST_BUF_LEN / 2, (int32_t)model->item_cnt, 0);
|
||||
model->array_offset = 0;
|
||||
model->list_offset = 0;
|
||||
model->list_loading = true;
|
||||
model->folder_loading = false;
|
||||
return false;
|
||||
});
|
||||
archive_update_offset(browser);
|
||||
|
||||
file_browser_worker_load(browser->worker, load_offset, FILE_LIST_BUF_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
static void archive_list_load_cb(void* context, uint32_t list_load_offset) {
|
||||
furi_assert(context);
|
||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_reset(model->files);
|
||||
model->array_offset = list_load_offset;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
static void archive_list_item_cb(void* context, string_t item_path, bool is_folder, bool is_last) {
|
||||
furi_assert(context);
|
||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||
|
||||
if(!is_last) {
|
||||
archive_add_file_item(browser, is_folder, string_get_cstr(item_path));
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->list_loading = false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void archive_long_load_cb(void* context) {
|
||||
furi_assert(context);
|
||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->folder_loading = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static void archive_file_browser_set_path(
|
||||
ArchiveBrowserView* browser,
|
||||
string_t path,
|
||||
const char* filter_ext,
|
||||
bool skip_assets) {
|
||||
furi_assert(browser);
|
||||
if(!browser->worker_running) {
|
||||
browser->worker = file_browser_worker_alloc(path, filter_ext, skip_assets);
|
||||
file_browser_worker_set_callback_context(browser->worker, browser);
|
||||
file_browser_worker_set_folder_callback(browser->worker, archive_folder_open_cb);
|
||||
file_browser_worker_set_list_callback(browser->worker, archive_list_load_cb);
|
||||
file_browser_worker_set_item_callback(browser->worker, archive_list_item_cb);
|
||||
file_browser_worker_set_long_load_callback(browser->worker, archive_long_load_cb);
|
||||
browser->worker_running = true;
|
||||
} else {
|
||||
furi_assert(browser->worker);
|
||||
file_browser_worker_set_config(browser->worker, path, filter_ext, skip_assets);
|
||||
}
|
||||
}
|
||||
|
||||
bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx) {
|
||||
size_t array_size = files_array_size(model->files);
|
||||
|
||||
if((idx >= (uint32_t)model->array_offset + array_size) ||
|
||||
(idx < (uint32_t)model->array_offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void archive_update_offset(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
uint16_t bounds = model->item_cnt > 3 ? 2 : model->item_cnt;
|
||||
|
||||
if((model->item_cnt > 3u) && (model->item_idx >= ((int32_t)model->item_cnt - 1))) {
|
||||
model->list_offset = model->item_idx - 3;
|
||||
} else if(model->list_offset < model->item_idx - bounds) {
|
||||
model->list_offset =
|
||||
CLAMP(model->item_idx - 2, (int32_t)model->item_cnt - bounds, 0);
|
||||
} else if(model->list_offset > model->item_idx - bounds) {
|
||||
model->list_offset =
|
||||
CLAMP(model->item_idx - 1, (int32_t)model->item_cnt - bounds, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
||||
furi_assert(browser);
|
||||
furi_assert(target);
|
||||
|
||||
archive_get_items(browser, string_get_cstr(browser->path));
|
||||
|
||||
if(!archive_file_get_array_size(browser) && archive_is_home(browser)) {
|
||||
archive_switch_tab(browser, TAB_RIGHT);
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
uint16_t idx = 0;
|
||||
while(idx < files_array_size(model->files)) {
|
||||
ArchiveFile_t* current = files_array_get(model->files, idx);
|
||||
if(!string_search(current->path, target)) {
|
||||
model->item_idx = idx + model->array_offset;
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
}
|
||||
|
||||
size_t archive_file_get_array_size(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
uint16_t size = 0;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
size = files_array_size(model->files);
|
||||
return false;
|
||||
});
|
||||
return size;
|
||||
}
|
||||
|
||||
void archive_set_item_count(ArchiveBrowserView* browser, uint32_t count) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->item_cnt = count;
|
||||
model->item_idx = CLAMP(model->item_idx, (int32_t)model->item_cnt - 1, 0);
|
||||
return false;
|
||||
});
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
|
||||
void archive_file_array_rm_selected(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
uint32_t items_cnt = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_remove_v(
|
||||
model->files,
|
||||
model->item_idx - model->array_offset,
|
||||
model->item_idx - model->array_offset + 1);
|
||||
model->item_cnt--;
|
||||
model->item_idx = CLAMP(model->item_idx, (int32_t)model->item_cnt - 1, 0);
|
||||
items_cnt = model->item_cnt;
|
||||
return false;
|
||||
});
|
||||
|
||||
if((items_cnt == 0) && (archive_is_home(browser))) {
|
||||
archive_switch_tab(browser, TAB_RIGHT);
|
||||
}
|
||||
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
|
||||
void archive_file_array_swap(ArchiveBrowserView* browser, int8_t dir) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
ArchiveFile_t temp;
|
||||
size_t array_size = files_array_size(model->files) - 1;
|
||||
uint8_t swap_idx = CLAMP((size_t)(model->item_idx + dir), array_size, 0u);
|
||||
|
||||
if(model->item_idx == 0 && dir < 0) {
|
||||
ArchiveFile_t_init(&temp);
|
||||
files_array_pop_at(&temp, model->files, array_size);
|
||||
files_array_push_at(model->files, model->item_idx, temp);
|
||||
ArchiveFile_t_clear(&temp);
|
||||
} else if(((uint32_t)model->item_idx == array_size) && (dir > 0)) {
|
||||
ArchiveFile_t_init(&temp);
|
||||
files_array_pop_at(&temp, model->files, 0);
|
||||
files_array_push_at(model->files, array_size, temp);
|
||||
ArchiveFile_t_clear(&temp);
|
||||
} else {
|
||||
files_array_swap_at(model->files, model->item_idx, swap_idx);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void archive_file_array_rm_all(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_reset(model->files);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void archive_file_array_load(ArchiveBrowserView* browser, int8_t dir) {
|
||||
furi_assert(browser);
|
||||
|
||||
int32_t offset_new = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
if(model->item_cnt > FILE_LIST_BUF_LEN) {
|
||||
if(dir < 0) {
|
||||
offset_new = model->item_idx - FILE_LIST_BUF_LEN / 4 * 3;
|
||||
} else if(dir == 0) {
|
||||
offset_new = model->item_idx - FILE_LIST_BUF_LEN / 4 * 2;
|
||||
} else {
|
||||
offset_new = model->item_idx - FILE_LIST_BUF_LEN / 4 * 1;
|
||||
}
|
||||
if(offset_new > 0) {
|
||||
offset_new =
|
||||
CLAMP(offset_new, (int32_t)model->item_cnt - FILE_LIST_BUF_LEN, 0);
|
||||
} else {
|
||||
offset_new = 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
file_browser_worker_load(browser->worker, offset_new, FILE_LIST_BUF_LEN);
|
||||
}
|
||||
|
||||
ArchiveFile_t* archive_get_current_file(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
ArchiveFile_t* selected;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
selected = files_array_size(model->files) ?
|
||||
files_array_get(model->files, model->item_idx - model->array_offset) :
|
||||
NULL;
|
||||
return false;
|
||||
});
|
||||
return selected;
|
||||
}
|
||||
|
||||
ArchiveFile_t* archive_get_file_at(ArchiveBrowserView* browser, size_t idx) {
|
||||
furi_assert(browser);
|
||||
|
||||
ArchiveFile_t* selected;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
idx = CLAMP(idx - model->array_offset, files_array_size(model->files), 0u);
|
||||
selected = files_array_size(model->files) ? files_array_get(model->files, idx) : NULL;
|
||||
return false;
|
||||
});
|
||||
return selected;
|
||||
}
|
||||
|
||||
ArchiveTabEnum archive_get_tab(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
ArchiveTabEnum tab_id;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
tab_id = model->tab_idx;
|
||||
return false;
|
||||
});
|
||||
return tab_id;
|
||||
}
|
||||
|
||||
bool archive_is_home(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
if(browser->is_root) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* default_path = archive_get_default_path(archive_get_tab(browser));
|
||||
return (string_cmp_str(browser->path, default_path) == 0);
|
||||
}
|
||||
|
||||
const char* archive_get_name(ArchiveBrowserView* browser) {
|
||||
ArchiveFile_t* selected = archive_get_current_file(browser);
|
||||
return string_get_cstr(selected->path);
|
||||
}
|
||||
|
||||
void archive_set_tab(ArchiveBrowserView* browser, ArchiveTabEnum tab) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->tab_idx = tab;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
|
||||
furi_assert(browser);
|
||||
furi_assert(name);
|
||||
|
||||
ArchiveFile_t item;
|
||||
ArchiveFile_t_init(&item);
|
||||
string_set_str(item.path, name);
|
||||
archive_set_file_type(&item, name, false, true);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_push_back(model->files, item);
|
||||
model->item_cnt = files_array_size(model->files);
|
||||
return false;
|
||||
});
|
||||
ArchiveFile_t_clear(&item);
|
||||
}
|
||||
|
||||
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);
|
||||
string_init_set_str(item.path, name);
|
||||
archive_set_file_type(&item, string_get_cstr(browser->path), is_folder, false);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_push_back(model->files, item);
|
||||
return false;
|
||||
});
|
||||
ArchiveFile_t_clear(&item);
|
||||
}
|
||||
|
||||
void archive_show_file_menu(ArchiveBrowserView* browser, bool show) {
|
||||
furi_assert(browser);
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
if(show) {
|
||||
if(archive_is_item_in_array(model, model->item_idx)) {
|
||||
model->menu = true;
|
||||
model->menu_idx = 0;
|
||||
ArchiveFile_t* selected =
|
||||
files_array_get(model->files, model->item_idx - model->array_offset);
|
||||
selected->fav = archive_is_favorite("%s", string_get_cstr(selected->path));
|
||||
}
|
||||
} else {
|
||||
model->menu = false;
|
||||
model->menu_idx = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->move_fav = active;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static bool archive_is_dir_exists(string_t path) {
|
||||
if(string_equal_str_p(path, STORAGE_ANY_PATH_PREFIX)) {
|
||||
return true;
|
||||
}
|
||||
bool state = false;
|
||||
FileInfo file_info;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if(file_info.flags & FSF_DIRECTORY) {
|
||||
state = true;
|
||||
}
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return state;
|
||||
}
|
||||
|
||||
void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
|
||||
furi_assert(browser);
|
||||
ArchiveTabEnum tab = archive_get_tab(browser);
|
||||
|
||||
browser->last_tab_switch_dir = key;
|
||||
|
||||
if(key == InputKeyLeft) {
|
||||
tab = ((tab - 1) + ArchiveTabTotal) % ArchiveTabTotal;
|
||||
} else {
|
||||
tab = (tab + 1) % ArchiveTabTotal;
|
||||
}
|
||||
|
||||
browser->is_root = true;
|
||||
archive_set_tab(browser, tab);
|
||||
|
||||
string_set_str(browser->path, archive_get_default_path(tab));
|
||||
bool tab_empty = true;
|
||||
if(tab == ArchiveTabFavorites) {
|
||||
if(archive_favorites_count(browser) > 0) {
|
||||
tab_empty = false;
|
||||
}
|
||||
} else if(string_start_with_str_p(browser->path, "/app:")) {
|
||||
char* app_name = strchr(string_get_cstr(browser->path), ':');
|
||||
if(app_name != NULL) {
|
||||
if(archive_app_is_available(browser, string_get_cstr(browser->path))) {
|
||||
tab_empty = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tab = archive_get_tab(browser);
|
||||
if(archive_is_dir_exists(browser->path)) {
|
||||
bool skip_assets = (strcmp(archive_get_tab_ext(tab), "*") == 0) ? false : true;
|
||||
archive_file_browser_set_path(
|
||||
browser, browser->path, archive_get_tab_ext(tab), skip_assets);
|
||||
tab_empty = false; // Empty check will be performed later
|
||||
} else {
|
||||
tab_empty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if((tab_empty) && (tab != ArchiveTabBrowser)) {
|
||||
archive_switch_tab(browser, key);
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->item_idx = 0;
|
||||
model->array_offset = 0;
|
||||
return false;
|
||||
});
|
||||
archive_get_items(browser, string_get_cstr(browser->path));
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
}
|
||||
|
||||
void archive_enter_dir(ArchiveBrowserView* browser, string_t path) {
|
||||
furi_assert(browser);
|
||||
furi_assert(path);
|
||||
|
||||
int32_t idx_temp = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
idx_temp = model->item_idx;
|
||||
return false;
|
||||
});
|
||||
|
||||
string_set(browser->path, path);
|
||||
file_browser_worker_folder_enter(browser->worker, path, idx_temp);
|
||||
}
|
||||
|
||||
void archive_leave_dir(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
file_browser_worker_folder_exit(browser->worker);
|
||||
}
|
||||
|
||||
void archive_refresh_dir(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
int32_t idx_temp = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
idx_temp = model->item_idx;
|
||||
return false;
|
||||
});
|
||||
file_browser_worker_folder_refresh(browser->worker, idx_temp);
|
||||
}
|
89
applications/main/archive/helpers/archive_browser.h
Normal file
89
applications/main/archive/helpers/archive_browser.h
Normal file
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include "../archive_i.h"
|
||||
#include <storage/storage.h>
|
||||
|
||||
#define TAB_RIGHT InputKeyRight // Default tab swith direction
|
||||
#define TAB_DEFAULT ArchiveTabFavorites // Start tab
|
||||
#define FILE_LIST_BUF_LEN 100
|
||||
|
||||
static const char* tab_default_paths[] = {
|
||||
[ArchiveTabFavorites] = "/app:favorites",
|
||||
[ArchiveTabIButton] = ANY_PATH("ibutton"),
|
||||
[ArchiveTabNFC] = ANY_PATH("nfc"),
|
||||
[ArchiveTabSubGhz] = ANY_PATH("subghz"),
|
||||
[ArchiveTabLFRFID] = ANY_PATH("lfrfid"),
|
||||
[ArchiveTabInfrared] = ANY_PATH("infrared"),
|
||||
[ArchiveTabBadUsb] = ANY_PATH("badusb"),
|
||||
[ArchiveTabU2f] = "/app:u2f",
|
||||
[ArchiveTabBrowser] = STORAGE_ANY_PATH_PREFIX,
|
||||
};
|
||||
|
||||
static const char* known_ext[] = {
|
||||
[ArchiveFileTypeIButton] = ".ibtn",
|
||||
[ArchiveFileTypeNFC] = ".nfc",
|
||||
[ArchiveFileTypeSubGhz] = ".sub",
|
||||
[ArchiveFileTypeLFRFID] = ".rfid",
|
||||
[ArchiveFileTypeInfrared] = ".ir",
|
||||
[ArchiveFileTypeBadUsb] = ".txt",
|
||||
[ArchiveFileTypeU2f] = "?",
|
||||
[ArchiveFileTypeUpdateManifest] = ".fuf",
|
||||
[ArchiveFileTypeFolder] = "?",
|
||||
[ArchiveFileTypeUnknown] = "*",
|
||||
};
|
||||
|
||||
static const ArchiveFileTypeEnum known_type[] = {
|
||||
[ArchiveTabFavorites] = ArchiveFileTypeUnknown,
|
||||
[ArchiveTabIButton] = ArchiveFileTypeIButton,
|
||||
[ArchiveTabNFC] = ArchiveFileTypeNFC,
|
||||
[ArchiveTabSubGhz] = ArchiveFileTypeSubGhz,
|
||||
[ArchiveTabLFRFID] = ArchiveFileTypeLFRFID,
|
||||
[ArchiveTabInfrared] = ArchiveFileTypeInfrared,
|
||||
[ArchiveTabBadUsb] = ArchiveFileTypeBadUsb,
|
||||
[ArchiveTabU2f] = ArchiveFileTypeU2f,
|
||||
[ArchiveTabBrowser] = ArchiveFileTypeUnknown,
|
||||
};
|
||||
|
||||
static inline ArchiveFileTypeEnum archive_get_tab_filetype(ArchiveTabEnum tab) {
|
||||
return known_type[tab];
|
||||
}
|
||||
|
||||
static inline const char* archive_get_tab_ext(ArchiveTabEnum tab) {
|
||||
return known_ext[archive_get_tab_filetype(tab)];
|
||||
}
|
||||
|
||||
static inline const char* archive_get_default_path(ArchiveTabEnum tab) {
|
||||
return tab_default_paths[tab];
|
||||
}
|
||||
|
||||
inline bool archive_is_known_app(ArchiveFileTypeEnum type) {
|
||||
return (type != ArchiveFileTypeFolder && type != ArchiveFileTypeUnknown);
|
||||
}
|
||||
|
||||
bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx);
|
||||
void archive_update_offset(ArchiveBrowserView* browser);
|
||||
void archive_update_focus(ArchiveBrowserView* browser, const char* target);
|
||||
|
||||
void archive_file_array_load(ArchiveBrowserView* browser, int8_t dir);
|
||||
size_t archive_file_get_array_size(ArchiveBrowserView* browser);
|
||||
void archive_file_array_rm_selected(ArchiveBrowserView* browser);
|
||||
void archive_file_array_swap(ArchiveBrowserView* browser, int8_t dir);
|
||||
void archive_file_array_rm_all(ArchiveBrowserView* browser);
|
||||
|
||||
void archive_set_item_count(ArchiveBrowserView* browser, uint32_t count);
|
||||
|
||||
ArchiveFile_t* archive_get_current_file(ArchiveBrowserView* browser);
|
||||
ArchiveFile_t* archive_get_file_at(ArchiveBrowserView* browser, size_t idx);
|
||||
ArchiveTabEnum archive_get_tab(ArchiveBrowserView* browser);
|
||||
bool archive_is_home(ArchiveBrowserView* browser);
|
||||
const char* archive_get_name(ArchiveBrowserView* browser);
|
||||
|
||||
void archive_add_app_item(ArchiveBrowserView* browser, const char* name);
|
||||
void archive_add_file_item(ArchiveBrowserView* browser, bool is_folder, const char* name);
|
||||
void archive_show_file_menu(ArchiveBrowserView* browser, bool show);
|
||||
void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active);
|
||||
|
||||
void archive_switch_tab(ArchiveBrowserView* browser, InputKey key);
|
||||
void archive_enter_dir(ArchiveBrowserView* browser, string_t name);
|
||||
void archive_leave_dir(ArchiveBrowserView* browser);
|
||||
void archive_refresh_dir(ArchiveBrowserView* browser);
|
337
applications/main/archive/helpers/archive_favorites.c
Normal file
337
applications/main/archive/helpers/archive_favorites.c
Normal file
@@ -0,0 +1,337 @@
|
||||
|
||||
#include "archive_favorites.h"
|
||||
#include "archive_files.h"
|
||||
#include "archive_apps.h"
|
||||
#include "archive_browser.h"
|
||||
|
||||
#define ARCHIVE_FAV_FILE_BUF_LEN 32
|
||||
|
||||
static bool archive_favorites_read_line(File* file, string_t str_result) {
|
||||
string_reset(str_result);
|
||||
uint8_t buffer[ARCHIVE_FAV_FILE_BUF_LEN];
|
||||
bool result = false;
|
||||
|
||||
do {
|
||||
uint16_t read_count = storage_file_read(file, buffer, ARCHIVE_FAV_FILE_BUF_LEN);
|
||||
if(storage_file_get_error(file) != FSE_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(uint16_t i = 0; i < read_count; i++) {
|
||||
if(buffer[i] == '\n') {
|
||||
uint32_t position = storage_file_tell(file);
|
||||
if(storage_file_get_error(file) != FSE_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
position = position - read_count + i + 1;
|
||||
|
||||
storage_file_seek(file, position, true);
|
||||
if(storage_file_get_error(file) != FSE_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result = true;
|
||||
break;
|
||||
} else {
|
||||
string_push_back(str_result, buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(result || read_count == 0) {
|
||||
break;
|
||||
}
|
||||
} while(true);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint16_t archive_favorites_count(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
string_t buffer;
|
||||
string_init(buffer);
|
||||
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
uint16_t lines = 0;
|
||||
|
||||
if(result) {
|
||||
while(1) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
continue; // Skip empty lines
|
||||
}
|
||||
++lines;
|
||||
}
|
||||
}
|
||||
|
||||
storage_file_close(file);
|
||||
|
||||
string_clear(buffer);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
static bool archive_favourites_rescan() {
|
||||
string_t buffer;
|
||||
string_init(buffer);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
if(result) {
|
||||
while(1) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(string_search(buffer, "/app:") == 0) {
|
||||
if(archive_app_is_available(NULL, string_get_cstr(buffer))) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
||||
}
|
||||
} else {
|
||||
if(storage_file_exists(storage, string_get_cstr(buffer))) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(buffer);
|
||||
|
||||
storage_file_close(file);
|
||||
storage_common_remove(storage, ARCHIVE_FAV_PATH);
|
||||
storage_common_rename(storage, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
||||
storage_common_remove(storage, ARCHIVE_FAV_TEMP_PATH);
|
||||
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool archive_favorites_read(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
ArchiveBrowserView* browser = context;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
string_t buffer;
|
||||
FileInfo file_info;
|
||||
string_init(buffer);
|
||||
|
||||
bool need_refresh = false;
|
||||
uint16_t file_count = 0;
|
||||
|
||||
archive_file_array_rm_all(browser);
|
||||
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
|
||||
if(result) {
|
||||
while(1) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(string_search(buffer, "/app:") == 0) {
|
||||
if(archive_app_is_available(browser, string_get_cstr(buffer))) {
|
||||
archive_add_app_item(browser, string_get_cstr(buffer));
|
||||
file_count++;
|
||||
} else {
|
||||
need_refresh = true;
|
||||
}
|
||||
} else {
|
||||
if(storage_file_exists(storage, string_get_cstr(buffer))) {
|
||||
storage_common_stat(storage, string_get_cstr(buffer), &file_info);
|
||||
archive_add_file_item(
|
||||
browser, (file_info.flags & FSF_DIRECTORY), string_get_cstr(buffer));
|
||||
file_count++;
|
||||
} else {
|
||||
need_refresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
string_reset(buffer);
|
||||
}
|
||||
}
|
||||
storage_file_close(file);
|
||||
string_clear(buffer);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
archive_set_item_count(browser, file_count);
|
||||
|
||||
if(need_refresh) {
|
||||
archive_favourites_rescan();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool archive_favorites_delete(const char* format, ...) {
|
||||
string_t buffer;
|
||||
string_t filename;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(filename, format, args);
|
||||
va_end(args);
|
||||
|
||||
string_init(buffer);
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
|
||||
if(result) {
|
||||
while(1) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(string_search(buffer, filename)) {
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(buffer);
|
||||
string_clear(filename);
|
||||
|
||||
storage_file_close(file);
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
||||
storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);
|
||||
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool archive_is_favorite(const char* format, ...) {
|
||||
string_t buffer;
|
||||
string_t filename;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(filename, format, args);
|
||||
va_end(args);
|
||||
|
||||
string_init(buffer);
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
bool found = false;
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
|
||||
if(result) {
|
||||
while(1) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
if(!string_search(buffer, filename)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
storage_file_close(file);
|
||||
string_clear(buffer);
|
||||
string_clear(filename);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
bool archive_favorites_rename(const char* src, const char* dst) {
|
||||
furi_assert(src);
|
||||
furi_assert(dst);
|
||||
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
string_t path;
|
||||
string_t buffer;
|
||||
|
||||
string_init(buffer);
|
||||
string_init(path);
|
||||
|
||||
string_printf(path, "%s", src);
|
||||
bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
|
||||
|
||||
if(result) {
|
||||
while(1) {
|
||||
if(!archive_favorites_read_line(file, buffer)) {
|
||||
break;
|
||||
}
|
||||
if(!string_size(buffer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
archive_file_append(
|
||||
ARCHIVE_FAV_TEMP_PATH,
|
||||
"%s\n",
|
||||
string_search(buffer, path) ? string_get_cstr(buffer) : dst);
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(buffer);
|
||||
string_clear(path);
|
||||
|
||||
storage_file_close(file);
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
||||
storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);
|
||||
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void archive_add_to_favorites(const char* file_path) {
|
||||
furi_assert(file_path);
|
||||
|
||||
archive_file_append(ARCHIVE_FAV_PATH, "%s\n", file_path);
|
||||
}
|
||||
|
||||
void archive_favorites_save(void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
ArchiveBrowserView* browser = context;
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
for(size_t i = 0; i < archive_file_get_array_size(browser); i++) {
|
||||
ArchiveFile_t* item = archive_get_file_at(browser, i);
|
||||
archive_file_append(ARCHIVE_FAV_TEMP_PATH, "%s\n", string_get_cstr(item->path));
|
||||
}
|
||||
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_PATH);
|
||||
storage_common_rename(fs_api, ARCHIVE_FAV_TEMP_PATH, ARCHIVE_FAV_PATH);
|
||||
storage_common_remove(fs_api, ARCHIVE_FAV_TEMP_PATH);
|
||||
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
14
applications/main/archive/helpers/archive_favorites.h
Normal file
14
applications/main/archive/helpers/archive_favorites.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <storage/storage.h>
|
||||
|
||||
#define ARCHIVE_FAV_PATH ANY_PATH("favorites.txt")
|
||||
#define ARCHIVE_FAV_TEMP_PATH ANY_PATH("favorites.tmp")
|
||||
|
||||
uint16_t archive_favorites_count(void* context);
|
||||
bool archive_favorites_read(void* context);
|
||||
bool archive_favorites_delete(const char* format, ...);
|
||||
bool archive_is_favorite(const char* format, ...);
|
||||
bool archive_favorites_rename(const char* src, const char* dst);
|
||||
void archive_add_to_favorites(const char* file_path);
|
||||
void archive_favorites_save(void* context);
|
111
applications/main/archive/helpers/archive_files.c
Normal file
111
applications/main/archive/helpers/archive_files.c
Normal file
@@ -0,0 +1,111 @@
|
||||
#include "archive_files.h"
|
||||
#include "archive_apps.h"
|
||||
#include "archive_browser.h"
|
||||
|
||||
#define TAG "Archive"
|
||||
|
||||
#define ASSETS_DIR "assets"
|
||||
|
||||
void archive_set_file_type(ArchiveFile_t* file, const char* path, bool is_folder, bool is_app) {
|
||||
furi_assert(file);
|
||||
|
||||
file->is_app = is_app;
|
||||
if(is_app) {
|
||||
file->type = archive_get_app_filetype(archive_get_app_type(path));
|
||||
} else {
|
||||
for(size_t i = 0; i < COUNT_OF(known_ext); i++) {
|
||||
if((known_ext[i][0] == '?') || (known_ext[i][0] == '*')) continue;
|
||||
if(string_search_str(file->path, known_ext[i], 0) != STRING_FAILURE) {
|
||||
if(i == ArchiveFileTypeBadUsb) {
|
||||
if(string_search_str(file->path, archive_get_default_path(ArchiveTabBadUsb)) ==
|
||||
0) {
|
||||
file->type = i;
|
||||
return; // *.txt file is a BadUSB script only if it is in BadUSB folder
|
||||
}
|
||||
} else {
|
||||
file->type = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(is_folder) {
|
||||
file->type = ArchiveFileTypeFolder;
|
||||
} else {
|
||||
file->type = ArchiveFileTypeUnknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool archive_get_items(void* context, const char* path) {
|
||||
furi_assert(context);
|
||||
|
||||
bool res = false;
|
||||
ArchiveBrowserView* browser = context;
|
||||
|
||||
if(archive_get_tab(browser) == ArchiveTabFavorites) {
|
||||
res = archive_favorites_read(browser);
|
||||
} else if(strncmp(path, "/app:", 5) == 0) {
|
||||
res = archive_app_read_dir(browser, path);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void archive_file_append(const char* path, const char* format, ...) {
|
||||
furi_assert(path);
|
||||
|
||||
string_t string;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(string, format, args);
|
||||
va_end(args);
|
||||
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
bool res = storage_file_open(file, path, FSAM_WRITE, FSOM_OPEN_APPEND);
|
||||
|
||||
if(res) {
|
||||
storage_file_write(file, string_get_cstr(string), string_size(string));
|
||||
}
|
||||
|
||||
storage_file_close(file);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
void archive_delete_file(void* context, const char* format, ...) {
|
||||
furi_assert(context);
|
||||
|
||||
string_t filename;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
string_init_vprintf(filename, format, args);
|
||||
va_end(args);
|
||||
|
||||
ArchiveBrowserView* browser = context;
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
FileInfo fileinfo;
|
||||
storage_common_stat(fs_api, string_get_cstr(filename), &fileinfo);
|
||||
|
||||
bool res = false;
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
res = storage_simply_remove_recursive(fs_api, string_get_cstr(filename));
|
||||
} else {
|
||||
res = (storage_common_remove(fs_api, string_get_cstr(filename)) == FSE_OK);
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(archive_is_favorite("%s", string_get_cstr(filename))) {
|
||||
archive_favorites_delete("%s", string_get_cstr(filename));
|
||||
}
|
||||
|
||||
if(res) {
|
||||
archive_file_array_rm_selected(browser);
|
||||
}
|
||||
|
||||
string_clear(filename);
|
||||
}
|
64
applications/main/archive/helpers/archive_files.h
Normal file
64
applications/main/archive/helpers/archive_files.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <m-array.h>
|
||||
#include <m-string.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
typedef enum {
|
||||
ArchiveFileTypeIButton,
|
||||
ArchiveFileTypeNFC,
|
||||
ArchiveFileTypeSubGhz,
|
||||
ArchiveFileTypeLFRFID,
|
||||
ArchiveFileTypeInfrared,
|
||||
ArchiveFileTypeBadUsb,
|
||||
ArchiveFileTypeU2f,
|
||||
ArchiveFileTypeUpdateManifest,
|
||||
ArchiveFileTypeFolder,
|
||||
ArchiveFileTypeUnknown,
|
||||
ArchiveFileTypeLoading,
|
||||
} ArchiveFileTypeEnum;
|
||||
|
||||
typedef struct {
|
||||
string_t path;
|
||||
ArchiveFileTypeEnum type;
|
||||
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;
|
||||
string_init(obj->path);
|
||||
}
|
||||
|
||||
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;
|
||||
string_init_set(obj->path, src->path);
|
||||
}
|
||||
|
||||
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;
|
||||
string_set(obj->path, src->path);
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_clear(ArchiveFile_t* obj) {
|
||||
string_clear(obj->path);
|
||||
}
|
||||
|
||||
ARRAY_DEF(
|
||||
files_array,
|
||||
ArchiveFile_t,
|
||||
(INIT(API_2(ArchiveFile_t_init)),
|
||||
SET(API_6(ArchiveFile_t_set)),
|
||||
INIT_SET(API_6(ArchiveFile_t_init_set)),
|
||||
CLEAR(API_2(ArchiveFile_t_clear))))
|
||||
|
||||
void archive_set_file_type(ArchiveFile_t* file, const char* path, bool is_folder, bool is_app);
|
||||
bool archive_get_items(void* context, const char* path);
|
||||
void archive_file_append(const char* path, const char* format, ...);
|
||||
void archive_delete_file(void* context, const char* format, ...);
|
Reference in New Issue
Block a user