storage.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. #include "flip_storage/storage.h"
  2. void save_settings(
  3. const char *ssid,
  4. const char *password)
  5. {
  6. // Create the directory for saving settings
  7. char directory_path[256];
  8. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world");
  9. // Create the directory
  10. Storage *storage = furi_record_open(RECORD_STORAGE);
  11. storage_common_mkdir(storage, directory_path);
  12. // Open the settings file
  13. File *file = storage_file_alloc(storage);
  14. if (!storage_file_open(file, SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS))
  15. {
  16. FURI_LOG_E(TAG, "Failed to open settings file for writing: %s", SETTINGS_PATH);
  17. storage_file_free(file);
  18. furi_record_close(RECORD_STORAGE);
  19. return;
  20. }
  21. // Save the ssid length and data
  22. size_t ssid_length = strlen(ssid) + 1; // Include null terminator
  23. if (storage_file_write(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) ||
  24. storage_file_write(file, ssid, ssid_length) != ssid_length)
  25. {
  26. FURI_LOG_E(TAG, "Failed to write SSID");
  27. }
  28. // Save the password length and data
  29. size_t password_length = strlen(password) + 1; // Include null terminator
  30. if (storage_file_write(file, &password_length, sizeof(size_t)) != sizeof(size_t) ||
  31. storage_file_write(file, password, password_length) != password_length)
  32. {
  33. FURI_LOG_E(TAG, "Failed to write password");
  34. }
  35. storage_file_close(file);
  36. storage_file_free(file);
  37. furi_record_close(RECORD_STORAGE);
  38. }
  39. bool load_settings(
  40. char *ssid,
  41. size_t ssid_size,
  42. char *password,
  43. size_t password_size)
  44. {
  45. Storage *storage = furi_record_open(RECORD_STORAGE);
  46. File *file = storage_file_alloc(storage);
  47. if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
  48. {
  49. FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
  50. storage_file_free(file);
  51. furi_record_close(RECORD_STORAGE);
  52. return false; // Return false if the file does not exist
  53. }
  54. // Load the ssid
  55. size_t ssid_length;
  56. if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
  57. storage_file_read(file, ssid, ssid_length) != ssid_length)
  58. {
  59. FURI_LOG_E(TAG, "Failed to read SSID");
  60. storage_file_close(file);
  61. storage_file_free(file);
  62. furi_record_close(RECORD_STORAGE);
  63. return false;
  64. }
  65. ssid[ssid_length - 1] = '\0'; // Ensure null-termination
  66. // Load the password
  67. size_t password_length;
  68. if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
  69. storage_file_read(file, password, password_length) != password_length)
  70. {
  71. FURI_LOG_E(TAG, "Failed to read password");
  72. storage_file_close(file);
  73. storage_file_free(file);
  74. furi_record_close(RECORD_STORAGE);
  75. return false;
  76. }
  77. password[password_length - 1] = '\0'; // Ensure null-termination
  78. storage_file_close(file);
  79. storage_file_free(file);
  80. furi_record_close(RECORD_STORAGE);
  81. return true;
  82. }
  83. bool save_char(
  84. const char *path_name, const char *value)
  85. {
  86. if (!value)
  87. {
  88. return false;
  89. }
  90. // Create the directory for saving settings
  91. char directory_path[256];
  92. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world");
  93. // Create the directory
  94. Storage *storage = furi_record_open(RECORD_STORAGE);
  95. storage_common_mkdir(storage, directory_path);
  96. // Open the settings file
  97. File *file = storage_file_alloc(storage);
  98. char file_path[256];
  99. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/%s.txt", path_name);
  100. // Open the file in write mode
  101. if (!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS))
  102. {
  103. FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
  104. storage_file_free(file);
  105. furi_record_close(RECORD_STORAGE);
  106. return false;
  107. }
  108. // Write the data to the file
  109. size_t data_size = strlen(value) + 1; // Include null terminator
  110. if (storage_file_write(file, value, data_size) != data_size)
  111. {
  112. FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
  113. storage_file_close(file);
  114. storage_file_free(file);
  115. furi_record_close(RECORD_STORAGE);
  116. return false;
  117. }
  118. storage_file_close(file);
  119. storage_file_free(file);
  120. furi_record_close(RECORD_STORAGE);
  121. return true;
  122. }
  123. bool load_char(
  124. const char *path_name,
  125. char *value,
  126. size_t value_size)
  127. {
  128. if (!value)
  129. {
  130. return false;
  131. }
  132. Storage *storage = furi_record_open(RECORD_STORAGE);
  133. File *file = storage_file_alloc(storage);
  134. char file_path[256];
  135. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/%s.txt", path_name);
  136. // Open the file for reading
  137. if (!storage_file_open(file, file_path, FSAM_READ, FSOM_OPEN_EXISTING))
  138. {
  139. storage_file_free(file);
  140. furi_record_close(RECORD_STORAGE);
  141. return NULL; // Return false if the file does not exist
  142. }
  143. // Read data into the buffer
  144. size_t read_count = storage_file_read(file, value, value_size);
  145. if (storage_file_get_error(file) != FSE_OK)
  146. {
  147. FURI_LOG_E(HTTP_TAG, "Error reading from file.");
  148. storage_file_close(file);
  149. storage_file_free(file);
  150. furi_record_close(RECORD_STORAGE);
  151. return false;
  152. }
  153. // Ensure null-termination
  154. value[read_count - 1] = '\0';
  155. storage_file_close(file);
  156. storage_file_free(file);
  157. furi_record_close(RECORD_STORAGE);
  158. return true;
  159. }
  160. bool save_world(
  161. const char *name,
  162. const char *world_data)
  163. {
  164. // Create the directory for saving settings
  165. char directory_path[256];
  166. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds");
  167. // Create the directory
  168. Storage *storage = furi_record_open(RECORD_STORAGE);
  169. storage_common_mkdir(storage, directory_path);
  170. // Open the settings file
  171. File *file = storage_file_alloc(storage);
  172. char file_path[256];
  173. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/%s.json", name);
  174. // Open the file in write mode
  175. if (!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS))
  176. {
  177. FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
  178. storage_file_free(file);
  179. furi_record_close(RECORD_STORAGE);
  180. return false;
  181. }
  182. // Write the data to the file
  183. size_t data_size = strlen(world_data) + 1; // Include null terminator
  184. if (storage_file_write(file, world_data, data_size) != data_size)
  185. {
  186. FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
  187. storage_file_close(file);
  188. storage_file_free(file);
  189. furi_record_close(RECORD_STORAGE);
  190. return false;
  191. }
  192. storage_file_close(file);
  193. storage_file_free(file);
  194. furi_record_close(RECORD_STORAGE);
  195. return true;
  196. }
  197. bool save_world_furi(FuriString *name, FuriString *world_data)
  198. {
  199. // Create the directory for saving settings
  200. char directory_path[256];
  201. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds");
  202. // Create the directory
  203. Storage *storage = furi_record_open(RECORD_STORAGE);
  204. storage_common_mkdir(storage, directory_path);
  205. // Open the settings file
  206. File *file = storage_file_alloc(storage);
  207. char file_path[256];
  208. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/%s.json", furi_string_get_cstr(name));
  209. // Open the file in write mode
  210. if (!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS))
  211. {
  212. FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
  213. storage_file_free(file);
  214. furi_record_close(RECORD_STORAGE);
  215. return false;
  216. }
  217. // Write the data to the file
  218. size_t data_size = furi_string_size(world_data) + 1; // Include null terminator
  219. if (storage_file_write(file, furi_string_get_cstr(world_data), data_size) != data_size)
  220. {
  221. FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
  222. storage_file_close(file);
  223. storage_file_free(file);
  224. furi_record_close(RECORD_STORAGE);
  225. return false;
  226. }
  227. storage_file_close(file);
  228. storage_file_free(file);
  229. furi_record_close(RECORD_STORAGE);
  230. return true;
  231. }
  232. bool load_world(
  233. const char *name,
  234. char *json_data,
  235. size_t json_data_size)
  236. {
  237. Storage *storage = furi_record_open(RECORD_STORAGE);
  238. File *file = storage_file_alloc(storage);
  239. char file_path[256];
  240. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/%s.json", name);
  241. // Open the file for reading
  242. if (!storage_file_open(file, file_path, FSAM_READ, FSOM_OPEN_EXISTING))
  243. {
  244. storage_file_free(file);
  245. furi_record_close(RECORD_STORAGE);
  246. return NULL; // Return false if the file does not exist
  247. }
  248. // Read data into the buffer
  249. size_t read_count = storage_file_read(file, json_data, json_data_size);
  250. if (storage_file_get_error(file) != FSE_OK)
  251. {
  252. FURI_LOG_E(HTTP_TAG, "Error reading from file.");
  253. storage_file_close(file);
  254. storage_file_free(file);
  255. furi_record_close(RECORD_STORAGE);
  256. return false;
  257. }
  258. // Ensure null-termination
  259. json_data[read_count - 1] = '\0';
  260. storage_file_close(file);
  261. storage_file_free(file);
  262. furi_record_close(RECORD_STORAGE);
  263. return true;
  264. }
  265. FuriString *load_furi_world(
  266. const char *name)
  267. {
  268. Storage *storage = furi_record_open(RECORD_STORAGE);
  269. File *file = storage_file_alloc(storage);
  270. char file_path[128];
  271. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/%s.json", name);
  272. // Open the file for reading
  273. if (!storage_file_open(file, file_path, FSAM_READ, FSOM_OPEN_EXISTING))
  274. {
  275. storage_file_free(file);
  276. furi_record_close(RECORD_STORAGE);
  277. return NULL; // Return false if the file does not exist
  278. }
  279. // Allocate a FuriString to hold the received data
  280. FuriString *str_result = furi_string_alloc();
  281. if (!str_result)
  282. {
  283. FURI_LOG_E(HTTP_TAG, "Failed to allocate FuriString");
  284. storage_file_close(file);
  285. storage_file_free(file);
  286. furi_record_close(RECORD_STORAGE);
  287. return NULL;
  288. }
  289. // Reset the FuriString to ensure it's empty before reading
  290. furi_string_reset(str_result);
  291. // Define a buffer to hold the read data
  292. uint8_t *buffer = (uint8_t *)malloc(MAX_FILE_SHOW);
  293. if (!buffer)
  294. {
  295. FURI_LOG_E(HTTP_TAG, "Failed to allocate buffer");
  296. furi_string_free(str_result);
  297. storage_file_close(file);
  298. storage_file_free(file);
  299. furi_record_close(RECORD_STORAGE);
  300. return NULL;
  301. }
  302. // Read data into the buffer
  303. size_t read_count = storage_file_read(file, buffer, MAX_FILE_SHOW);
  304. if (storage_file_get_error(file) != FSE_OK)
  305. {
  306. FURI_LOG_E(HTTP_TAG, "Error reading from file.");
  307. furi_string_free(str_result);
  308. storage_file_close(file);
  309. storage_file_free(file);
  310. furi_record_close(RECORD_STORAGE);
  311. return NULL;
  312. }
  313. // Append each byte to the FuriString
  314. for (size_t i = 0; i < read_count; i++)
  315. {
  316. furi_string_push_back(str_result, buffer[i]);
  317. }
  318. // Check if there is more data beyond the maximum size
  319. char extra_byte;
  320. storage_file_read(file, &extra_byte, 1);
  321. // Clean up
  322. storage_file_close(file);
  323. storage_file_free(file);
  324. furi_record_close(RECORD_STORAGE);
  325. free(buffer);
  326. return str_result;
  327. }
  328. bool world_exists(const char *name)
  329. {
  330. if (!name)
  331. {
  332. FURI_LOG_E(TAG, "Invalid name");
  333. return false;
  334. }
  335. Storage *storage = furi_record_open(RECORD_STORAGE);
  336. if (!storage)
  337. {
  338. FURI_LOG_E(TAG, "Failed to open storage");
  339. return false;
  340. }
  341. char file_path[256];
  342. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/%s.json", name);
  343. bool does_exist = storage_file_exists(storage, file_path);
  344. // Clean up
  345. furi_record_close(RECORD_STORAGE);
  346. return does_exist;
  347. }
  348. bool save_world_names(const FuriString *json)
  349. {
  350. // Create the directory for saving settings
  351. char directory_path[256];
  352. snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds");
  353. // Create the directory
  354. Storage *storage = furi_record_open(RECORD_STORAGE);
  355. storage_common_mkdir(storage, directory_path);
  356. // Open the settings file
  357. File *file = storage_file_alloc(storage);
  358. char file_path[128];
  359. snprintf(file_path, sizeof(file_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_world/worlds/world_list.json");
  360. // Open the file in write mode
  361. if (!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS))
  362. {
  363. FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
  364. storage_file_free(file);
  365. furi_record_close(RECORD_STORAGE);
  366. return false;
  367. }
  368. // Write the data to the file
  369. size_t data_size = furi_string_size(json) + 1; // Include null terminator
  370. if (storage_file_write(file, furi_string_get_cstr(json), data_size) != data_size)
  371. {
  372. FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
  373. storage_file_close(file);
  374. storage_file_free(file);
  375. furi_record_close(RECORD_STORAGE);
  376. return false;
  377. }
  378. storage_file_close(file);
  379. storage_file_free(file);
  380. furi_record_close(RECORD_STORAGE);
  381. return true;
  382. }
  383. static bool load_flip_social_settings(
  384. char *ssid,
  385. size_t ssid_size,
  386. char *password,
  387. size_t password_size,
  388. char *login_username_logged_out,
  389. size_t username_out_size,
  390. char *login_username_logged_in,
  391. size_t username_in_size,
  392. char *login_password_logged_out,
  393. size_t password_out_size,
  394. char *change_password_logged_in,
  395. size_t change_password_size,
  396. char *change_bio_logged_in,
  397. size_t change_bio_size,
  398. char *is_logged_in,
  399. size_t is_logged_in_size)
  400. {
  401. Storage *storage = furi_record_open(RECORD_STORAGE);
  402. File *file = storage_file_alloc(storage);
  403. if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
  404. {
  405. FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
  406. storage_file_free(file);
  407. furi_record_close(RECORD_STORAGE);
  408. return false; // Return false if the file does not exist
  409. }
  410. // Load the ssid
  411. size_t ssid_length;
  412. if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
  413. storage_file_read(file, ssid, ssid_length) != ssid_length)
  414. {
  415. FURI_LOG_E(TAG, "Failed to read SSID");
  416. storage_file_close(file);
  417. storage_file_free(file);
  418. furi_record_close(RECORD_STORAGE);
  419. return false;
  420. }
  421. else
  422. {
  423. ssid[ssid_length - 1] = '\0'; // Ensure null-termination
  424. }
  425. // Load the password
  426. size_t password_length;
  427. if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
  428. storage_file_read(file, password, password_length) != password_length)
  429. {
  430. FURI_LOG_E(TAG, "Failed to read password");
  431. storage_file_close(file);
  432. storage_file_free(file);
  433. furi_record_close(RECORD_STORAGE);
  434. return false;
  435. }
  436. else
  437. {
  438. password[password_length - 1] = '\0'; // Ensure null-termination
  439. }
  440. // Load the login_username_logged_out
  441. size_t username_out_length;
  442. if (storage_file_read(file, &username_out_length, sizeof(size_t)) != sizeof(size_t) || username_out_length > username_out_size ||
  443. storage_file_read(file, login_username_logged_out, username_out_length) != username_out_length)
  444. {
  445. FURI_LOG_E(TAG, "Failed to read login_username_logged_out");
  446. // storage_file_close(file);
  447. // storage_file_free(file);
  448. // furi_record_close(RECORD_STORAGE);
  449. // return false;
  450. }
  451. else
  452. {
  453. login_username_logged_out[username_out_length - 1] = '\0'; // Ensure null-termination
  454. }
  455. // Load the login_username_logged_in
  456. size_t username_in_length;
  457. if (storage_file_read(file, &username_in_length, sizeof(size_t)) != sizeof(size_t) || username_in_length > username_in_size ||
  458. storage_file_read(file, login_username_logged_in, username_in_length) != username_in_length)
  459. {
  460. FURI_LOG_E(TAG, "Failed to read login_username_logged_in");
  461. // storage_file_close(file);
  462. // storage_file_free(file);
  463. // furi_record_close(RECORD_STORAGE);
  464. // return false;
  465. }
  466. else
  467. {
  468. login_username_logged_in[username_in_length - 1] = '\0'; // Ensure null-termination
  469. }
  470. // Load the login_password_logged_out
  471. size_t password_out_length;
  472. if (storage_file_read(file, &password_out_length, sizeof(size_t)) != sizeof(size_t) || password_out_length > password_out_size ||
  473. storage_file_read(file, login_password_logged_out, password_out_length) != password_out_length)
  474. {
  475. FURI_LOG_E(TAG, "Failed to read login_password_logged_out");
  476. // storage_file_close(file);
  477. // storage_file_free(file);
  478. // furi_record_close(RECORD_STORAGE);
  479. // return false;
  480. }
  481. else
  482. {
  483. login_password_logged_out[password_out_length - 1] = '\0'; // Ensure null-termination
  484. }
  485. // Load the change_password_logged_in
  486. size_t change_password_length;
  487. if (storage_file_read(file, &change_password_length, sizeof(size_t)) != sizeof(size_t) || change_password_length > change_password_size ||
  488. storage_file_read(file, change_password_logged_in, change_password_length) != change_password_length)
  489. {
  490. FURI_LOG_E(TAG, "Failed to read change_password_logged_in");
  491. // storage_file_close(file);
  492. // storage_file_free(file);
  493. // furi_record_close(RECORD_STORAGE);
  494. // return false;
  495. }
  496. else
  497. {
  498. change_password_logged_in[change_password_length - 1] = '\0'; // Ensure null-termination
  499. }
  500. // Load the is_logged_in
  501. size_t is_logged_in_length;
  502. if (storage_file_read(file, &is_logged_in_length, sizeof(size_t)) != sizeof(size_t) || is_logged_in_length > is_logged_in_size ||
  503. storage_file_read(file, is_logged_in, is_logged_in_length) != is_logged_in_length)
  504. {
  505. FURI_LOG_E(TAG, "Failed to read is_logged_in");
  506. // storage_file_close(file);
  507. // storage_file_free(file);
  508. // furi_record_close(RECORD_STORAGE);
  509. // return false;
  510. }
  511. else
  512. {
  513. is_logged_in[is_logged_in_length - 1] = '\0'; // Ensure null-termination
  514. }
  515. // Load the change_bio_logged_in
  516. size_t change_bio_length;
  517. if (storage_file_read(file, &change_bio_length, sizeof(size_t)) != sizeof(size_t) || change_bio_length > change_bio_size ||
  518. storage_file_read(file, change_bio_logged_in, change_bio_length) != change_bio_length)
  519. {
  520. FURI_LOG_E(TAG, "Failed to read change_bio_logged_in");
  521. // storage_file_close(file);
  522. // storage_file_free(file);
  523. // furi_record_close(RECORD_STORAGE);
  524. // return false;
  525. }
  526. else
  527. {
  528. change_bio_logged_in[change_bio_length - 1] = '\0'; // Ensure null-termination
  529. }
  530. storage_file_close(file);
  531. storage_file_free(file);
  532. furi_record_close(RECORD_STORAGE);
  533. return true;
  534. }
  535. FuriString *flip_social_info(char *key)
  536. {
  537. char ssid[64];
  538. char password[64];
  539. char login_username_logged_out[64];
  540. char login_username_logged_in[64];
  541. char login_password_logged_out[64];
  542. char change_password_logged_in[64];
  543. char change_bio_logged_in[64];
  544. char is_logged_in[64];
  545. FuriString *result = furi_string_alloc();
  546. if (!result)
  547. {
  548. FURI_LOG_E(TAG, "Failed to allocate FuriString");
  549. return NULL;
  550. }
  551. if (!load_flip_social_settings(ssid, sizeof(ssid), password, sizeof(password), login_username_logged_out, sizeof(login_username_logged_out), login_username_logged_in, sizeof(login_username_logged_in), login_password_logged_out, sizeof(login_password_logged_out), change_password_logged_in, sizeof(change_password_logged_in), change_bio_logged_in, sizeof(change_bio_logged_in), is_logged_in, sizeof(is_logged_in)))
  552. {
  553. FURI_LOG_E(TAG, "Failed to load flip social settings");
  554. return NULL;
  555. }
  556. if (strcmp(key, "ssid") == 0)
  557. {
  558. furi_string_set_str(result, ssid);
  559. }
  560. else if (strcmp(key, "password") == 0)
  561. {
  562. furi_string_set_str(result, password);
  563. }
  564. else if (strcmp(key, "login_username_logged_out") == 0)
  565. {
  566. furi_string_set_str(result, login_username_logged_out);
  567. }
  568. else if (strcmp(key, "login_username_logged_in") == 0)
  569. {
  570. furi_string_set_str(result, login_username_logged_in);
  571. }
  572. else if (strcmp(key, "login_password_logged_out") == 0)
  573. {
  574. furi_string_set_str(result, login_password_logged_out);
  575. }
  576. else if (strcmp(key, "change_password_logged_in") == 0)
  577. {
  578. furi_string_set_str(result, change_password_logged_in);
  579. }
  580. else if (strcmp(key, "change_bio_logged_in") == 0)
  581. {
  582. furi_string_set_str(result, change_bio_logged_in);
  583. }
  584. else if (strcmp(key, "is_logged_in") == 0)
  585. {
  586. furi_string_set_str(result, is_logged_in);
  587. }
  588. FURI_LOG_E(TAG, "Invalid key");
  589. furi_string_free(result);
  590. return NULL;
  591. }
  592. bool is_logged_in_to_flip_social()
  593. {
  594. // load flip social settings and check if logged in
  595. FuriString *is_logged_in = flip_social_info("is_logged_in");
  596. if (!is_logged_in)
  597. {
  598. FURI_LOG_E(TAG, "Failed to load is_logged_in");
  599. return false;
  600. }
  601. bool logged_in = furi_string_cmp(is_logged_in, "true") == 0;
  602. free(is_logged_in);
  603. return logged_in;
  604. }