[FL-3608] Fix iButton crash on missing file (#3210)
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									c00776ca22
								
							
						
					
					
						commit
						615a147973
					
				| @ -174,22 +174,21 @@ void ibutton_free(iButton* ibutton) { | |||||||
|     free(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); |     view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewLoading); | ||||||
| 
 | 
 | ||||||
|     const bool success = ibutton_protocols_load( |     const bool success = ibutton_protocols_load( | ||||||
|         ibutton->protocols, ibutton->key, furi_string_get_cstr(ibutton->file_path)); |         ibutton->protocols, ibutton->key, furi_string_get_cstr(ibutton->file_path)); | ||||||
| 
 | 
 | ||||||
|     if(!success) { |     if(success) { | ||||||
|         dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file"); |  | ||||||
| 
 |  | ||||||
|     } else { |  | ||||||
|         FuriString* tmp = furi_string_alloc(); |         FuriString* tmp = furi_string_alloc(); | ||||||
| 
 | 
 | ||||||
|         path_extract_filename(ibutton->file_path, tmp, true); |         path_extract_filename(ibutton->file_path, tmp, true); | ||||||
|         strncpy(ibutton->key_name, furi_string_get_cstr(tmp), IBUTTON_KEY_NAME_SIZE); |         strncpy(ibutton->key_name, furi_string_get_cstr(tmp), IBUTTON_KEY_NAME_SIZE); | ||||||
| 
 | 
 | ||||||
|         furi_string_free(tmp); |         furi_string_free(tmp); | ||||||
|  |     } else if(show_error) { | ||||||
|  |         dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return success; |     return success; | ||||||
| @ -210,7 +209,7 @@ bool ibutton_select_and_load_key(iButton* ibutton) { | |||||||
|         if(!dialog_file_browser_show( |         if(!dialog_file_browser_show( | ||||||
|                ibutton->dialogs, ibutton->file_path, ibutton->file_path, &browser_options)) |                ibutton->dialogs, ibutton->file_path, ibutton->file_path, &browser_options)) | ||||||
|             break; |             break; | ||||||
|         success = ibutton_load_key(ibutton); |         success = ibutton_load_key(ibutton, true); | ||||||
|     } while(!success); |     } while(!success); | ||||||
| 
 | 
 | ||||||
|     return success; |     return success; | ||||||
| @ -283,7 +282,7 @@ int32_t ibutton_app(void* arg) { | |||||||
| 
 | 
 | ||||||
|         } else { |         } else { | ||||||
|             furi_string_set(ibutton->file_path, (const char*)arg); |             furi_string_set(ibutton->file_path, (const char*)arg); | ||||||
|             key_loaded = ibutton_load_key(ibutton); |             key_loaded = ibutton_load_key(ibutton, true); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -90,7 +90,7 @@ typedef enum { | |||||||
| } iButtonNotificationMessage; | } iButtonNotificationMessage; | ||||||
| 
 | 
 | ||||||
| bool ibutton_select_and_load_key(iButton* ibutton); | 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_save_key(iButton* ibutton); | ||||||
| bool ibutton_delete_key(iButton* ibutton); | bool ibutton_delete_key(iButton* ibutton); | ||||||
| void ibutton_reset_key(iButton* ibutton); | void ibutton_reset_key(iButton* ibutton); | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ bool ibutton_scene_add_value_on_event(void* context, SceneManagerEvent event) { | |||||||
|     } else if(event.type == SceneManagerEventTypeBack) { |     } else if(event.type == SceneManagerEventTypeBack) { | ||||||
|         // User cancelled editing, reload the key from storage
 |         // User cancelled editing, reload the key from storage
 | ||||||
|         if(scene_manager_has_previous_scene(scene_manager, iButtonSceneSavedKeyMenu)) { |         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( |                 consumed = scene_manager_search_and_switch_to_previous_scene( | ||||||
|                     scene_manager, iButtonSceneStart); |                     scene_manager, iButtonSceneStart); | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) { | |||||||
|         if(event.event == iButtonCustomEventRpcLoadFile) { |         if(event.event == iButtonCustomEventRpcLoadFile) { | ||||||
|             bool result = false; |             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); |                 popup_set_text(popup, ibutton->key_name, 82, 32, AlignCenter, AlignTop); | ||||||
|                 view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup); |                 view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Georgii Surkov
						Georgii Surkov