mirror of
https://protopirate.net/ProtoPirate/ProtoPirate.git
synced 2026-10-06 17:47:19 +00:00
Get rid of always allocated 64 byte save_flename
This commit is contained in:
+6
-1
@@ -185,7 +185,7 @@ ProtoPirateApp* protopirate_app_alloc() {
|
||||
app->save_protocol = NULL;
|
||||
app->save_history_idx = 0;
|
||||
app->emulate_disabled_for_loaded = false;
|
||||
memset(app->save_filename, 0, sizeof(app->save_filename));
|
||||
app->save_filename = NULL;
|
||||
|
||||
// File Browser path
|
||||
app->file_path = furi_string_alloc();
|
||||
@@ -410,6 +410,11 @@ void protopirate_app_free(ProtoPirateApp* app) {
|
||||
|
||||
protopirate_views_free(app);
|
||||
|
||||
if(app->save_filename) {
|
||||
free(app->save_filename);
|
||||
app->save_filename = NULL;
|
||||
}
|
||||
|
||||
if(app->file_path) {
|
||||
FURI_LOG_D(TAG, "Freeing file_path");
|
||||
furi_string_free(app->file_path);
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ struct ProtoPirateApp {
|
||||
uint8_t emulate_feature_enabled : 1;
|
||||
uint32_t start_tx_time;
|
||||
uint8_t tx_power;
|
||||
char save_filename[64];
|
||||
char* save_filename;
|
||||
FuriString* save_protocol;
|
||||
uint16_t save_history_idx;
|
||||
PluginManager* plugin_manager;
|
||||
|
||||
@@ -315,13 +315,16 @@ bool protopirate_scene_receiver_info_on_event(void* context, SceneManagerEvent e
|
||||
size_t name_len = strlen(name_start);
|
||||
const char* dot = strrchr(name_start, '.');
|
||||
if(dot) name_len = dot - name_start;
|
||||
if(name_len >= sizeof(app->save_filename))
|
||||
name_len = sizeof(app->save_filename) - 1;
|
||||
if(name_len >= 64) name_len = 64;
|
||||
|
||||
if(app->save_filename) free(app->save_filename);
|
||||
app->save_filename = malloc(name_len + 1);
|
||||
memcpy(app->save_filename, name_start, name_len);
|
||||
app->save_filename[name_len] = '\0';
|
||||
} else {
|
||||
snprintf(app->save_filename, sizeof(app->save_filename), "capture");
|
||||
if(app->save_filename) free(app->save_filename);
|
||||
uint8_t len = 8;
|
||||
app->save_filename = malloc(len);
|
||||
snprintf(app->save_filename, len, "capture");
|
||||
}
|
||||
furi_string_free(auto_path);
|
||||
|
||||
@@ -338,7 +341,7 @@ bool protopirate_scene_receiver_info_on_event(void* context, SceneManagerEvent e
|
||||
protopirate_scene_receiver_info_text_input_callback,
|
||||
app,
|
||||
app->save_filename,
|
||||
sizeof(app->save_filename),
|
||||
strlen(app->save_filename),
|
||||
false); // don't clear default text
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ProtoPirateViewTextInput);
|
||||
@@ -377,6 +380,19 @@ bool protopirate_scene_receiver_info_on_event(void* context, SceneManagerEvent e
|
||||
|
||||
// Return to the receiver info widget
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ProtoPirateViewWidget);
|
||||
|
||||
//Kill the text_input view.
|
||||
if(app->text_input) {
|
||||
FURI_LOG_D(TAG, "Removing text_input view");
|
||||
view_dispatcher_remove_view(app->view_dispatcher, ProtoPirateViewTextInput);
|
||||
text_input_free(app->text_input);
|
||||
app->text_input = NULL;
|
||||
}
|
||||
|
||||
if(app->save_filename) {
|
||||
free(app->save_filename);
|
||||
app->save_filename = NULL;
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -677,13 +677,16 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
|
||||
size_t name_len = strlen(name_start);
|
||||
const char* dot = strrchr(name_start, '.');
|
||||
if(dot) name_len = dot - name_start;
|
||||
if(name_len >= sizeof(app->save_filename))
|
||||
name_len = sizeof(app->save_filename) - 1;
|
||||
if(name_len > 64) name_len = 64;
|
||||
|
||||
if(app->save_filename) free(app->save_filename);
|
||||
app->save_filename = malloc(name_len + 1);
|
||||
memcpy(app->save_filename, name_start, name_len);
|
||||
app->save_filename[name_len] = '\0';
|
||||
} else {
|
||||
snprintf(app->save_filename, sizeof(app->save_filename), "capture");
|
||||
if(app->save_filename) free(app->save_filename);
|
||||
uint8_t len = 8;
|
||||
app->save_filename = malloc(len);
|
||||
snprintf(app->save_filename, len, "capture");
|
||||
}
|
||||
furi_string_free(auto_path);
|
||||
|
||||
@@ -705,7 +708,7 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
|
||||
protopirate_scene_sub_decode_text_input_callback,
|
||||
app,
|
||||
app->save_filename,
|
||||
sizeof(app->save_filename),
|
||||
strlen(app->save_filename),
|
||||
false); // don't clear default text
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ProtoPirateViewTextInput);
|
||||
@@ -750,6 +753,11 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
|
||||
text_input_free(app->text_input);
|
||||
app->text_input = NULL;
|
||||
}
|
||||
|
||||
if(app->save_filename) {
|
||||
free(app->save_filename);
|
||||
app->save_filename = NULL;
|
||||
}
|
||||
consumed = true;
|
||||
|
||||
}
|
||||
@@ -1393,7 +1401,10 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even
|
||||
if(ctx->showing_signal_info) {
|
||||
// In signal info - go back to history
|
||||
ctx->showing_signal_info = false;
|
||||
//ctx->selected_history_index = 0;
|
||||
if(app->save_filename) {
|
||||
free(app->save_filename);
|
||||
app->save_filename = NULL;
|
||||
};
|
||||
ctx->state = DecodeStateShowHistory;
|
||||
view_dispatcher_send_custom_event(
|
||||
app->view_dispatcher, ProtoPirateCustomEventSubDecodeUpdate);
|
||||
|
||||
Reference in New Issue
Block a user