archive_apps.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "archive_files.h"
  2. #include "archive_apps.h"
  3. #include "archive_browser.h"
  4. static const char* known_apps[] = {
  5. [ArchiveAppTypeU2f] = "u2f",
  6. };
  7. ArchiveAppTypeEnum archive_get_app_type(const char* path) {
  8. for(size_t i = 0; i < SIZEOF_ARRAY(known_apps); i++) {
  9. if(strncmp(path, known_apps[i], strlen(known_apps[i])) != STRING_FAILURE) {
  10. return i;
  11. }
  12. }
  13. return ArchiveAppTypeUnknown;
  14. }
  15. bool archive_app_is_available(void* context, const char* path) {
  16. furi_assert(path);
  17. ArchiveAppTypeEnum app = archive_get_app_type(path);
  18. if(app == ArchiveAppTypeU2f) {
  19. bool file_exists = false;
  20. Storage* fs_api = furi_record_open("storage");
  21. File* file = storage_file_alloc(fs_api);
  22. file_exists = storage_file_open(file, "/any/u2f/key.u2f", FSAM_READ, FSOM_OPEN_EXISTING);
  23. if(file_exists) {
  24. storage_file_close(file);
  25. file_exists =
  26. storage_file_open(file, "/any/u2f/cnt.u2f", FSAM_READ, FSOM_OPEN_EXISTING);
  27. if(file_exists) {
  28. storage_file_close(file);
  29. }
  30. }
  31. storage_file_free(file);
  32. furi_record_close("storage");
  33. return file_exists;
  34. } else {
  35. return false;
  36. }
  37. }
  38. bool archive_app_read_dir(void* context, const char* path) {
  39. furi_assert(context);
  40. furi_assert(path);
  41. ArchiveBrowserView* browser = context;
  42. archive_file_array_rm_all(browser);
  43. ArchiveAppTypeEnum app = archive_get_app_type(path);
  44. if(app == ArchiveAppTypeU2f) {
  45. archive_add_app_item(browser, "/app:u2f/U2F Token");
  46. return true;
  47. } else {
  48. return false;
  49. }
  50. }
  51. void archive_app_delete_file(void* context, const char* path) {
  52. furi_assert(context);
  53. furi_assert(path);
  54. ArchiveBrowserView* browser = context;
  55. ArchiveAppTypeEnum app = archive_get_app_type(path);
  56. bool res = false;
  57. if(app == ArchiveAppTypeU2f) {
  58. Storage* fs_api = furi_record_open("storage");
  59. res = (storage_common_remove(fs_api, "/any/u2f/key.u2f") == FSE_OK);
  60. res |= (storage_common_remove(fs_api, "/any/u2f/cnt.u2f") == FSE_OK);
  61. furi_record_close("storage");
  62. if(archive_is_favorite("/app:u2f/U2F Token")) {
  63. archive_favorites_delete("/app:u2f/U2F Token");
  64. }
  65. }
  66. if(res) {
  67. archive_file_array_rm_selected(browser);
  68. }
  69. }