diff --git a/applications/subghz/scenes/subghz_scene_read_raw.c b/applications/subghz/scenes/subghz_scene_read_raw.c index 5323bfe58..93991cd8d 100644 --- a/applications/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/subghz/scenes/subghz_scene_read_raw.c @@ -25,7 +25,7 @@ bool subghz_scene_read_raw_update_filename(SubGhz* subghz) { break; } - strncpy(subghz->file_path, string_get_cstr(temp_str), SUBGHZ_MAX_LEN_NAME); + string_set(subghz->file_path, temp_str); ret = true; } while(false); @@ -75,13 +75,13 @@ void subghz_scene_read_raw_on_enter(void* context) { subghz_read_raw_set_status(subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, ""); break; case SubGhzRxKeyStateRAWLoad: - path_extract_filename_no_ext(subghz->file_path, file_name); + path_extract_filename(subghz->file_path, file_name, true); subghz_read_raw_set_status( subghz->subghz_read_raw, SubGhzReadRAWStatusLoadKeyTX, string_get_cstr(file_name)); subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; break; case SubGhzRxKeyStateRAWSave: - path_extract_filename_no_ext(subghz->file_path, file_name); + path_extract_filename(subghz->file_path, file_name, true); subghz_read_raw_set_status( subghz->subghz_read_raw, SubGhzReadRAWStatusSaveKey, string_get_cstr(file_name)); subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; @@ -170,10 +170,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWErase: subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; - if(subghz_scene_read_raw_update_filename(subghz)) { - strncpy(subghz->file_path_tmp, subghz->file_path, SUBGHZ_MAX_LEN_NAME); - subghz_delete_file(subghz); - } notification_message(subghz->notifications, &sequence_reset_rgb); return true; break; @@ -253,7 +249,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { ); string_printf( - temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, strings[0], SUBGHZ_APP_EXTENSION); + temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, RAW_FILE_NAME, SUBGHZ_APP_EXTENSION); subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, string_get_cstr(temp_str)); string_clear(temp_str); @@ -284,7 +280,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if(subghz_protocol_raw_save_to_file_init( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, - strings[0], + RAW_FILE_NAME,, subghz->txrx->frequency, subghz->txrx->preset)) { DOLPHIN_DEED(DolphinDeedSubGhzRawRec); @@ -296,7 +292,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->state_notifications = SubGhzNotificationStateRx; subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; } else { - string_set(subghz->error_str, "Function requires\nan SD card."); + string_set_str(subghz->error_str, "Function requires\nan SD card."); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } } @@ -350,4 +346,4 @@ void subghz_scene_read_raw_on_exit(void* context) { //filter restoration subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); -} +} \ No newline at end of file diff --git a/applications/subghz/scenes/subghz_scene_set_type.c b/applications/subghz/scenes/subghz_scene_set_type.c index 206863f4d..a2034e976 100644 --- a/applications/subghz/scenes/subghz_scene_set_type.c +++ b/applications/subghz/scenes/subghz_scene_set_type.c @@ -49,7 +49,7 @@ bool subghz_scene_set_type_submenu_gen_data_protocol( subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, protocol_name); if(subghz->txrx->decoder_result == NULL) { - string_set(subghz->error_str, "Protocol not found"); + string_set_str(subghz->error_str, "Protocol not found"); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub); return false; } @@ -340,7 +340,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } subghz_transmitter_free(subghz->txrx->transmitter); if(!generated_protocol) { - string_set( + string_set_str( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } @@ -364,7 +364,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { } subghz_transmitter_free(subghz->txrx->transmitter); if(!generated_protocol) { - string_set( + string_set_str( subghz->error_str, "Function requires\nan SD card with\nfresh databases."); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } @@ -472,4 +472,4 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { void subghz_scene_set_type_on_exit(void* context) { SubGhz* subghz = context; submenu_reset(subghz->submenu); -} +} \ No newline at end of file diff --git a/applications/subghz/subghz.c b/applications/subghz/subghz.c index 99c9db452..2dd573eee 100644 --- a/applications/subghz/subghz.c +++ b/applications/subghz/subghz.c @@ -1,5 +1,7 @@ /* Abandon hope, all ye who enter here. */ +#include "m-string.h" +#include "subghz/types.h" #include "subghz_i.h" #include @@ -24,6 +26,9 @@ void subghz_tick_event_callback(void* context) { SubGhz* subghz_alloc() { SubGhz* subghz = malloc(sizeof(SubGhz)); + string_init(subghz->file_path); + string_init(subghz->file_path_tmp); + // GUI subghz->gui = furi_record_open("gui"); @@ -251,9 +256,9 @@ void subghz_free(SubGhz* subghz) { furi_record_close("notification"); subghz->notifications = NULL; - // About birds - furi_assert(subghz->file_path[SUBGHZ_MAX_LEN_NAME] == 0); - furi_assert(subghz->file_path_tmp[SUBGHZ_MAX_LEN_NAME] == 0); + // Path strings + string_clear(subghz->file_path); + string_clear(subghz->file_path_tmp); // The rest free(subghz); @@ -270,7 +275,7 @@ int32_t subghz_app(void* p) { // Check argument and run corresponding scene if(p) { if(subghz_key_load(subghz, p)) { - strncpy(subghz->file_path, p, SUBGHZ_MAX_LEN_NAME); + string_set_str(subghz->file_path, p); if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) { //Load Raw TX @@ -286,12 +291,13 @@ int32_t subghz_app(void* p) { view_dispatcher_stop(subghz->view_dispatcher); } } else { + string_set_str(subghz->file_path, SUBGHZ_APP_FOLDER); if(load_database) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart); } else { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneShowError, SubGhzCustomEventManagerSet); - string_set( + string_set_str( subghz->error_str, "No SD card or\ndatabase found.\nSome app function\nmay be reduced."); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); @@ -307,4 +313,4 @@ int32_t subghz_app(void* p) { subghz_free(subghz); return 0; -} +} \ No newline at end of file diff --git a/applications/subghz/subghz_i.h b/applications/subghz/subghz_i.h index b1a932836..8a2f0b8bc 100644 --- a/applications/subghz/subghz_i.h +++ b/applications/subghz/subghz_i.h @@ -36,7 +36,7 @@ #include #include -#define SUBGHZ_MAX_LEN_NAME 250 +#define SUBGHZ_MAX_LEN_NAME 64 /** SubGhzNotification state */ typedef enum { @@ -128,10 +128,9 @@ struct SubGhz { ByteInput* byte_input; Widget* widget; DialogsApp* dialogs; - char file_path[SUBGHZ_MAX_LEN_NAME + 1]; - char file_path_tmp[SUBGHZ_MAX_LEN_NAME + 1]; - //ToDo you can get rid of it, you need to refactor text input to return the path to the folder - char file_dir[SUBGHZ_MAX_LEN_NAME + 1]; + string_t file_path; + string_t file_path_tmp; + char file_name_tmp[SUBGHZ_MAX_LEN_NAME]; SubGhzNotificationState state_notifications; SubGhzViewReceiver* subghz_receiver; @@ -183,5 +182,6 @@ bool subghz_load_protocol_from_file(SubGhz* subghz); bool subghz_rename_file(SubGhz* subghz); bool subghz_delete_file(SubGhz* subghz); void subghz_file_name_clear(SubGhz* subghz); +bool subghz_path_is_file(string_t path); uint32_t subghz_random_serial(void); -void subghz_hopper_update(SubGhz* subghz); +void subghz_hopper_update(SubGhz* subghz); \ No newline at end of file