Skip to content

Commit

Permalink
feat: limit file size added
Browse files Browse the repository at this point in the history
  • Loading branch information
AdonaiDiazEsparza committed Oct 15, 2024
1 parent 57a53b9 commit ef311f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
37 changes: 27 additions & 10 deletions Canbus_app/scenes/playLogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ uint32_t hex_to_int(const char* hex_str) {
return (uint32_t)result;
}

char *custom_strtok_r(char *str, const char *delim, char **saveptr) {
if (str) {
char* custom_strtok_r(char* str, const char* delim, char** saveptr) {
if(str) {
*saveptr = str;
}
if (!*saveptr) {
if(!*saveptr) {
return NULL;
}

char *start = *saveptr;
while (*start && strchr(delim, *start)) {
char* start = *saveptr;
while(*start && strchr(delim, *start)) {
++start;
}
if (*start == '\0') {
if(*start == '\0') {
*saveptr = NULL;
return NULL;
}

char *end = start;
while (*end && !strchr(delim, *end)) {
char* end = start;
while(*end && !strchr(delim, *end)) {
++end;
}

if (*end) {
if(*end) {
*end = '\0';
*saveptr = end + 1;
} else {
Expand All @@ -72,25 +72,42 @@ void play_data_frames(App* app, UniqueId* unique_ids, int unique_id_count);
void play_data_frames_bk(void* context, int frame_interval);

// Function to select log file
void select_log_file(App* app) {
bool select_log_file(App* app, FuriString* file_name) {
FuriString* predefined_filepath = furi_string_alloc_set_str(PATHAPP);
FuriString* selected_filepath = furi_string_alloc();
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, ".log", NULL);

browser_options.base_path = PATHAPP;

dialog_file_browser_show(
app->dialogs, selected_filepath, predefined_filepath, &browser_options);

if(storage_file_open(
app->log_file, furi_string_get_cstr(selected_filepath), FSAM_READ, FSOM_OPEN_EXISTING)) {
app->size_of_storage = storage_file_size(app->log_file);
// File opened successfully
//app->log_filepath = furi_string_alloc_set(selected_filepath);
} else {
dialog_message_show_storage_error(app->dialogs, "Cannot open File");
// TODO: something
return false;
}

if(app->size_of_storage > 25000) return false;

furi_string_reset(file_name);

furi_string_cat_str(file_name, furi_string_get_cstr(selected_filepath));

furi_string_reset(app->data);
char buf[storage_file_size(app->log_file)];
storage_file_read(app->log_file, buf, sizeof(buf));

buf[sizeof(buf)] = '\0';
furi_string_cat_str(app->data, buf);

storage_file_close(app->log_file);
furi_string_free(selected_filepath);
furi_string_free(predefined_filepath);
}

Check failure on line 113 in Canbus_app/scenes/playLogs.c

View workflow job for this annotation

GitHub Actions / ufbt: Build for Dev branch

control reaches end of non-void function [-Werror=return-type]
Expand Down
2 changes: 1 addition & 1 deletion Canbus_app/scenes/snippet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ void send_data_frame(void* context) {

model->flag_tx_file = false;

}
}

0 comments on commit ef311f0

Please sign in to comment.