example_apps_assets.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <furi.h>
  2. #include <storage/storage.h>
  3. #include <toolbox/stream/stream.h>
  4. #include <toolbox/stream/file_stream.h>
  5. // Define log tag
  6. #define TAG "example_apps_assets"
  7. static void example_apps_data_print_file_content(Storage* storage, const char* path) {
  8. Stream* stream = file_stream_alloc(storage);
  9. FuriString* line = furi_string_alloc();
  10. FURI_LOG_I(TAG, "----------------------------------------");
  11. FURI_LOG_I(TAG, "File \"%s\" content:", path);
  12. if(file_stream_open(stream, path, FSAM_READ, FSOM_OPEN_EXISTING)) {
  13. while(stream_read_line(stream, line)) {
  14. furi_string_replace_all(line, "\r", "");
  15. furi_string_replace_all(line, "\n", "");
  16. FURI_LOG_I(TAG, "%s", furi_string_get_cstr(line));
  17. }
  18. } else {
  19. FURI_LOG_E(TAG, "Failed to open file");
  20. }
  21. FURI_LOG_I(TAG, "----------------------------------------");
  22. furi_string_free(line);
  23. file_stream_close(stream);
  24. stream_free(stream);
  25. }
  26. // Application entry point
  27. int32_t example_apps_assets_main(void* p) {
  28. // Mark argument as unused
  29. UNUSED(p);
  30. // Open storage
  31. Storage* storage = furi_record_open(RECORD_STORAGE);
  32. example_apps_data_print_file_content(storage, APP_ASSETS_PATH("test_asset.txt"));
  33. example_apps_data_print_file_content(storage, APP_ASSETS_PATH("poems/a jelly-fish.txt"));
  34. example_apps_data_print_file_content(storage, APP_ASSETS_PATH("poems/theme in yellow.txt"));
  35. example_apps_data_print_file_content(storage, APP_ASSETS_PATH("poems/my shadow.txt"));
  36. // Close storage
  37. furi_record_close(RECORD_STORAGE);
  38. return 0;
  39. }