action.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "quac.h"
  2. #include "item.h"
  3. #include "action_i.h"
  4. #define MAX_FILE_LEN (size_t)256
  5. void action_ql_resolve(
  6. void* context,
  7. FuriString* action_path,
  8. FuriString* new_path,
  9. FuriString* error) {
  10. UNUSED(error);
  11. App* app = (App*)context;
  12. File* file_link = storage_file_alloc(app->storage);
  13. do {
  14. if(!storage_file_open(
  15. file_link, furi_string_get_cstr(action_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
  16. ACTION_SET_ERROR(
  17. "Quac Link: Failed to open file %s", furi_string_get_cstr(action_path));
  18. break;
  19. }
  20. furi_string_reset(new_path);
  21. size_t ret = 0;
  22. do {
  23. uint8_t buffer[65] = {0};
  24. ret = storage_file_read(file_link, buffer, sizeof(buffer) - 1);
  25. for(size_t i = 0; i < ret; i++) {
  26. furi_string_push_back(new_path, buffer[i]);
  27. }
  28. } while(ret > 0);
  29. furi_string_trim(new_path);
  30. if(!furi_string_size(new_path)) {
  31. ACTION_SET_ERROR(
  32. "Quac Link: Error reading link file %s", furi_string_get_cstr(action_path));
  33. break;
  34. }
  35. if(!storage_file_exists(app->storage, furi_string_get_cstr(new_path))) {
  36. ACTION_SET_ERROR(
  37. "Quac Link: Linked file does not exist! %s", furi_string_get_cstr(new_path));
  38. break;
  39. }
  40. } while(false);
  41. storage_file_close(file_link);
  42. storage_file_free(file_link);
  43. }
  44. void action_tx(void* context, Item* item, FuriString* error) {
  45. // FURI_LOG_I(TAG, "action_run: %s : %s", furi_string_get_cstr(item->name), item->ext);
  46. FuriString* path = furi_string_alloc();
  47. furi_string_set(path, item->path);
  48. if(item->is_link) {
  49. // This is a Quac link, open the file and pull the real filename
  50. action_ql_resolve(context, item->path, path, error);
  51. if(furi_string_size(error)) {
  52. furi_string_free(path);
  53. return;
  54. }
  55. FURI_LOG_I(TAG, "Resolved Quac link file to: %s", furi_string_get_cstr(path));
  56. }
  57. if(!strcmp(item->ext, ".sub")) {
  58. action_subghz_tx(context, path, error);
  59. } else if(!strcmp(item->ext, ".ir")) {
  60. action_ir_tx(context, path, error);
  61. } else if(!strcmp(item->ext, ".rfid")) {
  62. action_rfid_tx(context, path, error);
  63. } else if(!strcmp(item->ext, ".nfc")) {
  64. action_nfc_tx(context, path, error);
  65. } else if(!strcmp(item->ext, ".ibtn")) {
  66. action_ibutton_tx(context, path, error);
  67. } else if(!strcmp(item->ext, ".qpl")) {
  68. action_qpl_tx(context, path, error);
  69. } else {
  70. FURI_LOG_E(TAG, "Unknown item file type! %s", item->ext);
  71. }
  72. furi_string_free(path);
  73. }