|
|
@@ -404,128 +404,4 @@ static bool rename_received_data(const char *old_name, const char *new_name, con
|
|
|
return renamed;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-static bool text_show_read_lines(File *file, FuriString *str_result)
|
|
|
-{
|
|
|
- // Reset the FuriString to ensure it's empty before reading
|
|
|
- furi_string_reset(str_result);
|
|
|
-
|
|
|
- // Define a buffer to hold the read data
|
|
|
- uint8_t buffer[SHOW_MAX_FILE_SIZE];
|
|
|
-
|
|
|
- // Read data into the buffer
|
|
|
- size_t read_count = storage_file_read(file, buffer, SHOW_MAX_FILE_SIZE);
|
|
|
- if (storage_file_get_error(file) != FSE_OK)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Error reading from file.");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Append each byte to the FuriString
|
|
|
- for (size_t i = 0; i < read_count; i++)
|
|
|
- {
|
|
|
- furi_string_push_back(str_result, buffer[i]);
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-static bool load_received_data(WebCrawlerApp *app)
|
|
|
-{
|
|
|
- if (app == NULL)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "WebCrawlerApp is NULL");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!app->widget_file_read)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Textbox is NULL");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Open the storage record
|
|
|
- Storage *storage = furi_record_open(RECORD_STORAGE);
|
|
|
- if (!storage)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Failed to open storage record");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Allocate a file handle
|
|
|
- File *file = storage_file_alloc(storage);
|
|
|
- if (!file)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Failed to allocate storage file");
|
|
|
- furi_record_close(RECORD_STORAGE);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Open the file for reading
|
|
|
- if (!storage_file_open(file, RECEIVED_DATA_PATH "received_data.txt", FSAM_READ, FSOM_OPEN_EXISTING))
|
|
|
- {
|
|
|
- storage_file_free(file);
|
|
|
- furi_record_close(RECORD_STORAGE);
|
|
|
- return false; // Return false if the file does not exist
|
|
|
- }
|
|
|
-
|
|
|
- // Allocate a FuriString to hold the received data
|
|
|
- FuriString *str_result = furi_string_alloc();
|
|
|
- if (!str_result)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Failed to allocate FuriString");
|
|
|
- storage_file_close(file);
|
|
|
- storage_file_free(file);
|
|
|
- furi_record_close(RECORD_STORAGE);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Read data into the FuriString
|
|
|
- bool read_success = text_show_read_lines(file, str_result);
|
|
|
- if (!read_success)
|
|
|
- {
|
|
|
- FURI_LOG_E(TAG, "Failed to read data from file");
|
|
|
- furi_string_free(str_result);
|
|
|
- storage_file_close(file);
|
|
|
- storage_file_free(file);
|
|
|
- furi_record_close(RECORD_STORAGE);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Check if there is more data beyond the maximum size
|
|
|
- char extra_byte;
|
|
|
- storage_file_read(file, &extra_byte, 1);
|
|
|
-
|
|
|
- // Retrieve the C-string from FuriString
|
|
|
- const char *data_cstr = furi_string_get_cstr(str_result);
|
|
|
- // Set the text box with the received data
|
|
|
-
|
|
|
- widget_reset(app->widget_file_read);
|
|
|
-
|
|
|
- if (str_result != NULL)
|
|
|
- {
|
|
|
- widget_add_text_scroll_element(
|
|
|
- app->widget_file_read,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- 128,
|
|
|
- 64, data_cstr);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- widget_add_text_scroll_element(
|
|
|
- app->widget_file_read,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- 128,
|
|
|
- 64, "File is empty.");
|
|
|
- }
|
|
|
- // Clean up
|
|
|
- furi_string_free(str_result);
|
|
|
- storage_file_close(file);
|
|
|
- storage_file_free(file);
|
|
|
- furi_record_close(RECORD_STORAGE);
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
#endif // WEB_CRAWLER_STORAGE_H
|