archive_apps.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. ArchiveAppTypeEnum app = archive_get_app_type(path);
  36. if(app == ArchiveAppTypeU2f) {
  37. archive_add_app_item(browser, "/app:u2f/U2F Token");
  38. return true;
  39. } else {
  40. return false;
  41. }
  42. }
  43. void archive_app_delete_file(void* context, const char* path) {
  44. furi_assert(context);
  45. furi_assert(path);
  46. ArchiveBrowserView* browser = context;
  47. ArchiveAppTypeEnum app = archive_get_app_type(path);
  48. bool res = false;
  49. if(app == ArchiveAppTypeU2f) {
  50. FileWorker* file_worker = file_worker_alloc(true);
  51. res = file_worker_remove(file_worker, "/any/u2f/key.u2f");
  52. res |= file_worker_remove(file_worker, "/any/u2f/cnt.u2f");
  53. file_worker_free(file_worker);
  54. if(archive_is_favorite("/app:u2f/U2F Token")) {
  55. archive_favorites_delete("/app:u2f/U2F Token");
  56. }
  57. }
  58. if(res) {
  59. archive_file_array_rm_selected(browser);
  60. }
  61. }