action.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "quac.h"
  2. #include "item.h"
  3. #include "action_i.h"
  4. void action_ql_resolve(
  5. void* context,
  6. const FuriString* action_path,
  7. FuriString* new_path,
  8. FuriString* error) {
  9. UNUSED(error);
  10. App* app = (App*)context;
  11. File* file_link = storage_file_alloc(app->storage);
  12. do {
  13. if(!storage_file_open(
  14. file_link, furi_string_get_cstr(action_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
  15. ACTION_SET_ERROR(
  16. "Quac Link: Failed to open file %s", furi_string_get_cstr(action_path));
  17. break;
  18. }
  19. furi_string_reset(new_path);
  20. const size_t file_size = storage_file_size(file_link);
  21. size_t bytes_read = 0;
  22. while(bytes_read < file_size) {
  23. char buffer[65] = {0};
  24. const size_t chunk_size = MIN(file_size - bytes_read, sizeof(buffer) - 1);
  25. size_t chunk_read = storage_file_read(file_link, buffer, chunk_size);
  26. if(chunk_read != chunk_size) break;
  27. bytes_read += chunk_read;
  28. furi_string_cat_str(new_path, buffer);
  29. }
  30. furi_string_trim(new_path);
  31. if(bytes_read != file_size) {
  32. ACTION_SET_ERROR(
  33. "Quac Link: Error reading link file %s", furi_string_get_cstr(action_path));
  34. break;
  35. }
  36. if(!storage_file_exists(app->storage, furi_string_get_cstr(new_path))) {
  37. ACTION_SET_ERROR(
  38. "Quac Link: Linked file does not exist! %s", furi_string_get_cstr(new_path));
  39. break;
  40. }
  41. } while(false);
  42. storage_file_close(file_link);
  43. storage_file_free(file_link);
  44. }
  45. void action_tx(void* context, Item* item, FuriString* error) {
  46. // FURI_LOG_I(TAG, "action_run: %s : %s", furi_string_get_cstr(item->name), item->ext);
  47. FuriString* path = furi_string_alloc_set(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. }