archive_apps.c 2.4 KB

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