[FL-2216, FL-2233] Archive fixes (#987)
* archive: badusb, u2f and various fixes * archive: delete confirmation * badusb: removed empty string check * string pointer check * FuriHal: insomnia overflow assert, fix double insomnia exit in ble. BadUsb: fix uncommitted model. * view update fixes in gpio, badusb, u2f Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "../archive_i.h"
|
||||
#include "../helpers/archive_files.h"
|
||||
#include "../helpers/archive_apps.h"
|
||||
#include "../helpers/archive_favorites.h"
|
||||
#include "../helpers/archive_browser.h"
|
||||
#include "../views/archive_browser_view.h"
|
||||
@@ -12,29 +13,29 @@ static const char* flipper_app_name[] = {
|
||||
[ArchiveFileTypeSubGhz] = "Sub-GHz",
|
||||
[ArchiveFileTypeLFRFID] = "125 kHz RFID",
|
||||
[ArchiveFileTypeIrda] = "Infrared",
|
||||
[ArchiveFileTypeBadUsb] = "Bad USB",
|
||||
[ArchiveFileTypeU2f] = "U2F",
|
||||
};
|
||||
|
||||
static void archive_run_in_app(
|
||||
ArchiveBrowserView* browser,
|
||||
ArchiveFile_t* selected,
|
||||
bool full_path_provided) {
|
||||
static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selected) {
|
||||
Loader* loader = furi_record_open("loader");
|
||||
|
||||
string_t full_path;
|
||||
if(!full_path_provided) {
|
||||
string_init_printf(
|
||||
full_path, "%s/%s", string_get_cstr(browser->path), string_get_cstr(selected->name));
|
||||
LoaderStatus status;
|
||||
if(selected->is_app) {
|
||||
char* param = strrchr(string_get_cstr(selected->name), '/');
|
||||
if(param != NULL) {
|
||||
param++;
|
||||
}
|
||||
status = loader_start(loader, flipper_app_name[selected->type], param);
|
||||
} else {
|
||||
string_init_set(full_path, selected->name);
|
||||
status = loader_start(
|
||||
loader, flipper_app_name[selected->type], string_get_cstr(selected->name));
|
||||
}
|
||||
|
||||
LoaderStatus status =
|
||||
loader_start(loader, flipper_app_name[selected->type], string_get_cstr(full_path));
|
||||
if(status != LoaderStatusOk) {
|
||||
FURI_LOG_E(TAG, "loader_start failed: %d", status);
|
||||
}
|
||||
|
||||
string_clear(full_path);
|
||||
furi_record_close("loader");
|
||||
}
|
||||
|
||||
@@ -57,9 +58,8 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
ArchiveBrowserView* browser = archive->browser;
|
||||
ArchiveFile_t* selected = archive_get_current_file(browser);
|
||||
|
||||
const char* path = archive_get_path(browser);
|
||||
const char* name = archive_get_name(browser);
|
||||
bool known_app = is_known_app(selected->type);
|
||||
bool known_app = archive_is_known_app(selected->type);
|
||||
bool favorites = archive_get_tab(browser) == ArchiveTabFavorites;
|
||||
bool consumed = false;
|
||||
|
||||
@@ -75,7 +75,7 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
break;
|
||||
case ArchiveBrowserEventFileMenuRun:
|
||||
if(known_app) {
|
||||
archive_run_in_app(browser, selected, favorites);
|
||||
archive_run_in_app(browser, selected);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
@@ -85,10 +85,10 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
archive_file_array_rm_selected(browser);
|
||||
archive_show_file_menu(browser, false);
|
||||
} else if(known_app) {
|
||||
if(archive_is_favorite("%s/%s", path, name)) {
|
||||
archive_favorites_delete("%s/%s", path, name);
|
||||
if(archive_is_favorite("%s", name)) {
|
||||
archive_favorites_delete("%s", name);
|
||||
} else {
|
||||
archive_file_append(ARCHIVE_FAV_PATH, "%s/%s\n", path, name);
|
||||
archive_file_append(ARCHIVE_FAV_PATH, "%s\n", name);
|
||||
}
|
||||
archive_show_file_menu(browser, false);
|
||||
}
|
||||
@@ -98,18 +98,13 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
case ArchiveBrowserEventFileMenuAction:
|
||||
if(favorites) {
|
||||
browser->callback(ArchiveBrowserEventEnterFavMove, browser->context);
|
||||
} else if(known_app) {
|
||||
} else if((known_app) && (selected->is_app == false)) {
|
||||
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneRename);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventFileMenuDelete:
|
||||
if(favorites) {
|
||||
archive_delete_file(browser, "%s", name);
|
||||
} else {
|
||||
archive_delete_file(browser, "%s/%s", path, name);
|
||||
}
|
||||
archive_show_file_menu(browser, false);
|
||||
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneDelete);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventEnterDir:
|
||||
|
@@ -1,2 +1,3 @@
|
||||
ADD_SCENE(archive, browser, Browser)
|
||||
ADD_SCENE(archive, rename, Rename)
|
||||
ADD_SCENE(archive, delete, Delete)
|
||||
|
70
applications/archive/scenes/archive_scene_delete.c
Normal file
70
applications/archive/scenes/archive_scene_delete.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "../archive_i.h"
|
||||
#include "../helpers/archive_favorites.h"
|
||||
#include "../helpers/archive_files.h"
|
||||
#include "../helpers/archive_apps.h"
|
||||
#include "../helpers/archive_browser.h"
|
||||
|
||||
#define SCENE_DELETE_CUSTOM_EVENT (0UL)
|
||||
#define MAX_TEXT_INPUT_LEN 22
|
||||
|
||||
void archive_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
ArchiveApp* app = (ArchiveApp*)context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void archive_scene_delete_on_enter(void* context) {
|
||||
furi_assert(context);
|
||||
ArchiveApp* app = (ArchiveApp*)context;
|
||||
|
||||
widget_add_button_element(
|
||||
app->widget, GuiButtonTypeLeft, "Back", archive_scene_delete_widget_callback, app);
|
||||
widget_add_button_element(
|
||||
app->widget, GuiButtonTypeRight, "Delete", archive_scene_delete_widget_callback, app);
|
||||
|
||||
ArchiveFile_t* current = archive_get_current_file(app->browser);
|
||||
strlcpy(app->text_store, string_get_cstr(current->name), MAX_NAME_LEN);
|
||||
char* name = strrchr(app->text_store, '/');
|
||||
if(name != NULL) {
|
||||
name++;
|
||||
}
|
||||
|
||||
char delete_str[64];
|
||||
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", name);
|
||||
widget_add_text_box_element(app->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ArchiveViewWidget);
|
||||
}
|
||||
|
||||
bool archive_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
||||
furi_assert(context);
|
||||
ArchiveApp* app = (ArchiveApp*)context;
|
||||
|
||||
ArchiveBrowserView* browser = app->browser;
|
||||
ArchiveFile_t* selected = archive_get_current_file(browser);
|
||||
const char* name = archive_get_name(browser);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeRight) {
|
||||
if(selected->is_app) {
|
||||
archive_app_delete_file(browser, name);
|
||||
} else {
|
||||
archive_delete_file(browser, "%s", name);
|
||||
}
|
||||
archive_show_file_menu(browser, false);
|
||||
return scene_manager_previous_scene(app->scene_manager);
|
||||
} else if(event.event == GuiButtonTypeLeft) {
|
||||
return scene_manager_previous_scene(app->scene_manager);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void archive_scene_delete_on_exit(void* context) {
|
||||
furi_assert(context);
|
||||
ArchiveApp* app = (ArchiveApp*)context;
|
||||
|
||||
widget_reset(app->widget);
|
||||
}
|
@@ -52,7 +52,8 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
const char* path = archive_get_path(archive->browser);
|
||||
const char* name = archive_get_name(archive->browser);
|
||||
|
||||
string_init_printf(buffer_src, "%s/%s", path, name);
|
||||
string_init_printf(buffer_src, "%s", name);
|
||||
//TODO: take path from src name
|
||||
string_init_printf(buffer_dst, "%s/%s", path, archive->text_store);
|
||||
|
||||
// append extension
|
||||
@@ -64,7 +65,7 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
furi_record_close("storage");
|
||||
|
||||
if(file->fav) {
|
||||
archive_favorites_rename(path, name, string_get_cstr(buffer_dst));
|
||||
archive_favorites_rename(name, string_get_cstr(buffer_dst));
|
||||
}
|
||||
|
||||
string_clear(buffer_src);
|
||||
|
Reference in New Issue
Block a user