2022-09-24 17:47:21 +00:00
|
|
|
#include "../subbrute_i.h"
|
2022-09-30 14:36:56 +00:00
|
|
|
#include "subbrute_scene.h"
|
2022-09-25 17:31:33 +00:00
|
|
|
|
|
|
|
#define TAG "SubBruteSceneLoadFile"
|
2022-09-24 17:47:21 +00:00
|
|
|
|
|
|
|
//void subbrute_scene_load_file_callback(SubBruteCustomEvent event, void* context) {
|
|
|
|
//// furi_assert(context);
|
|
|
|
////
|
|
|
|
//// SubBruteState* instance = (SubBruteState*)context;
|
|
|
|
//// view_dispatcher_send_custom_event(instance->view_dispatcher, event);
|
|
|
|
//}
|
|
|
|
|
|
|
|
void subbrute_scene_load_file_on_enter(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubBruteState* instance = (SubBruteState*)context;
|
2022-09-25 17:31:33 +00:00
|
|
|
|
|
|
|
// Input events and views are managed by file_browser
|
2022-10-05 18:27:13 +00:00
|
|
|
FuriString* app_folder;
|
|
|
|
FuriString* load_path;
|
|
|
|
load_path = furi_string_alloc();
|
|
|
|
app_folder = furi_string_alloc_set(SUBBRUTE_PATH);
|
2022-09-24 17:47:21 +00:00
|
|
|
|
|
|
|
DialogsFileBrowserOptions browser_options;
|
|
|
|
dialog_file_browser_set_basic_options(&browser_options, SUBBRUTE_FILE_EXT, &I_sub1_10px);
|
|
|
|
|
2022-09-25 17:31:33 +00:00
|
|
|
SubBruteFileResult load_result = SubBruteFileResultUnknown;
|
|
|
|
bool res =
|
|
|
|
dialog_file_browser_show(instance->dialogs, load_path, app_folder, &browser_options);
|
|
|
|
#ifdef FURI_DEBUG
|
|
|
|
FURI_LOG_D(
|
|
|
|
TAG,
|
|
|
|
"load_path: %s, app_folder: %s",
|
2022-10-05 18:27:13 +00:00
|
|
|
furi_string_get_cstr(load_path),
|
|
|
|
furi_string_get_cstr(app_folder));
|
2022-09-25 17:31:33 +00:00
|
|
|
#endif
|
2022-09-24 17:47:21 +00:00
|
|
|
if(res) {
|
2022-10-07 22:24:19 +00:00
|
|
|
load_result =
|
|
|
|
subbrute_device_load_from_file(instance->device, furi_string_get_cstr(load_path));
|
2022-09-24 17:47:21 +00:00
|
|
|
if(load_result == SubBruteFileResultOk) {
|
2022-09-25 17:31:33 +00:00
|
|
|
load_result = subbrute_device_attack_set(instance->device, SubBruteAttackLoadFile);
|
|
|
|
if(load_result == SubBruteFileResultOk) {
|
|
|
|
// Ready to run!
|
|
|
|
FURI_LOG_I(TAG, "Ready to run");
|
|
|
|
res = true;
|
|
|
|
}
|
2022-09-24 17:47:21 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 17:01:14 +00:00
|
|
|
if(load_result == SubBruteFileResultOk) {
|
|
|
|
scene_manager_next_scene(instance->scene_manager, SubBruteSceneLoadSelect);
|
|
|
|
} else {
|
|
|
|
FURI_LOG_E(TAG, "Returned error: %d", load_result);
|
2022-09-24 17:47:21 +00:00
|
|
|
|
2022-10-05 18:27:13 +00:00
|
|
|
FuriString* dialog_msg;
|
|
|
|
dialog_msg = furi_string_alloc();
|
2022-10-07 22:24:19 +00:00
|
|
|
furi_string_cat_printf(dialog_msg, "Cannot parse\nfile: %s", subbrute_device_error_get_desc(load_result));
|
2022-10-05 18:27:13 +00:00
|
|
|
dialog_message_show_storage_error(instance->dialogs, furi_string_get_cstr(dialog_msg));
|
|
|
|
furi_string_free(dialog_msg);
|
2022-09-26 17:01:14 +00:00
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
|
|
instance->scene_manager, SubBruteSceneStart);
|
|
|
|
}
|
|
|
|
} else {
|
2022-09-24 17:47:21 +00:00
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
2022-09-25 17:31:33 +00:00
|
|
|
instance->scene_manager, SubBruteSceneStart);
|
2022-09-24 17:47:21 +00:00
|
|
|
}
|
2022-09-25 17:31:33 +00:00
|
|
|
|
2022-10-05 18:27:13 +00:00
|
|
|
furi_string_free(app_folder);
|
|
|
|
furi_string_free(load_path);
|
2022-09-24 17:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subbrute_scene_load_file_on_exit(void* context) {
|
|
|
|
UNUSED(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool subbrute_scene_load_file_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
UNUSED(context);
|
|
|
|
UNUSED(event);
|
|
|
|
return false;
|
|
|
|
}
|