storage.c 22 KB

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