archive_apps.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. FileWorker* file_worker = file_worker_alloc(true);
  20. bool file_exists = false;
  21. file_worker_is_file_exist(file_worker, "/any/u2f/key.u2f", &file_exists);
  22. if(file_exists) {
  23. file_worker_is_file_exist(file_worker, "/any/u2f/cnt.u2f", &file_exists);
  24. }
  25. file_worker_free(file_worker);
  26. return file_exists;
  27. } else {
  28. return false;
  29. }
  30. }
  31. bool archive_app_read_dir(void* context, const char* path) {
  32. furi_assert(context);
  33. furi_assert(path);
  34. ArchiveBrowserView* browser = context;
  35. archive_file_array_rm_all(browser);
  36. ArchiveAppTypeEnum app = archive_get_app_type(path);
  37. if(app == ArchiveAppTypeU2f) {
  38. archive_add_app_item(browser, "/app:u2f/U2F Token");
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. }
  44. void archive_app_delete_file(void* context, const char* path) {
  45. furi_assert(context);
  46. furi_assert(path);
  47. ArchiveBrowserView* browser = context;
  48. ArchiveAppTypeEnum app = archive_get_app_type(path);
  49. bool res = false;
  50. if(app == ArchiveAppTypeU2f) {
  51. FileWorker* file_worker = file_worker_alloc(true);
  52. res = file_worker_remove(file_worker, "/any/u2f/key.u2f");
  53. res |= file_worker_remove(file_worker, "/any/u2f/cnt.u2f");
  54. file_worker_free(file_worker);
  55. if(archive_is_favorite("/app:u2f/U2F Token")) {
  56. archive_favorites_delete("/app:u2f/U2F Token");
  57. }
  58. }
  59. if(res) {
  60. archive_file_array_rm_selected(browser);
  61. }
  62. }