archive_apps.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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++) { //-V1008
  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* storage = furi_record_open(RECORD_STORAGE);
  27. if(storage_file_exists(storage, ANY_PATH("u2f/key.u2f"))) {
  28. file_exists = storage_file_exists(storage, ANY_PATH("u2f/cnt.u2f"));
  29. }
  30. furi_record_close(RECORD_STORAGE);
  31. return file_exists;
  32. } else {
  33. return false;
  34. }
  35. }
  36. bool archive_app_read_dir(void* context, const char* path) {
  37. furi_assert(context);
  38. furi_assert(path);
  39. ArchiveBrowserView* browser = context;
  40. archive_file_array_rm_all(browser);
  41. ArchiveAppTypeEnum app = archive_get_app_type(path);
  42. if(app == ArchiveAppTypeU2f) {
  43. archive_add_app_item(browser, "/app:u2f/U2F Token");
  44. return true;
  45. } else {
  46. return false;
  47. }
  48. }
  49. void archive_app_delete_file(void* context, const char* path) {
  50. furi_assert(context);
  51. furi_assert(path);
  52. ArchiveBrowserView* browser = context;
  53. ArchiveAppTypeEnum app = archive_get_app_type(path);
  54. bool res = false;
  55. if(app == ArchiveAppTypeU2f) {
  56. Storage* fs_api = furi_record_open(RECORD_STORAGE);
  57. res = (storage_common_remove(fs_api, ANY_PATH("u2f/key.u2f")) == FSE_OK);
  58. res |= (storage_common_remove(fs_api, ANY_PATH("u2f/cnt.u2f")) == FSE_OK);
  59. furi_record_close(RECORD_STORAGE);
  60. if(archive_is_favorite("/app:u2f/U2F Token")) {
  61. archive_favorites_delete("/app:u2f/U2F Token");
  62. }
  63. }
  64. if(res) {
  65. archive_file_array_rm_selected(browser);
  66. }
  67. }