diff --git a/applications/main/bad_kb/bad_kb_app.c b/applications/main/bad_kb/bad_kb_app.c index 4ee226481..d5a1ae27c 100644 --- a/applications/main/bad_kb/bad_kb_app.c +++ b/applications/main/bad_kb/bad_kb_app.c @@ -108,6 +108,17 @@ static void bad_kb_save_settings(BadKbApp* app) { furi_record_close(RECORD_STORAGE); } +void bad_kb_app_show_loading_popup(BadKbApp* app, bool show) { + if(show) { + // Raise timer priority so that animations can play + furi_timer_set_thread_priority(FuriTimerThreadPriorityElevated); + view_dispatcher_switch_to_view(app->view_dispatcher, BadKbAppViewLoading); + } else { + // Restore default timer priority + furi_timer_set_thread_priority(FuriTimerThreadPriorityNormal); + } +} + BadKbApp* bad_kb_app_alloc(char* arg) { BadKbApp* app = malloc(sizeof(BadKbApp)); @@ -119,11 +130,6 @@ BadKbApp* bad_kb_app_alloc(char* arg) { furi_string_set(app->file_path, arg); } - Storage* storage = furi_record_open(RECORD_STORAGE); - storage_common_rename_safe(storage, EXT_PATH("badusb"), BAD_KB_APP_BASE_FOLDER); - storage_simply_mkdir(storage, BAD_KB_APP_BASE_FOLDER); - furi_record_close(RECORD_STORAGE); - bad_kb_load_settings(app); app->gui = furi_record_open(RECORD_GUI); @@ -184,6 +190,10 @@ BadKbApp* bad_kb_app_alloc(char* arg) { view_dispatcher_add_view( app->view_dispatcher, BadKbAppViewByteInput, byte_input_get_view(app->byte_input)); + app->loading = loading_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, BadKbAppViewLoading, loading_get_view(app->loading)); + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); app->conn_mode = BadKbConnModeNone; @@ -230,6 +240,10 @@ void bad_kb_app_free(BadKbApp* app) { view_dispatcher_remove_view(app->view_dispatcher, BadKbAppViewByteInput); byte_input_free(app->byte_input); + // Loading + view_dispatcher_remove_view(app->view_dispatcher, BadKbAppViewLoading); + loading_free(app->loading); + // View dispatcher view_dispatcher_free(app->view_dispatcher); scene_manager_free(app->scene_manager); diff --git a/applications/main/bad_kb/bad_kb_app.h b/applications/main/bad_kb/bad_kb_app.h index e2786d301..08945b832 100644 --- a/applications/main/bad_kb/bad_kb_app.h +++ b/applications/main/bad_kb/bad_kb_app.h @@ -23,5 +23,8 @@ typedef enum { BadKbAppViewWork, BadKbAppViewVarItemList, BadKbAppViewByteInput, - BadKbAppViewTextInput + BadKbAppViewTextInput, + BadKbAppViewLoading, } BadKbAppView; + +void bad_kb_app_show_loading_popup(BadKbApp* app, bool show); diff --git a/applications/main/bad_kb/helpers/ducky_script.h b/applications/main/bad_kb/helpers/ducky_script.h index 7ed928efe..a4a3ef7b4 100644 --- a/applications/main/bad_kb/helpers/ducky_script.h +++ b/applications/main/bad_kb/helpers/ducky_script.h @@ -13,6 +13,7 @@ extern "C" { #include #include #include +#include #include "../views/bad_kb_view.h" #include "../bad_kb_paths.h" @@ -137,6 +138,7 @@ struct BadKbApp { VariableItemList* var_item_list; TextInput* text_input; ByteInput* byte_input; + Loading* loading; char usb_name_buf[BAD_KB_USB_LEN]; uint16_t usb_vidpid_buf[2]; char bt_name_buf[BAD_KB_NAME_LEN]; diff --git a/applications/main/bad_kb/scenes/bad_kb_scene_file_select.c b/applications/main/bad_kb/scenes/bad_kb_scene_file_select.c index 635b4f318..3dd9f669c 100644 --- a/applications/main/bad_kb/scenes/bad_kb_scene_file_select.c +++ b/applications/main/bad_kb/scenes/bad_kb_scene_file_select.c @@ -6,6 +6,32 @@ static bool bad_kb_file_select(BadKbApp* bad_kb) { furi_assert(bad_kb); + bad_kb_app_show_loading_popup(bad_kb, true); + Storage* storage = furi_record_open(RECORD_STORAGE); + if(storage_dir_exists(storage, EXT_PATH("badusb"))) { + DialogMessage* message = dialog_message_alloc(); + dialog_message_set_header(message, "Migrate BadUSB?", 64, 0, AlignCenter, AlignTop); + dialog_message_set_buttons(message, "No", NULL, "Yes"); + dialog_message_set_text( + message, + "A badusb folder was found!\n" + "XFW uses the badkb folder.\n" + "Want to transfer the files?", + 64, + 32, + AlignCenter, + AlignCenter); + DialogMessageButton res = dialog_message_show(furi_record_open(RECORD_DIALOGS), message); + dialog_message_free(message); + furi_record_close(RECORD_DIALOGS); + if(res == DialogMessageButtonRight) { + storage_common_migrate(storage, EXT_PATH("badusb"), BAD_KB_APP_BASE_FOLDER); + } + } + storage_simply_mkdir(storage, BAD_KB_APP_BASE_FOLDER); + furi_record_close(RECORD_STORAGE); + bad_kb_app_show_loading_popup(bad_kb, false); + DialogsFileBrowserOptions browser_options; dialog_file_browser_set_basic_options( &browser_options, BAD_KB_APP_SCRIPT_EXTENSION, &I_badkb_10px);