[FL-2491] File browser GUI module (#1237)
* File browser module and test app * nfc: Add support for saved files in subdirectories * nfc: Use helper function to get shadow path when loading data * File browser dialog integration pt.1 * File browser dialog integration pt.2 * Gui,Dialogs: drop file select * Correct use of dynamic string_t(string_ptr) Co-authored-by: Yukai Li <yukaili.geek@gmail.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "bad_usb_app_i.h"
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <storage/storage.h>
|
||||
@@ -22,33 +23,13 @@ static void bad_usb_app_tick_event_callback(void* context) {
|
||||
scene_manager_handle_tick_event(app->scene_manager);
|
||||
}
|
||||
|
||||
static bool bad_usb_check_assets() {
|
||||
Storage* fs_api = furi_record_open("storage");
|
||||
|
||||
File* dir = storage_file_alloc(fs_api);
|
||||
bool ret = false;
|
||||
|
||||
if(storage_dir_open(dir, BAD_USB_APP_PATH_FOLDER)) {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
storage_dir_close(dir);
|
||||
storage_file_free(dir);
|
||||
|
||||
furi_record_close("storage");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BadUsbApp* bad_usb_app_alloc(char* arg) {
|
||||
BadUsbApp* app = malloc(sizeof(BadUsbApp));
|
||||
|
||||
string_init(app->file_path);
|
||||
|
||||
if(arg != NULL) {
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
path_extract_filename_no_ext(arg, filename);
|
||||
strncpy(app->file_name, string_get_cstr(filename), BAD_USB_FILE_NAME_LEN);
|
||||
string_clear(filename);
|
||||
string_set_str(app->file_path, arg);
|
||||
}
|
||||
|
||||
app->gui = furi_record_open("gui");
|
||||
@@ -83,13 +64,11 @@ BadUsbApp* bad_usb_app_alloc(char* arg) {
|
||||
app->error = BadUsbAppErrorCloseRpc;
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
|
||||
} else {
|
||||
if(*app->file_name != '\0') {
|
||||
if(!string_empty_p(app->file_path)) {
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneWork);
|
||||
} else if(bad_usb_check_assets()) {
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
|
||||
} else {
|
||||
app->error = BadUsbAppErrorNoFiles;
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
|
||||
string_set_str(app->file_path, BAD_USB_APP_PATH_FOLDER);
|
||||
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +96,8 @@ void bad_usb_app_free(BadUsbApp* app) {
|
||||
furi_record_close("notification");
|
||||
furi_record_close("dialogs");
|
||||
|
||||
string_clear(app->file_path);
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
#define BAD_USB_APP_PATH_FOLDER "/any/badusb"
|
||||
#define BAD_USB_APP_EXTENSION ".txt"
|
||||
#define BAD_USB_FILE_NAME_LEN 40
|
||||
|
||||
typedef enum {
|
||||
BadUsbAppErrorNoFiles,
|
||||
@@ -32,7 +31,7 @@ struct BadUsbApp {
|
||||
Widget* widget;
|
||||
|
||||
BadUsbAppError error;
|
||||
char file_name[BAD_USB_FILE_NAME_LEN + 1];
|
||||
string_t file_path;
|
||||
BadUsb* bad_usb_view;
|
||||
BadUsbScript* bad_usb_script;
|
||||
};
|
||||
|
@@ -5,14 +5,16 @@
|
||||
static bool bad_usb_file_select(BadUsbApp* bad_usb) {
|
||||
furi_assert(bad_usb);
|
||||
|
||||
// Input events and views are managed by file_select
|
||||
bool res = dialog_file_select_show(
|
||||
// Input events and views are managed by file_browser
|
||||
bool res = dialog_file_browser_show(
|
||||
bad_usb->dialogs,
|
||||
BAD_USB_APP_PATH_FOLDER,
|
||||
bad_usb->file_path,
|
||||
bad_usb->file_path,
|
||||
BAD_USB_APP_EXTENSION,
|
||||
bad_usb->file_name,
|
||||
sizeof(bad_usb->file_name),
|
||||
NULL);
|
||||
true,
|
||||
&I_badusb_10px,
|
||||
true);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,8 @@
|
||||
#include "../bad_usb_app_i.h"
|
||||
#include "../views/bad_usb_view.h"
|
||||
#include "furi_hal.h"
|
||||
#include "m-string.h"
|
||||
#include "toolbox/path.h"
|
||||
|
||||
void bad_usb_scene_work_ok_callback(InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
@@ -28,10 +30,9 @@ void bad_usb_scene_work_on_enter(void* context) {
|
||||
string_t file_name;
|
||||
string_init(file_name);
|
||||
|
||||
bad_usb_set_file_name(app->bad_usb_view, app->file_name);
|
||||
string_printf(
|
||||
file_name, "%s/%s%s", BAD_USB_APP_PATH_FOLDER, app->file_name, BAD_USB_APP_EXTENSION);
|
||||
app->bad_usb_script = bad_usb_script_open(file_name);
|
||||
path_extract_filename(app->file_path, file_name, true);
|
||||
bad_usb_set_file_name(app->bad_usb_view, string_get_cstr(file_name));
|
||||
app->bad_usb_script = bad_usb_script_open(app->file_path);
|
||||
|
||||
string_clear(file_name);
|
||||
|
||||
|
@@ -2,6 +2,8 @@
|
||||
#include "../bad_usb_script.h"
|
||||
#include <gui/elements.h>
|
||||
|
||||
#define MAX_NAME_LEN 64
|
||||
|
||||
struct BadUsb {
|
||||
View* view;
|
||||
BadUsbOkCallback callback;
|
||||
@@ -9,7 +11,7 @@ struct BadUsb {
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char* file_name;
|
||||
char file_name[MAX_NAME_LEN];
|
||||
BadUsbState state;
|
||||
uint8_t anim_frame;
|
||||
} BadUsbModel;
|
||||
@@ -149,11 +151,11 @@ void bad_usb_set_ok_callback(BadUsb* bad_usb, BadUsbOkCallback callback, void* c
|
||||
});
|
||||
}
|
||||
|
||||
void bad_usb_set_file_name(BadUsb* bad_usb, char* name) {
|
||||
void bad_usb_set_file_name(BadUsb* bad_usb, const char* name) {
|
||||
furi_assert(name);
|
||||
with_view_model(
|
||||
bad_usb->view, (BadUsbModel * model) {
|
||||
model->file_name = name;
|
||||
strncpy(model->file_name, name, MAX_NAME_LEN);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@@ -14,6 +14,6 @@ View* bad_usb_get_view(BadUsb* bad_usb);
|
||||
|
||||
void bad_usb_set_ok_callback(BadUsb* bad_usb, BadUsbOkCallback callback, void* context);
|
||||
|
||||
void bad_usb_set_file_name(BadUsb* bad_usb, char* name);
|
||||
void bad_usb_set_file_name(BadUsb* bad_usb, const char* name);
|
||||
|
||||
void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st);
|
||||
|
Reference in New Issue
Block a user