archive_apps.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. const char* app_name = strchr(path, ':');
  9. if(app_name == NULL) {
  10. return ArchiveAppTypeUnknown;
  11. }
  12. app_name++;
  13. for(size_t i = 0; i < COUNT_OF(known_apps); i++) {
  14. if(strncmp(app_name, known_apps[i], strlen(known_apps[i])) == 0) {
  15. return i;
  16. }
  17. }
  18. return ArchiveAppTypeUnknown;
  19. }
  20. bool archive_app_is_available(void* context, const char* path) {
  21. UNUSED(context);
  22. furi_assert(path);
  23. ArchiveAppTypeEnum app = archive_get_app_type(path);
  24. if(app == ArchiveAppTypeU2f) {
  25. bool file_exists = false;
  26. Storage* fs_api = furi_record_open("storage");
  27. File* file = storage_file_alloc(fs_api);
  28. file_exists = storage_file_open(file, "/any/u2f/key.u2f", FSAM_READ, FSOM_OPEN_EXISTING);
  29. if(file_exists) {
  30. storage_file_close(file);
  31. file_exists =
  32. storage_file_open(file, "/any/u2f/cnt.u2f", FSAM_READ, FSOM_OPEN_EXISTING);
  33. if(file_exists) {
  34. storage_file_close(file);
  35. }
  36. }
  37. storage_file_free(file);
  38. furi_record_close("storage");
  39. return file_exists;
  40. } else {
  41. return false;
  42. }
  43. }
  44. bool archive_app_read_dir(void* context, const char* path) {
  45. furi_assert(context);
  46. furi_assert(path);
  47. ArchiveBrowserView* browser = context;
  48. archive_file_array_rm_all(browser);
  49. ArchiveAppTypeEnum app = archive_get_app_type(path);
  50. if(app == ArchiveAppTypeU2f) {
  51. archive_add_app_item(browser, "/app:u2f/U2F Token");
  52. return true;
  53. } else {
  54. return false;
  55. }
  56. }
  57. void archive_app_delete_file(void* context, const char* path) {
  58. furi_assert(context);
  59. furi_assert(path);
  60. ArchiveBrowserView* browser = context;
  61. ArchiveAppTypeEnum app = archive_get_app_type(path);
  62. bool res = false;
  63. if(app == ArchiveAppTypeU2f) {
  64. Storage* fs_api = furi_record_open("storage");
  65. res = (storage_common_remove(fs_api, "/any/u2f/key.u2f") == FSE_OK);
  66. res |= (storage_common_remove(fs_api, "/any/u2f/cnt.u2f") == FSE_OK);
  67. furi_record_close("storage");
  68. if(archive_is_favorite("/app:u2f/U2F Token")) {
  69. archive_favorites_delete("/app:u2f/U2F Token");
  70. }
  71. }
  72. if(res) {
  73. archive_file_array_rm_selected(browser);
  74. }
  75. }