Skip to content

Commit

Permalink
Fix iButton crash on missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
gsurkov committed Nov 10, 2023
1 parent 49dcf81 commit b085876
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions applications/main/ibutton/ibutton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion applications/main/ibutton/ibutton_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion applications/main/ibutton/scenes/ibutton_scene_add_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion applications/main/ibutton/scenes/ibutton_scene_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b085876

Please sign in to comment.