action.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. const 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. char buffer[MAX_FILE_LEN]; // long enough?
  21. size_t bytes_read = storage_file_read(file_link, buffer, MAX_FILE_LEN);
  22. if(bytes_read == 0) {
  23. ACTION_SET_ERROR(
  24. "Quac Link: Error reading link file %s", furi_string_get_cstr(action_path));
  25. break;
  26. }
  27. if(!storage_file_exists(app->storage, buffer)) {
  28. ACTION_SET_ERROR("Quac Link: Linked file does not exist! %s", buffer);
  29. break;
  30. }
  31. furi_string_set_strn(new_path, buffer, bytes_read);
  32. } while(false);
  33. storage_file_close(file_link);
  34. storage_file_free(file_link);
  35. }
  36. void action_tx(void* context, Item* item, FuriString* error) {
  37. // FURI_LOG_I(TAG, "action_run: %s : %s", furi_string_get_cstr(item->name), item->ext);
  38. FuriString* path = furi_string_alloc_set(item->path);
  39. if(item->is_link) {
  40. // This is a Quac link, open the file and pull the real filename
  41. action_ql_resolve(context, item->path, path, error);
  42. if(furi_string_size(error)) {
  43. furi_string_free(path);
  44. return;
  45. }
  46. FURI_LOG_I(TAG, "Resolved Quac link file to: %s", furi_string_get_cstr(path));
  47. }
  48. if(!strcmp(item->ext, ".sub")) {
  49. action_subghz_tx(context, path, error);
  50. } else if(!strcmp(item->ext, ".ir")) {
  51. action_ir_tx(context, path, error);
  52. } else if(!strcmp(item->ext, ".rfid")) {
  53. action_rfid_tx(context, path, error);
  54. } else if(!strcmp(item->ext, ".nfc")) {
  55. action_nfc_tx(context, path, error);
  56. } else if(!strcmp(item->ext, ".ibtn")) {
  57. action_ibutton_tx(context, path, error);
  58. } else if(!strcmp(item->ext, ".qpl")) {
  59. action_qpl_tx(context, path, error);
  60. } else {
  61. FURI_LOG_E(TAG, "Unknown item file type! %s", item->ext);
  62. }
  63. furi_string_free(path);
  64. }