diff --git a/applications/debug_tools/file_browser_test/file_browser_app.c b/applications/debug_tools/file_browser_test/file_browser_app.c index a408f5cde..c9b63ecb0 100644 --- a/applications/debug_tools/file_browser_test/file_browser_app.c +++ b/applications/debug_tools/file_browser_test/file_browser_app.c @@ -48,7 +48,7 @@ FileBrowserApp* file_browser_app_alloc(char* arg) { app->widget = widget_alloc(); string_init(app->file_path); - app->file_browser = file_browser_alloc(&(app->file_path)); + app->file_browser = file_browser_alloc(app->file_path); file_browser_configure(app->file_browser, "*", true, &I_badusb_10px, true); view_dispatcher_add_view( diff --git a/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c b/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c index 9c570cec0..ca16ad0d1 100644 --- a/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c +++ b/applications/debug_tools/file_browser_test/scenes/file_browser_scene_browser.c @@ -20,12 +20,10 @@ bool file_browser_scene_browser_on_event(void* context, SceneManagerEvent event) return consumed; } -static void file_browser_callback(void* context, bool state) { +static void file_browser_callback(void* context) { FileBrowserApp* app = context; furi_assert(app); view_dispatcher_send_custom_event(app->view_dispatcher, SceneManagerEventTypeCustom); - - UNUSED(state); } void file_browser_scene_browser_on_enter(void* context) { diff --git a/applications/gui/modules/file_browser.c b/applications/gui/modules/file_browser.c index 919750962..1cef1d079 100644 --- a/applications/gui/modules/file_browser.c +++ b/applications/gui/modules/file_browser.c @@ -10,6 +10,7 @@ #include #include #include +#include "toolbox/path.h" #define LIST_ITEMS 5u #define MAX_LEN_PX 110 @@ -60,13 +61,13 @@ ARRAY_DEF( struct FileBrowser { View* view; BrowserWorker* worker; - char* ext_filter; + const char* ext_filter; bool skip_assets; FileBrowserCallback callback; void* context; - string_t* result_path; + string_ptr result_path; }; typedef struct { @@ -100,7 +101,7 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset); static void browser_list_item_cb(void* context, string_t item_path, bool is_folder, bool is_last); static void browser_long_load_cb(void* context); -FileBrowser* file_browser_alloc(string_t* result_path) { +FileBrowser* file_browser_alloc(string_ptr result_path) { furi_assert(result_path); FileBrowser* browser = malloc(sizeof(FileBrowser)); browser->view = view_alloc(); @@ -140,7 +141,7 @@ View* file_browser_get_view(FileBrowser* browser) { void file_browser_configure( FileBrowser* browser, - char* extension, + const char* extension, bool skip_assets, const Icon* file_icon, bool hide_ext) { @@ -250,6 +251,7 @@ static void with_view_model( browser->view, (FileBrowserModel * model) { + items_array_reset(model->items); if(is_root) { model->item_cnt = item_cnt; model->item_idx = (file_idx > 0) ? file_idx : 0; @@ -383,7 +385,7 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) { BrowserItem_t* item = items_array_get( model->items, CLAMP(idx - model->array_offset, (int32_t)(array_size - 1), 0)); item_type = item->type; - file_browser_worker_get_filename( + path_extract_filename( item->path, filename, (model->hide_ext) && (item_type == BrowserItemTypeFile)); } else { string_set_str(filename, "---"); @@ -505,9 +507,9 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) { file_browser_worker_folder_enter( browser->worker, selected_item->path, select_index); } else if(selected_item->type == BrowserItemTypeFile) { - string_set(*(browser->result_path), selected_item->path); + string_set(browser->result_path, selected_item->path); if(browser->callback) { - browser->callback(browser->context, true); + browser->callback(browser->context); } } } diff --git a/applications/gui/modules/file_browser.h b/applications/gui/modules/file_browser.h index b77c6e65c..ebc64509a 100644 --- a/applications/gui/modules/file_browser.h +++ b/applications/gui/modules/file_browser.h @@ -13,9 +13,9 @@ extern "C" { #endif typedef struct FileBrowser FileBrowser; -typedef void (*FileBrowserCallback)(void* context, bool state); +typedef void (*FileBrowserCallback)(void* context); -FileBrowser* file_browser_alloc(string_t* result_path); +FileBrowser* file_browser_alloc(string_ptr result_path); void file_browser_free(FileBrowser* browser); @@ -23,7 +23,7 @@ View* file_browser_get_view(FileBrowser* browser); void file_browser_configure( FileBrowser* browser, - char* extension, + const char* extension, bool skip_assets, const Icon* file_icon, bool hide_ext); diff --git a/applications/gui/modules/file_browser_worker.c b/applications/gui/modules/file_browser_worker.c index 13fc97111..93baba008 100644 --- a/applications/gui/modules/file_browser_worker.c +++ b/applications/gui/modules/file_browser_worker.c @@ -8,6 +8,7 @@ #include #include #include +#include "toolbox/path.h" #define TAG "BrowserWorker" @@ -149,6 +150,7 @@ static bool browser_folder_init( (*item_cnt)++; } if(total_files_cnt == LONG_LOAD_THRESHOLD) { + // There are too many files in folder and counting them will take some time - send callback to app if(browser->long_load_cb) { browser->long_load_cb(browser->cb_ctx); } @@ -255,7 +257,7 @@ static int32_t browser_worker(void* context) { string_t filename; string_init(filename); if(browser_path_is_file(browser->path_next)) { - file_browser_worker_get_filename(browser->path_next, filename, false); + path_extract_filename(browser->path_next, filename, false); } osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtFolderEnter); @@ -319,21 +321,7 @@ static int32_t browser_worker(void* context) { return 0; } -void file_browser_worker_get_filename(string_t path, string_t name, bool trim_ext) { - size_t filename_start = string_search_rchar(path, '/'); - if(filename_start > 0) { - filename_start++; - string_set_n(name, path, filename_start, string_size(path) - filename_start); - } - if(trim_ext) { - size_t dot = string_search_rchar(name, '.'); - if(dot > 0) { - string_left(name, dot); - } - } -} - -BrowserWorker* file_browser_worker_alloc(string_t path, char* filter_ext, bool skip_assets) { +BrowserWorker* file_browser_worker_alloc(string_t path, const char* filter_ext, bool skip_assets) { BrowserWorker* browser = malloc(sizeof(BrowserWorker)); idx_last_array_init(browser->idx_last); diff --git a/applications/gui/modules/file_browser_worker.h b/applications/gui/modules/file_browser_worker.h index 821d5103f..b0d360a38 100644 --- a/applications/gui/modules/file_browser_worker.h +++ b/applications/gui/modules/file_browser_worker.h @@ -22,9 +22,7 @@ typedef void (*BrowserWorkerListItemCallback)( bool is_last); typedef void (*BrowserWorkerLongLoadCallback)(void* context); -void file_browser_worker_get_filename(string_t path, string_t name, bool trim_ext); - -BrowserWorker* file_browser_worker_alloc(string_t path, char* filter_ext, bool skip_assets); +BrowserWorker* file_browser_worker_alloc(string_t path, const char* filter_ext, bool skip_assets); void file_browser_worker_free(BrowserWorker* browser);