2022-09-14 16:11:38 +00:00
|
|
|
#include <archive/views/archive_browser_view.h>
|
2022-02-10 13:01:49 +00:00
|
|
|
#include "archive_files.h"
|
|
|
|
#include "archive_apps.h"
|
2021-09-21 10:56:33 +00:00
|
|
|
#include "archive_browser.h"
|
2022-07-20 10:56:33 +00:00
|
|
|
#include <core/common_defines.h>
|
|
|
|
#include <core/log.h>
|
2022-06-09 07:09:52 +00:00
|
|
|
#include "gui/modules/file_browser_worker.h"
|
2022-10-06 15:37:53 +00:00
|
|
|
#include <fap_loader/fap_loader_app.h>
|
2022-02-10 13:01:49 +00:00
|
|
|
#include <math.h>
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
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;
|
2022-07-06 13:54:08 +00:00
|
|
|
ArchiveTabEnum tab = archive_get_tab(browser);
|
2022-06-09 07:09:52 +00:00
|
|
|
|
2022-07-06 13:54:08 +00:00
|
|
|
if((item_cnt == 0) && (archive_is_home(browser)) && (tab != ArchiveTabBrowser)) {
|
2022-06-09 07:09:52 +00:00
|
|
|
archive_switch_tab(browser, browser->last_tab_switch_dir);
|
2022-10-05 15:15:23 +00:00
|
|
|
} else if(!furi_string_start_with_str(browser->path, "/app:")) {
|
2022-06-09 07:09:52 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-06-09 07:09:52 +00:00
|
|
|
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;
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2022-06-09 07:09:52 +00:00
|
|
|
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(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-06-09 07:09:52 +00:00
|
|
|
files_array_reset(model->files);
|
|
|
|
model->array_offset = list_load_offset;
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2022-06-09 07:09:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
static void
|
|
|
|
archive_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
|
2022-06-09 07:09:52 +00:00
|
|
|
furi_assert(context);
|
|
|
|
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
|
|
|
|
|
|
|
if(!is_last) {
|
2022-10-05 15:15:23 +00:00
|
|
|
archive_add_file_item(browser, is_folder, furi_string_get_cstr(item_path));
|
2022-06-09 07:09:52 +00:00
|
|
|
} else {
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view, ArchiveBrowserViewModel * model, { model->list_loading = false; }, true);
|
2022-06-09 07:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void archive_long_load_cb(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
|
|
|
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view, ArchiveBrowserViewModel * model, { model->folder_loading = true; }, true);
|
2022-06-09 07:09:52 +00:00
|
|
|
}
|
|
|
|
|
2022-08-22 16:19:03 +00:00
|
|
|
static void archive_file_browser_set_path(
|
|
|
|
ArchiveBrowserView* browser,
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* path,
|
2022-08-22 16:19:03 +00:00
|
|
|
const char* filter_ext,
|
|
|
|
bool skip_assets) {
|
2022-06-09 07:09:52 +00:00
|
|
|
furi_assert(browser);
|
2022-08-22 16:19:03 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-06-09 07:09:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx) {
|
|
|
|
size_t array_size = files_array_size(model->files);
|
|
|
|
|
2022-05-06 13:37:10 +00:00
|
|
|
if((idx >= (uint32_t)model->array_offset + array_size) ||
|
|
|
|
(idx < (uint32_t)model->array_offset)) {
|
2022-04-06 17:44:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
void archive_update_offset(ArchiveBrowserView* browser) {
|
|
|
|
furi_assert(browser);
|
2022-04-06 17:44:06 +00:00
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-04-06 17:44:06 +00:00
|
|
|
uint16_t bounds = model->item_cnt > 3 ? 2 : model->item_cnt;
|
|
|
|
|
2022-05-06 16:26:25 +00:00
|
|
|
if((model->item_cnt > 3u) && (model->item_idx >= ((int32_t)model->item_cnt - 1))) {
|
2022-04-06 17:44:06 +00:00
|
|
|
model->list_offset = model->item_idx - 3;
|
|
|
|
} else if(model->list_offset < model->item_idx - bounds) {
|
2022-05-06 13:37:10 +00:00
|
|
|
model->list_offset =
|
2022-05-06 16:26:25 +00:00
|
|
|
CLAMP(model->item_idx - 2, (int32_t)model->item_cnt - bounds, 0);
|
2022-04-06 17:44:06 +00:00
|
|
|
} else if(model->list_offset > model->item_idx - bounds) {
|
2022-05-06 13:37:10 +00:00
|
|
|
model->list_offset =
|
2022-05-06 16:26:25 +00:00
|
|
|
CLAMP(model->item_idx - 1, (int32_t)model->item_cnt - bounds, 0);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
true);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
|
|
|
furi_assert(browser);
|
|
|
|
furi_assert(target);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
archive_get_items(browser, furi_string_get_cstr(browser->path));
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
if(!archive_file_get_array_size(browser) && archive_is_home(browser)) {
|
2022-04-06 17:44:06 +00:00
|
|
|
archive_switch_tab(browser, TAB_RIGHT);
|
2021-09-21 10:56:33 +00:00
|
|
|
} else {
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2021-09-21 10:56:33 +00:00
|
|
|
uint16_t idx = 0;
|
|
|
|
while(idx < files_array_size(model->files)) {
|
|
|
|
ArchiveFile_t* current = files_array_get(model->files, idx);
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_search(current->path, target)) {
|
2022-04-06 17:44:06 +00:00
|
|
|
model->item_idx = idx + model->array_offset;
|
2021-09-21 10:56:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++idx;
|
|
|
|
}
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2021-09-21 10:56:33 +00:00
|
|
|
|
|
|
|
archive_update_offset(browser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
size_t archive_file_get_array_size(ArchiveBrowserView* browser) {
|
|
|
|
furi_assert(browser);
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
uint16_t size = 0;
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{ size = files_array_size(model->files); },
|
|
|
|
false);
|
2021-09-21 10:56:33 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
void archive_set_item_count(ArchiveBrowserView* browser, uint32_t count) {
|
|
|
|
furi_assert(browser);
|
|
|
|
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-04-06 17:44:06 +00:00
|
|
|
model->item_cnt = count;
|
2022-05-06 16:26:25 +00:00
|
|
|
model->item_idx = CLAMP(model->item_idx, (int32_t)model->item_cnt - 1, 0);
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2022-05-04 22:51:45 +00:00
|
|
|
archive_update_offset(browser);
|
2022-04-06 17:44:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
void archive_file_array_rm_selected(ArchiveBrowserView* browser) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
uint32_t items_cnt = 0;
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-04-06 17:44:06 +00:00
|
|
|
files_array_remove_v(
|
|
|
|
model->files,
|
|
|
|
model->item_idx - model->array_offset,
|
|
|
|
model->item_idx - model->array_offset + 1);
|
|
|
|
model->item_cnt--;
|
2022-05-06 16:26:25 +00:00
|
|
|
model->item_idx = CLAMP(model->item_idx, (int32_t)model->item_cnt - 1, 0);
|
2022-04-06 17:44:06 +00:00
|
|
|
items_cnt = model->item_cnt;
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
if((items_cnt == 0) && (archive_is_home(browser))) {
|
2022-04-06 17:44:06 +00:00
|
|
|
archive_switch_tab(browser, TAB_RIGHT);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
archive_update_offset(browser);
|
|
|
|
}
|
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
void archive_file_array_swap(ArchiveBrowserView* browser, int8_t dir) {
|
|
|
|
furi_assert(browser);
|
|
|
|
|
2021-10-12 13:09:34 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2021-10-13 09:53:58 +00:00
|
|
|
ArchiveFile_t temp;
|
2021-10-12 13:09:34 +00:00
|
|
|
size_t array_size = files_array_size(model->files) - 1;
|
2022-05-06 13:37:10 +00:00
|
|
|
uint8_t swap_idx = CLAMP((size_t)(model->item_idx + dir), array_size, 0u);
|
2021-10-12 13:09:34 +00:00
|
|
|
|
2022-04-06 17:44:06 +00:00
|
|
|
if(model->item_idx == 0 && dir < 0) {
|
2021-10-13 09:53:58 +00:00
|
|
|
ArchiveFile_t_init(&temp);
|
|
|
|
files_array_pop_at(&temp, model->files, array_size);
|
2022-04-06 17:44:06 +00:00
|
|
|
files_array_push_at(model->files, model->item_idx, temp);
|
2021-10-13 09:53:58 +00:00
|
|
|
ArchiveFile_t_clear(&temp);
|
2022-05-06 13:37:10 +00:00
|
|
|
} else if(((uint32_t)model->item_idx == array_size) && (dir > 0)) {
|
2021-10-13 09:53:58 +00:00
|
|
|
ArchiveFile_t_init(&temp);
|
2022-04-14 17:02:16 +00:00
|
|
|
files_array_pop_at(&temp, model->files, 0);
|
2021-10-13 09:53:58 +00:00
|
|
|
files_array_push_at(model->files, array_size, temp);
|
|
|
|
ArchiveFile_t_clear(&temp);
|
|
|
|
} else {
|
2022-04-06 17:44:06 +00:00
|
|
|
files_array_swap_at(model->files, model->item_idx, swap_idx);
|
2021-10-12 13:09:34 +00:00
|
|
|
}
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2021-10-12 13:09:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
void archive_file_array_rm_all(ArchiveBrowserView* browser) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{ files_array_reset(model->files); },
|
|
|
|
false);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
void archive_file_array_load(ArchiveBrowserView* browser, int8_t dir) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
|
|
|
int32_t offset_new = 0;
|
|
|
|
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-04-06 17:44:06 +00:00
|
|
|
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;
|
|
|
|
}
|
2022-06-09 07:09:52 +00:00
|
|
|
if(offset_new > 0) {
|
2022-11-28 18:59:24 +00:00
|
|
|
offset_new = CLAMP(offset_new, (int32_t)model->item_cnt, 0);
|
2022-06-09 07:09:52 +00:00
|
|
|
} else {
|
|
|
|
offset_new = 0;
|
|
|
|
}
|
2022-04-06 17:44:06 +00:00
|
|
|
}
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2022-04-06 17:44:06 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
file_browser_worker_load(browser->worker, offset_new, FILE_LIST_BUF_LEN);
|
2022-04-06 17:44:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
ArchiveFile_t* archive_get_current_file(ArchiveBrowserView* browser) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
2022-09-19 13:03:42 +00:00
|
|
|
ArchiveFile_t* selected = NULL;
|
2021-09-21 10:56:33 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-04-06 17:44:06 +00:00
|
|
|
selected = files_array_size(model->files) ?
|
|
|
|
files_array_get(model->files, model->item_idx - model->array_offset) :
|
|
|
|
NULL;
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2021-09-21 10:56:33 +00:00
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
2021-10-12 13:09:34 +00:00
|
|
|
ArchiveFile_t* archive_get_file_at(ArchiveBrowserView* browser, size_t idx) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
2022-09-19 13:03:42 +00:00
|
|
|
ArchiveFile_t* selected = NULL;
|
2021-10-12 13:09:34 +00:00
|
|
|
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-05-06 13:37:10 +00:00
|
|
|
idx = CLAMP(idx - model->array_offset, files_array_size(model->files), 0u);
|
2021-10-12 13:09:34 +00:00
|
|
|
selected = files_array_size(model->files) ? files_array_get(model->files, idx) : NULL;
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2021-10-12 13:09:34 +00:00
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
ArchiveTabEnum archive_get_tab(ArchiveBrowserView* browser) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
2022-09-19 13:03:42 +00:00
|
|
|
ArchiveTabEnum tab_id = 0;
|
2021-09-21 10:56:33 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view, ArchiveBrowserViewModel * model, { tab_id = model->tab_idx; }, false);
|
2021-09-21 10:56:33 +00:00
|
|
|
return tab_id;
|
|
|
|
}
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
bool archive_is_home(ArchiveBrowserView* browser) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
if(browser->is_root) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
const char* default_path = archive_get_default_path(archive_get_tab(browser));
|
2022-10-05 15:15:23 +00:00
|
|
|
return (furi_string_cmp_str(browser->path, default_path) == 0);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* archive_get_name(ArchiveBrowserView* browser) {
|
|
|
|
ArchiveFile_t* selected = archive_get_current_file(browser);
|
2022-10-05 15:15:23 +00:00
|
|
|
return furi_string_get_cstr(selected->path);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void archive_set_tab(ArchiveBrowserView* browser, ArchiveTabEnum tab) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view, ArchiveBrowserViewModel * model, { model->tab_idx = tab; }, false);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 13:01:49 +00:00
|
|
|
void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
|
|
|
|
furi_assert(browser);
|
|
|
|
furi_assert(name);
|
|
|
|
|
|
|
|
ArchiveFile_t item;
|
|
|
|
ArchiveFile_t_init(&item);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(item.path, name);
|
2022-06-09 07:09:52 +00:00
|
|
|
archive_set_file_type(&item, name, false, true);
|
2022-02-10 13:01:49 +00:00
|
|
|
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-02-10 13:01:49 +00:00
|
|
|
files_array_push_back(model->files, item);
|
2022-04-06 17:44:06 +00:00
|
|
|
model->item_cnt = files_array_size(model->files);
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2022-02-10 13:01:49 +00:00
|
|
|
ArchiveFile_t_clear(&item);
|
|
|
|
}
|
|
|
|
|
2022-10-06 15:37:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
void archive_add_file_item(ArchiveBrowserView* browser, bool is_folder, const char* name) {
|
2021-09-21 10:56:33 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
furi_assert(name);
|
|
|
|
|
|
|
|
ArchiveFile_t item;
|
2022-06-09 07:09:52 +00:00
|
|
|
ArchiveFile_t_init(&item);
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-10-06 15:37:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-06-09 07:09:52 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{ files_array_push_back(model->files, item); },
|
|
|
|
false);
|
2022-06-09 07:09:52 +00:00
|
|
|
ArchiveFile_t_clear(&item);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void archive_show_file_menu(ArchiveBrowserView* browser, bool show) {
|
|
|
|
furi_assert(browser);
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2021-09-21 10:56:33 +00:00
|
|
|
if(show) {
|
2022-04-06 17:44:06 +00:00
|
|
|
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);
|
2022-10-05 15:15:23 +00:00
|
|
|
selected->fav =
|
|
|
|
archive_is_favorite("%s", furi_string_get_cstr(selected->path));
|
2022-04-06 17:44:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
model->menu = false;
|
|
|
|
model->menu_idx = 0;
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
true);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 13:09:34 +00:00
|
|
|
void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active) {
|
2022-04-06 17:44:06 +00:00
|
|
|
furi_assert(browser);
|
|
|
|
|
2021-10-12 13:09:34 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view, ArchiveBrowserViewModel * model, { model->move_fav = active; }, true);
|
2021-10-12 13:09:34 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
static bool archive_is_dir_exists(FuriString* path) {
|
|
|
|
if(furi_string_equal(path, STORAGE_ANY_PATH_PREFIX)) {
|
2022-07-06 13:54:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool state = false;
|
|
|
|
FileInfo file_info;
|
2022-07-26 12:21:51 +00:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-10-05 15:15:23 +00:00
|
|
|
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
2022-07-06 13:54:08 +00:00
|
|
|
if(file_info.flags & FSF_DIRECTORY) {
|
|
|
|
state = true;
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-07-06 13:54:08 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
|
|
|
|
furi_assert(browser);
|
|
|
|
ArchiveTabEnum tab = archive_get_tab(browser);
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
browser->last_tab_switch_dir = key;
|
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
if(key == InputKeyLeft) {
|
|
|
|
tab = ((tab - 1) + ArchiveTabTotal) % ArchiveTabTotal;
|
2022-06-09 07:09:52 +00:00
|
|
|
} else {
|
2021-09-21 10:56:33 +00:00
|
|
|
tab = (tab + 1) % ArchiveTabTotal;
|
|
|
|
}
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
browser->is_root = true;
|
2021-09-21 10:56:33 +00:00
|
|
|
archive_set_tab(browser, tab);
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(browser->path, archive_get_default_path(tab));
|
2022-02-10 13:01:49 +00:00
|
|
|
bool tab_empty = true;
|
|
|
|
if(tab == ArchiveTabFavorites) {
|
2022-06-09 07:09:52 +00:00
|
|
|
if(archive_favorites_count(browser) > 0) {
|
|
|
|
tab_empty = false;
|
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
} else if(furi_string_start_with_str(browser->path, "/app:")) {
|
|
|
|
char* app_name = strchr(furi_string_get_cstr(browser->path), ':');
|
2022-06-09 07:09:52 +00:00
|
|
|
if(app_name != NULL) {
|
2022-10-05 15:15:23 +00:00
|
|
|
if(archive_app_is_available(browser, furi_string_get_cstr(browser->path))) {
|
2022-06-09 07:09:52 +00:00
|
|
|
tab_empty = false;
|
|
|
|
}
|
|
|
|
}
|
2022-02-10 13:01:49 +00:00
|
|
|
} else {
|
2022-07-06 13:54:08 +00:00
|
|
|
tab = archive_get_tab(browser);
|
|
|
|
if(archive_is_dir_exists(browser->path)) {
|
|
|
|
bool skip_assets = (strcmp(archive_get_tab_ext(tab), "*") == 0) ? false : true;
|
2022-08-22 16:19:03 +00:00
|
|
|
archive_file_browser_set_path(
|
|
|
|
browser, browser->path, archive_get_tab_ext(tab), skip_assets);
|
2022-07-06 13:54:08 +00:00
|
|
|
tab_empty = false; // Empty check will be performed later
|
|
|
|
}
|
2022-02-10 13:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if((tab_empty) && (tab != ArchiveTabBrowser)) {
|
|
|
|
archive_switch_tab(browser, key);
|
2021-09-21 10:56:33 +00:00
|
|
|
} else {
|
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view,
|
|
|
|
ArchiveBrowserViewModel * model,
|
|
|
|
{
|
2022-06-09 07:09:52 +00:00
|
|
|
model->item_idx = 0;
|
|
|
|
model->array_offset = 0;
|
2022-10-08 17:38:29 +00:00
|
|
|
},
|
|
|
|
false);
|
2022-10-05 15:15:23 +00:00
|
|
|
archive_get_items(browser, furi_string_get_cstr(browser->path));
|
2022-06-09 07:09:52 +00:00
|
|
|
archive_update_offset(browser);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
void archive_enter_dir(ArchiveBrowserView* browser, FuriString* path) {
|
2021-09-21 10:56:33 +00:00
|
|
|
furi_assert(browser);
|
2022-06-09 07:09:52 +00:00
|
|
|
furi_assert(path);
|
2022-04-14 11:28:59 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
int32_t idx_temp = 0;
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view, ArchiveBrowserViewModel * model, { idx_temp = model->item_idx; }, false);
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_set(browser->path, path);
|
2022-06-09 07:09:52 +00:00
|
|
|
file_browser_worker_folder_enter(browser->worker, path, idx_temp);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void archive_leave_dir(ArchiveBrowserView* browser) {
|
|
|
|
furi_assert(browser);
|
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
file_browser_worker_folder_exit(browser->worker);
|
|
|
|
}
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
void archive_refresh_dir(ArchiveBrowserView* browser) {
|
|
|
|
furi_assert(browser);
|
2021-09-21 10:56:33 +00:00
|
|
|
|
2022-06-09 07:09:52 +00:00
|
|
|
int32_t idx_temp = 0;
|
2022-04-06 17:44:06 +00:00
|
|
|
|
2021-09-21 10:56:33 +00:00
|
|
|
with_view_model(
|
2022-10-08 17:38:29 +00:00
|
|
|
browser->view, ArchiveBrowserViewModel * model, { idx_temp = model->item_idx; }, false);
|
2022-06-09 07:09:52 +00:00
|
|
|
file_browser_worker_folder_refresh(browser->worker, idx_temp);
|
2021-09-21 10:56:33 +00:00
|
|
|
}
|