diff --git a/applications/main/ibutton/scenes/ibutton_scene_add_value.c b/applications/main/ibutton/scenes/ibutton_scene_add_value.c index 71b852115e6..622ed5ad3fc 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_add_value.c +++ b/applications/main/ibutton/scenes/ibutton_scene_add_value.c @@ -36,7 +36,22 @@ bool ibutton_scene_add_value_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == iButtonCustomEventByteEditResult) { - scene_manager_next_scene(scene_manager, iButtonSceneSaveName); + furi_string_printf( + ibutton->file_path, + "%s/%s%s", + IBUTTON_APP_FOLDER, + ibutton->key_name, + IBUTTON_APP_FILENAME_EXTENSION); + + if(ibutton_save_key(ibutton)) { + scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSaveSuccess); + + } else { + const uint32_t possible_scenes[] = { + iButtonSceneReadKeyMenu, iButtonSceneSavedKeyMenu, iButtonSceneAddType}; + scene_manager_search_and_switch_to_previous_scene_one_of( + ibutton->scene_manager, possible_scenes, COUNT_OF(possible_scenes)); + } } else if(event.event == iButtonCustomEventByteEditChanged) { ibutton_protocols_apply_edits(ibutton->protocols, ibutton->key); } diff --git a/applications/main/ibutton/scenes/ibutton_scene_save_name.c b/applications/main/ibutton/scenes/ibutton_scene_save_name.c index e6236dc3592..522d2be786e 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_save_name.c +++ b/applications/main/ibutton/scenes/ibutton_scene_save_name.c @@ -41,9 +41,17 @@ bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) { iButton* ibutton = context; bool consumed = false; + const bool is_new_file = furi_string_empty(ibutton->file_path); + if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == iButtonCustomEventTextEditResult) { + if(!is_new_file) { + Storage* storage = furi_record_open(RECORD_STORAGE); + storage_simply_remove(storage, furi_string_get_cstr(ibutton->file_path)); + furi_record_close(RECORD_STORAGE); + } + furi_string_printf( ibutton->file_path, "%s/%s%s", diff --git a/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c b/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c index 1547a647bf1..668b79ae3c5 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c +++ b/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c @@ -6,6 +6,7 @@ enum SubmenuIndex { SubmenuIndexWriteBlank, SubmenuIndexWriteCopy, SubmenuIndexEdit, + SubmenuIndexRename, SubmenuIndexDelete, SubmenuIndexInfo, }; @@ -34,6 +35,7 @@ void ibutton_scene_saved_key_menu_on_enter(void* context) { } submenu_add_item(submenu, "Edit", SubmenuIndexEdit, ibutton_submenu_callback, ibutton); + submenu_add_item(submenu, "Rename", SubmenuIndexRename, ibutton_submenu_callback, ibutton); submenu_add_item(submenu, "Delete", SubmenuIndexDelete, ibutton_submenu_callback, ibutton); submenu_add_item(submenu, "Info", SubmenuIndexInfo, ibutton_submenu_callback, ibutton); @@ -61,6 +63,8 @@ bool ibutton_scene_saved_key_menu_on_event(void* context, SceneManagerEvent even scene_manager_next_scene(scene_manager, iButtonSceneWrite); } else if(event.event == SubmenuIndexEdit) { scene_manager_next_scene(scene_manager, iButtonSceneAddValue); + } else if(event.event == SubmenuIndexRename) { + scene_manager_next_scene(scene_manager, iButtonSceneSaveName); } else if(event.event == SubmenuIndexDelete) { scene_manager_next_scene(scene_manager, iButtonSceneDeleteConfirm); } else if(event.event == SubmenuIndexInfo) { diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c b/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c index 11a687bdd4d..5d5371e9137 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c @@ -31,8 +31,17 @@ bool lfrfid_scene_save_data_on_event(void* context, SceneManagerEvent event) { consumed = true; size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id); protocol_dict_set_data(app->dict, app->protocol_id, app->new_key_data, size); - scene_manager_next_scene(scene_manager, LfRfidSceneSaveName); - scene_manager_set_scene_state(scene_manager, LfRfidSceneSaveData, 1); + + if(!furi_string_empty(app->file_name)) { + lfrfid_delete_key(app); + } + + if(lfrfid_save_key(app)) { + scene_manager_next_scene(scene_manager, LfRfidSceneSaveSuccess); + } else { + scene_manager_search_and_switch_to_previous_scene( + scene_manager, LfRfidSceneSavedKeyMenu); + } } } else if(event.type == SceneManagerEventTypeBack) { scene_manager_set_scene_state(scene_manager, LfRfidSceneSaveData, 0); diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c b/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c index f687cd0a294..9ae789a170c 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c @@ -5,6 +5,7 @@ typedef enum { SubmenuIndexEmulate, SubmenuIndexWrite, SubmenuIndexEdit, + SubmenuIndexRename, SubmenuIndexDelete, SubmenuIndexInfo, } SubmenuIndex; @@ -25,6 +26,8 @@ void lfrfid_scene_saved_key_menu_on_enter(void* context) { submenu, "Write", SubmenuIndexWrite, lfrfid_scene_saved_key_menu_submenu_callback, app); submenu_add_item( submenu, "Edit", SubmenuIndexEdit, lfrfid_scene_saved_key_menu_submenu_callback, app); + submenu_add_item( + submenu, "Rename", SubmenuIndexRename, lfrfid_scene_saved_key_menu_submenu_callback, app); submenu_add_item( submenu, "Delete", SubmenuIndexDelete, lfrfid_scene_saved_key_menu_submenu_callback, app); submenu_add_item( @@ -51,6 +54,9 @@ bool lfrfid_scene_saved_key_menu_on_event(void* context, SceneManagerEvent event } else if(event.event == SubmenuIndexEdit) { scene_manager_next_scene(app->scene_manager, LfRfidSceneSaveData); consumed = true; + } else if(event.event == SubmenuIndexRename) { + scene_manager_next_scene(app->scene_manager, LfRfidSceneSaveName); + consumed = true; } else if(event.event == SubmenuIndexDelete) { scene_manager_next_scene(app->scene_manager, LfRfidSceneDeleteConfirm); consumed = true;