|
|
@@ -444,3 +444,239 @@ bool save_world_names(const FuriString *json)
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+static bool load_flip_social_settings(
|
|
|
+ char *ssid,
|
|
|
+ size_t ssid_size,
|
|
|
+ char *password,
|
|
|
+ size_t password_size,
|
|
|
+ char *login_username_logged_out,
|
|
|
+ size_t username_out_size,
|
|
|
+ char *login_username_logged_in,
|
|
|
+ size_t username_in_size,
|
|
|
+ char *login_password_logged_out,
|
|
|
+ size_t password_out_size,
|
|
|
+ char *change_password_logged_in,
|
|
|
+ size_t change_password_size,
|
|
|
+ char *change_bio_logged_in,
|
|
|
+ size_t change_bio_size,
|
|
|
+ char *is_logged_in,
|
|
|
+ size_t is_logged_in_size)
|
|
|
+{
|
|
|
+ Storage *storage = furi_record_open(RECORD_STORAGE);
|
|
|
+ File *file = storage_file_alloc(storage);
|
|
|
+
|
|
|
+ if (!storage_file_open(file, SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING))
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to open settings file for reading: %s", SETTINGS_PATH);
|
|
|
+ storage_file_free(file);
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
+ return false; // Return false if the file does not exist
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the ssid
|
|
|
+ size_t ssid_length;
|
|
|
+ if (storage_file_read(file, &ssid_length, sizeof(size_t)) != sizeof(size_t) || ssid_length > ssid_size ||
|
|
|
+ storage_file_read(file, ssid, ssid_length) != ssid_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read SSID");
|
|
|
+ storage_file_close(file);
|
|
|
+ storage_file_free(file);
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ssid[ssid_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the password
|
|
|
+ size_t password_length;
|
|
|
+ if (storage_file_read(file, &password_length, sizeof(size_t)) != sizeof(size_t) || password_length > password_size ||
|
|
|
+ storage_file_read(file, password, password_length) != password_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read password");
|
|
|
+ storage_file_close(file);
|
|
|
+ storage_file_free(file);
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ password[password_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the login_username_logged_out
|
|
|
+ size_t username_out_length;
|
|
|
+ if (storage_file_read(file, &username_out_length, sizeof(size_t)) != sizeof(size_t) || username_out_length > username_out_size ||
|
|
|
+ storage_file_read(file, login_username_logged_out, username_out_length) != username_out_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read login_username_logged_out");
|
|
|
+ // storage_file_close(file);
|
|
|
+ // storage_file_free(file);
|
|
|
+ // furi_record_close(RECORD_STORAGE);
|
|
|
+ // return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ login_username_logged_out[username_out_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the login_username_logged_in
|
|
|
+ size_t username_in_length;
|
|
|
+ if (storage_file_read(file, &username_in_length, sizeof(size_t)) != sizeof(size_t) || username_in_length > username_in_size ||
|
|
|
+ storage_file_read(file, login_username_logged_in, username_in_length) != username_in_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read login_username_logged_in");
|
|
|
+ // storage_file_close(file);
|
|
|
+ // storage_file_free(file);
|
|
|
+ // furi_record_close(RECORD_STORAGE);
|
|
|
+ // return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ login_username_logged_in[username_in_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the login_password_logged_out
|
|
|
+ size_t password_out_length;
|
|
|
+ if (storage_file_read(file, &password_out_length, sizeof(size_t)) != sizeof(size_t) || password_out_length > password_out_size ||
|
|
|
+ storage_file_read(file, login_password_logged_out, password_out_length) != password_out_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read login_password_logged_out");
|
|
|
+ // storage_file_close(file);
|
|
|
+ // storage_file_free(file);
|
|
|
+ // furi_record_close(RECORD_STORAGE);
|
|
|
+ // return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ login_password_logged_out[password_out_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the change_password_logged_in
|
|
|
+ size_t change_password_length;
|
|
|
+ if (storage_file_read(file, &change_password_length, sizeof(size_t)) != sizeof(size_t) || change_password_length > change_password_size ||
|
|
|
+ storage_file_read(file, change_password_logged_in, change_password_length) != change_password_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read change_password_logged_in");
|
|
|
+ // storage_file_close(file);
|
|
|
+ // storage_file_free(file);
|
|
|
+ // furi_record_close(RECORD_STORAGE);
|
|
|
+ // return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ change_password_logged_in[change_password_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the is_logged_in
|
|
|
+ size_t is_logged_in_length;
|
|
|
+ if (storage_file_read(file, &is_logged_in_length, sizeof(size_t)) != sizeof(size_t) || is_logged_in_length > is_logged_in_size ||
|
|
|
+ storage_file_read(file, is_logged_in, is_logged_in_length) != is_logged_in_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read is_logged_in");
|
|
|
+ // storage_file_close(file);
|
|
|
+ // storage_file_free(file);
|
|
|
+ // furi_record_close(RECORD_STORAGE);
|
|
|
+ // return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ is_logged_in[is_logged_in_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load the change_bio_logged_in
|
|
|
+ size_t change_bio_length;
|
|
|
+ if (storage_file_read(file, &change_bio_length, sizeof(size_t)) != sizeof(size_t) || change_bio_length > change_bio_size ||
|
|
|
+ storage_file_read(file, change_bio_logged_in, change_bio_length) != change_bio_length)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to read change_bio_logged_in");
|
|
|
+ // storage_file_close(file);
|
|
|
+ // storage_file_free(file);
|
|
|
+ // furi_record_close(RECORD_STORAGE);
|
|
|
+ // return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ change_bio_logged_in[change_bio_length - 1] = '\0'; // Ensure null-termination
|
|
|
+ }
|
|
|
+
|
|
|
+ storage_file_close(file);
|
|
|
+ storage_file_free(file);
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+FuriString *flip_social_info(char *key)
|
|
|
+{
|
|
|
+ char ssid[64];
|
|
|
+ char password[64];
|
|
|
+ char login_username_logged_out[64];
|
|
|
+ char login_username_logged_in[64];
|
|
|
+ char login_password_logged_out[64];
|
|
|
+ char change_password_logged_in[64];
|
|
|
+ char change_bio_logged_in[64];
|
|
|
+ char is_logged_in[64];
|
|
|
+ FuriString *result = furi_string_alloc();
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to allocate FuriString");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ 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)))
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to load flip social settings");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ if (strcmp(key, "ssid") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, ssid);
|
|
|
+ }
|
|
|
+ else if (strcmp(key, "password") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, password);
|
|
|
+ }
|
|
|
+ else if (strcmp(key, "login_username_logged_out") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, login_username_logged_out);
|
|
|
+ }
|
|
|
+ else if (strcmp(key, "login_username_logged_in") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, login_username_logged_in);
|
|
|
+ }
|
|
|
+ else if (strcmp(key, "login_password_logged_out") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, login_password_logged_out);
|
|
|
+ }
|
|
|
+ else if (strcmp(key, "change_password_logged_in") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, change_password_logged_in);
|
|
|
+ }
|
|
|
+ else if (strcmp(key, "change_bio_logged_in") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, change_bio_logged_in);
|
|
|
+ }
|
|
|
+ else if (strcmp(key, "is_logged_in") == 0)
|
|
|
+ {
|
|
|
+ furi_string_set_str(result, is_logged_in);
|
|
|
+ }
|
|
|
+ FURI_LOG_E(TAG, "Invalid key");
|
|
|
+ furi_string_free(result);
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
+bool is_logged_in_to_flip_social()
|
|
|
+{
|
|
|
+ // load flip social settings and check if logged in
|
|
|
+ FuriString *is_logged_in = flip_social_info("is_logged_in");
|
|
|
+ if (!is_logged_in)
|
|
|
+ {
|
|
|
+ FURI_LOG_E(TAG, "Failed to load is_logged_in");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ bool logged_in = furi_string_cmp(is_logged_in, "true") == 0;
|
|
|
+ free(is_logged_in);
|
|
|
+ return logged_in;
|
|
|
+}
|