From 615a1479734ecf2e03626153f60dc267800cc429 Mon Sep 17 00:00:00 2001 From: Georgii Surkov <37121527+gsurkov@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:45:41 +0300 Subject: [PATCH] [FL-3608] Fix iButton crash on missing file (#3210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- applications/main/ibutton/ibutton.c | 13 ++++++------- applications/main/ibutton/ibutton_i.h | 2 +- .../main/ibutton/scenes/ibutton_scene_add_value.c | 2 +- .../main/ibutton/scenes/ibutton_scene_rpc.c | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/applications/main/ibutton/ibutton.c b/applications/main/ibutton/ibutton.c index fb6d9dcb5..afd51f7c9 100644 --- a/applications/main/ibutton/ibutton.c +++ b/applications/main/ibutton/ibutton.c @@ -174,22 +174,21 @@ void ibutton_free(iButton* ibutton) { free(ibutton); } -bool ibutton_load_key(iButton* ibutton) { +bool ibutton_load_key(iButton* ibutton, bool show_error) { view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewLoading); const bool success = ibutton_protocols_load( ibutton->protocols, ibutton->key, furi_string_get_cstr(ibutton->file_path)); - if(!success) { - dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file"); - - } else { + if(success) { FuriString* tmp = furi_string_alloc(); path_extract_filename(ibutton->file_path, tmp, true); strncpy(ibutton->key_name, furi_string_get_cstr(tmp), IBUTTON_KEY_NAME_SIZE); furi_string_free(tmp); + } else if(show_error) { + dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file"); } return success; @@ -210,7 +209,7 @@ bool ibutton_select_and_load_key(iButton* ibutton) { if(!dialog_file_browser_show( ibutton->dialogs, ibutton->file_path, ibutton->file_path, &browser_options)) break; - success = ibutton_load_key(ibutton); + success = ibutton_load_key(ibutton, true); } while(!success); return success; @@ -283,7 +282,7 @@ int32_t ibutton_app(void* arg) { } else { furi_string_set(ibutton->file_path, (const char*)arg); - key_loaded = ibutton_load_key(ibutton); + key_loaded = ibutton_load_key(ibutton, true); } } diff --git a/applications/main/ibutton/ibutton_i.h b/applications/main/ibutton/ibutton_i.h index 077b14807..c6a35f888 100644 --- a/applications/main/ibutton/ibutton_i.h +++ b/applications/main/ibutton/ibutton_i.h @@ -90,7 +90,7 @@ typedef enum { } iButtonNotificationMessage; bool ibutton_select_and_load_key(iButton* ibutton); -bool ibutton_load_key(iButton* ibutton); +bool ibutton_load_key(iButton* ibutton, bool show_error); bool ibutton_save_key(iButton* ibutton); bool ibutton_delete_key(iButton* ibutton); void ibutton_reset_key(iButton* ibutton); diff --git a/applications/main/ibutton/scenes/ibutton_scene_add_value.c b/applications/main/ibutton/scenes/ibutton_scene_add_value.c index dc340771b..71b852115 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_add_value.c +++ b/applications/main/ibutton/scenes/ibutton_scene_add_value.c @@ -43,7 +43,7 @@ bool ibutton_scene_add_value_on_event(void* context, SceneManagerEvent event) { } else if(event.type == SceneManagerEventTypeBack) { // User cancelled editing, reload the key from storage if(scene_manager_has_previous_scene(scene_manager, iButtonSceneSavedKeyMenu)) { - if(!ibutton_load_key(ibutton)) { + if(!ibutton_load_key(ibutton, true)) { consumed = scene_manager_search_and_switch_to_previous_scene( scene_manager, iButtonSceneStart); } diff --git a/applications/main/ibutton/scenes/ibutton_scene_rpc.c b/applications/main/ibutton/scenes/ibutton_scene_rpc.c index 7106fefaa..f4f193a47 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_rpc.c +++ b/applications/main/ibutton/scenes/ibutton_scene_rpc.c @@ -26,7 +26,7 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) { if(event.event == iButtonCustomEventRpcLoadFile) { bool result = false; - if(ibutton_load_key(ibutton)) { + if(ibutton_load_key(ibutton, false)) { popup_set_text(popup, ibutton->key_name, 82, 32, AlignCenter, AlignTop); view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);