dir_walk.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <storage/storage.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef struct DirWalk DirWalk;
  7. typedef enum {
  8. DirWalkOK, /**< OK */
  9. DirWalkError, /**< Error */
  10. DirWalkLast, /**< Last element */
  11. } DirWalkResult;
  12. typedef bool (*DirWalkFilterCb)(const char* name, FileInfo* fileinfo, void* ctx);
  13. /**
  14. * Allocate DirWalk
  15. * @param storage
  16. * @return DirWalk*
  17. */
  18. DirWalk* dir_walk_alloc(Storage* storage);
  19. /**
  20. * Free DirWalk
  21. * @param dir_walk
  22. */
  23. void dir_walk_free(DirWalk* dir_walk);
  24. /**
  25. * Set recursive mode (true by default)
  26. * @param dir_walk
  27. * @param recursive
  28. */
  29. void dir_walk_set_recursive(DirWalk* dir_walk, bool recursive);
  30. /**
  31. * Set filter callback (Should return true if the data is valid)
  32. * @param dir_walk
  33. * @param cb
  34. * @param context
  35. */
  36. void dir_walk_set_filter_cb(DirWalk* dir_walk, DirWalkFilterCb cb, void* context);
  37. /**
  38. * Open directory
  39. * @param dir_walk
  40. * @param path
  41. * @return true
  42. * @return false
  43. */
  44. bool dir_walk_open(DirWalk* dir_walk, const char* path);
  45. /**
  46. * Get error id
  47. * @param dir_walk
  48. * @return FS_Error
  49. */
  50. FS_Error dir_walk_get_error(DirWalk* dir_walk);
  51. /**
  52. * Read next element from directory
  53. * @param dir_walk
  54. * @param return_path
  55. * @param fileinfo
  56. * @return DirWalkResult
  57. */
  58. DirWalkResult dir_walk_read(DirWalk* dir_walk, FuriString* return_path, FileInfo* fileinfo);
  59. /**
  60. * Close directory
  61. * @param dir_walk
  62. */
  63. void dir_walk_close(DirWalk* dir_walk);
  64. #ifdef __cplusplus
  65. }
  66. #endif