mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Fix archive selection index issues after refresh
This commit is contained in:
@@ -573,9 +573,11 @@ void archive_leave_dir(ArchiveBrowserView* browser) {
|
||||
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; }, false);
|
||||
file_browser_worker_folder_refresh(browser->worker, idx_temp);
|
||||
ArchiveFile_t* current = archive_get_current_file(browser);
|
||||
FuriString* str = furi_string_alloc();
|
||||
if(current != NULL) {
|
||||
path_extract_basename(furi_string_get_cstr(current->path), str);
|
||||
}
|
||||
file_browser_worker_folder_refresh(browser->worker, furi_string_get_cstr(str));
|
||||
furi_string_free(str);
|
||||
}
|
||||
|
||||
@@ -113,47 +113,45 @@ void archive_delete_file(void* context, const char* format, ...) {
|
||||
FS_Error archive_copy_rename_file_or_dir(
|
||||
void* context,
|
||||
const char* src_path,
|
||||
const char* dst_path,
|
||||
FuriString* dst_path,
|
||||
bool copy,
|
||||
bool find_name) {
|
||||
furi_assert(context);
|
||||
const char* dst_cstr = furi_string_get_cstr(dst_path);
|
||||
|
||||
FURI_LOG_I(TAG, "%s from %s to %s", copy ? "Copy" : "Move", src_path, dst_path);
|
||||
FURI_LOG_I(TAG, "%s from %s to %s", copy ? "Copy" : "Move", src_path, dst_cstr);
|
||||
|
||||
ArchiveBrowserView* browser = context;
|
||||
UNUSED(context);
|
||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* dst_str = furi_string_alloc_set(dst_path);
|
||||
dst_path = furi_string_get_cstr(dst_str);
|
||||
|
||||
FileInfo fileinfo;
|
||||
storage_common_stat(fs_api, src_path, &fileinfo);
|
||||
|
||||
FS_Error error = FSE_OK;
|
||||
|
||||
if(!path_contains_only_ascii(dst_path)) {
|
||||
if(!path_contains_only_ascii(dst_cstr)) {
|
||||
error = FSE_INVALID_NAME;
|
||||
} else if(!copy && !strcmp(src_path, dst_path)) {
|
||||
} else if(!copy && !strcmp(src_path, dst_cstr)) {
|
||||
error = FSE_EXIST;
|
||||
} else {
|
||||
if(find_name && storage_common_exists(fs_api, dst_path)) {
|
||||
if(find_name && storage_common_exists(fs_api, dst_cstr)) {
|
||||
FuriString* dir_path = furi_string_alloc();
|
||||
FuriString* filename = furi_string_alloc();
|
||||
FuriString* file_ext = furi_string_alloc();
|
||||
|
||||
path_extract_dirname(furi_string_get_cstr(dst_str), dir_path);
|
||||
path_extract_filename(dst_str, filename, true);
|
||||
path_extract_ext_str(dst_str, file_ext);
|
||||
path_extract_dirname(dst_cstr, dir_path);
|
||||
path_extract_filename(dst_path, filename, true);
|
||||
path_extract_ext_str(dst_path, file_ext);
|
||||
|
||||
storage_get_next_filename(
|
||||
fs_api,
|
||||
furi_string_get_cstr(dir_path),
|
||||
furi_string_get_cstr(filename),
|
||||
furi_string_get_cstr(file_ext),
|
||||
dst_str,
|
||||
dst_path,
|
||||
255);
|
||||
furi_string_cat_printf(
|
||||
dir_path, "/%s%s", furi_string_get_cstr(dst_str), furi_string_get_cstr(file_ext));
|
||||
furi_string_set(dst_str, dir_path);
|
||||
furi_string_cat_printf(dir_path, "/%s%s", dst_cstr, furi_string_get_cstr(file_ext));
|
||||
furi_string_set(dst_path, dir_path);
|
||||
|
||||
furi_string_free(dir_path);
|
||||
furi_string_free(filename);
|
||||
@@ -161,20 +159,19 @@ FS_Error archive_copy_rename_file_or_dir(
|
||||
}
|
||||
|
||||
if(copy) {
|
||||
error = storage_common_copy(fs_api, src_path, dst_path);
|
||||
error = storage_common_copy(fs_api, src_path, dst_cstr);
|
||||
} else {
|
||||
error = storage_common_rename(fs_api, src_path, dst_path);
|
||||
error = storage_common_rename(fs_api, src_path, dst_cstr);
|
||||
}
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(!copy && archive_is_favorite("%s", src_path)) {
|
||||
archive_favorites_rename(src_path, dst_path);
|
||||
archive_favorites_rename(src_path, dst_cstr);
|
||||
}
|
||||
|
||||
if(error == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "%s from %s to %s is DONE", copy ? "Copy" : "Move", src_path, dst_path);
|
||||
archive_refresh_dir(browser);
|
||||
FURI_LOG_I(TAG, "%s from %s to %s is DONE", copy ? "Copy" : "Move", src_path, dst_cstr);
|
||||
} else {
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
@@ -184,7 +181,5 @@ FS_Error archive_copy_rename_file_or_dir(
|
||||
error);
|
||||
}
|
||||
|
||||
furi_string_free(dst_str);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -116,6 +116,6 @@ void archive_delete_file(void* context, const char* format, ...)
|
||||
FS_Error archive_copy_rename_file_or_dir(
|
||||
void* context,
|
||||
const char* src_path,
|
||||
const char* dst_path,
|
||||
FuriString* dst_path,
|
||||
bool copy,
|
||||
bool find_name);
|
||||
|
||||
@@ -201,14 +201,8 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewStack);
|
||||
archive_show_loading_popup(archive, true);
|
||||
FS_Error error = archive_copy_rename_file_or_dir(
|
||||
archive->browser,
|
||||
furi_string_get_cstr(path_src),
|
||||
furi_string_get_cstr(path_dst),
|
||||
copy,
|
||||
true);
|
||||
archive->browser, furi_string_get_cstr(path_src), path_dst, copy, true);
|
||||
archive_show_loading_popup(archive, false);
|
||||
furi_string_free(path_src);
|
||||
furi_string_free(path_dst);
|
||||
if(error != FSE_OK) {
|
||||
FuriString* dialog_msg;
|
||||
dialog_msg = furi_string_alloc();
|
||||
@@ -220,7 +214,14 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
dialog_message_show_storage_error(
|
||||
archive->dialogs, furi_string_get_cstr(dialog_msg));
|
||||
furi_string_free(dialog_msg);
|
||||
} else {
|
||||
ArchiveFile_t* current = archive_get_current_file(archive->browser);
|
||||
if(current != NULL) furi_string_set(current->path, path_dst);
|
||||
view_dispatcher_send_custom_event(
|
||||
archive->view_dispatcher, ArchiveBrowserEventListRefresh);
|
||||
}
|
||||
furi_string_free(path_src);
|
||||
furi_string_free(path_dst);
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewBrowser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,11 +55,8 @@ bool archive_scene_new_dir_on_event(void* context, SceneManagerEvent event) {
|
||||
error = storage_common_mkdir(fs_api, furi_string_get_cstr(path_dst));
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
archive_refresh_dir(archive->browser);
|
||||
archive_show_loading_popup(archive, false);
|
||||
|
||||
furi_string_free(path_dst);
|
||||
|
||||
if(error != FSE_OK) {
|
||||
FuriString* dialog_msg;
|
||||
dialog_msg = furi_string_alloc();
|
||||
@@ -68,7 +65,12 @@ bool archive_scene_new_dir_on_event(void* context, SceneManagerEvent event) {
|
||||
dialog_message_show_storage_error(
|
||||
archive->dialogs, furi_string_get_cstr(dialog_msg));
|
||||
furi_string_free(dialog_msg);
|
||||
} else {
|
||||
ArchiveFile_t* current = archive_get_current_file(archive->browser);
|
||||
if(current != NULL) furi_string_set(current->path, path_dst);
|
||||
}
|
||||
|
||||
furi_string_free(path_dst);
|
||||
scene_manager_previous_scene(archive->scene_manager);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
@@ -85,11 +85,9 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewStack);
|
||||
archive_show_loading_popup(archive, true);
|
||||
FS_Error error = archive_copy_rename_file_or_dir(
|
||||
archive->browser, path_src, furi_string_get_cstr(path_dst), false, false);
|
||||
archive->browser, path_src, path_dst, false, false);
|
||||
archive_show_loading_popup(archive, false);
|
||||
|
||||
furi_string_free(path_dst);
|
||||
|
||||
if(error != FSE_OK) {
|
||||
FuriString* dialog_msg;
|
||||
dialog_msg = furi_string_alloc();
|
||||
@@ -98,7 +96,12 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
dialog_message_show_storage_error(
|
||||
archive->dialogs, furi_string_get_cstr(dialog_msg));
|
||||
furi_string_free(dialog_msg);
|
||||
} else {
|
||||
ArchiveFile_t* current = archive_get_current_file(archive->browser);
|
||||
if(current != NULL) furi_string_set(current->path, path_dst);
|
||||
}
|
||||
|
||||
furi_string_free(path_dst);
|
||||
scene_manager_previous_scene(archive->scene_manager);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ struct BrowserWorker {
|
||||
FuriString* path_start;
|
||||
FuriString* path_current;
|
||||
FuriString* path_next;
|
||||
int32_t item_sel_idx;
|
||||
uint32_t load_offset;
|
||||
uint32_t load_count;
|
||||
bool skip_assets;
|
||||
@@ -325,7 +324,6 @@ static int32_t browser_worker(void* context) {
|
||||
uint32_t items_cnt = 0;
|
||||
FuriString* path;
|
||||
path = furi_string_alloc_set(BROWSER_ROOT);
|
||||
browser->item_sel_idx = -1;
|
||||
|
||||
FuriString* filename;
|
||||
filename = furi_string_alloc();
|
||||
@@ -387,20 +385,22 @@ static int32_t browser_worker(void* context) {
|
||||
}
|
||||
|
||||
if(flags & WorkerEvtFolderRefresh) {
|
||||
furi_string_set(filename, browser->path_next);
|
||||
|
||||
bool is_root = browser_folder_check_and_switch(path);
|
||||
|
||||
int32_t file_idx = 0;
|
||||
furi_string_reset(filename);
|
||||
browser_folder_init(browser, path, filename, &items_cnt, &file_idx);
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"Refresh folder: %s items: %lu idx: %ld",
|
||||
furi_string_get_cstr(path),
|
||||
items_cnt,
|
||||
browser->item_sel_idx);
|
||||
file_idx);
|
||||
if(browser->folder_cb) {
|
||||
browser->folder_cb(browser->cb_ctx, items_cnt, browser->item_sel_idx, is_root);
|
||||
browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root);
|
||||
}
|
||||
furi_string_reset(filename);
|
||||
}
|
||||
|
||||
if(flags & WorkerEvtLoad) {
|
||||
@@ -517,7 +517,7 @@ void file_browser_worker_set_config(
|
||||
void file_browser_worker_folder_enter(BrowserWorker* browser, FuriString* path, int32_t item_idx) {
|
||||
furi_assert(browser);
|
||||
furi_string_set(browser->path_next, path);
|
||||
browser->item_sel_idx = item_idx;
|
||||
UNUSED(item_idx);
|
||||
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter);
|
||||
}
|
||||
|
||||
@@ -531,9 +531,13 @@ void file_browser_worker_folder_exit(BrowserWorker* browser) {
|
||||
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderExit);
|
||||
}
|
||||
|
||||
void file_browser_worker_folder_refresh(BrowserWorker* browser, int32_t item_idx) {
|
||||
void file_browser_worker_folder_refresh(BrowserWorker* browser, const char* item_name) {
|
||||
furi_assert(browser);
|
||||
browser->item_sel_idx = item_idx;
|
||||
if(item_name != NULL) {
|
||||
furi_string_set(browser->path_next, item_name);
|
||||
} else {
|
||||
furi_string_reset(browser->path_next);
|
||||
}
|
||||
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderRefresh);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ bool file_browser_worker_is_in_start_folder(BrowserWorker* browser);
|
||||
|
||||
void file_browser_worker_folder_exit(BrowserWorker* browser);
|
||||
|
||||
void file_browser_worker_folder_refresh(BrowserWorker* browser, int32_t item_idx);
|
||||
void file_browser_worker_folder_refresh(BrowserWorker* browser, const char* item_name);
|
||||
|
||||
void file_browser_worker_load(BrowserWorker* browser, uint32_t offset, uint32_t count);
|
||||
|
||||
|
||||
@@ -927,7 +927,7 @@ Function,+,file_browser_stop,void,FileBrowser*
|
||||
Function,+,file_browser_worker_alloc,BrowserWorker*,"FuriString*, const char*, const char*, _Bool, _Bool"
|
||||
Function,+,file_browser_worker_folder_enter,void,"BrowserWorker*, FuriString*, int32_t"
|
||||
Function,+,file_browser_worker_folder_exit,void,BrowserWorker*
|
||||
Function,+,file_browser_worker_folder_refresh,void,"BrowserWorker*, int32_t"
|
||||
Function,+,file_browser_worker_folder_refresh,void,"BrowserWorker*, const char*"
|
||||
Function,+,file_browser_worker_free,void,BrowserWorker*
|
||||
Function,+,file_browser_worker_is_in_start_folder,_Bool,BrowserWorker*
|
||||
Function,+,file_browser_worker_load,void,"BrowserWorker*, uint32_t, uint32_t"
|
||||
|
||||
|
Reference in New Issue
Block a user