|
|
@@ -1,73 +1,68 @@
|
|
|
#include "flipbip_file.h"
|
|
|
-
|
|
|
#include "../flipbip.h"
|
|
|
|
|
|
-#include <storage/storage.h>
|
|
|
-#include <lib/flipper_format/flipper_format.h>
|
|
|
-
|
|
|
-bool flipbip_load_file(const char* file_path) {
|
|
|
- furi_assert(file_path);
|
|
|
-
|
|
|
- bool result = false;
|
|
|
- FuriString* temp_str;
|
|
|
- temp_str = furi_string_alloc();
|
|
|
-
|
|
|
- Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
- FlipperFormat* file = flipper_format_file_alloc(storage);
|
|
|
+#include "../crypto/memzero.h"
|
|
|
|
|
|
- do {
|
|
|
- if(!flipper_format_file_open_existing(file, file_path)) break;
|
|
|
-
|
|
|
- uint32_t version = 0;
|
|
|
- if(!flipper_format_read_header(file, temp_str, &version)) break;
|
|
|
- if(furi_string_cmp_str(temp_str, "FlipBIP") ||
|
|
|
- (version != 1)) {
|
|
|
- break;
|
|
|
- }
|
|
|
+#include <storage/storage.h>
|
|
|
|
|
|
- if(!flipper_format_read_string(file, "X", temp_str)) {
|
|
|
- break;
|
|
|
+#define FLIPBIP_APP_BASE_FOLDER EXT_PATH("apps_data/flipbip")
|
|
|
+// #define FLIPBIP_SETTINGS_FILE_NAME ".flipbip.dat"
|
|
|
+#define FLIPBIP_SETTINGS_FILE_NAME ".flipbip.txt"
|
|
|
+#define FLIPBIP_SETTINGS_PATH FLIPBIP_APP_BASE_FOLDER "/" FLIPBIP_SETTINGS_FILE_NAME
|
|
|
+
|
|
|
+bool flipbip_load_settings(char* settings) {
|
|
|
+ Storage *fs_api = furi_record_open(RECORD_STORAGE);
|
|
|
+ File* settings_file = storage_file_alloc(fs_api);
|
|
|
+ if(storage_file_open(settings_file, FLIPBIP_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
+ char chr;
|
|
|
+ int i = 0;
|
|
|
+ while((storage_file_read(settings_file, &chr, 1) == 1) &&
|
|
|
+ !storage_file_eof(settings_file) && !isspace(chr)) {
|
|
|
+ settings[i] = chr;
|
|
|
+ i++;
|
|
|
}
|
|
|
-
|
|
|
- result = true;
|
|
|
- } while(false);
|
|
|
-
|
|
|
+ } else {
|
|
|
+ memzero(settings, strlen(settings));
|
|
|
+ settings[0] = '\0';
|
|
|
+ }
|
|
|
+ storage_file_close(settings_file);
|
|
|
+ storage_file_free(settings_file);
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
- flipper_format_free(file);
|
|
|
- furi_string_free(temp_str);
|
|
|
|
|
|
- return result;
|
|
|
+ // if(!strlen(settings) == 0) {
|
|
|
+ // Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
|
|
+ // FileInfo layout_file_info;
|
|
|
+ // FS_Error file_check_err = storage_common_stat(
|
|
|
+ // fs_api, FLIPBIP_SETTINGS_PATH, &layout_file_info);
|
|
|
+ // furi_record_close(RECORD_STORAGE);
|
|
|
+ // if(file_check_err != FSE_OK) {
|
|
|
+ // memzero(settings, strlen(settings));
|
|
|
+ // settings[0] = '\0';
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // if(layout_file_info.size != 256) {
|
|
|
+ // memzero(settings, strlen(settings));
|
|
|
+ // settings[0] = '\0';
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
-bool flipbip_save_file(const char* file_path) {
|
|
|
- furi_assert(file_path);
|
|
|
-
|
|
|
- bool result = false;
|
|
|
- FuriString* temp_str;
|
|
|
- temp_str = furi_string_alloc();
|
|
|
-
|
|
|
- Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
- FlipperFormat* file = flipper_format_file_alloc(storage);
|
|
|
-
|
|
|
- do {
|
|
|
- if(!flipper_format_file_open_existing(file, file_path) ||
|
|
|
- !flipper_format_file_open_new(file, file_path)) break;
|
|
|
-
|
|
|
- //uint32_t version = 1;
|
|
|
- //temp_str = "FlipBIP";
|
|
|
- if(!flipper_format_write_header_cstr(file, "FlipBIP", 1)) break;
|
|
|
-
|
|
|
- //temp_str = "12345abcde";
|
|
|
- if(!flipper_format_write_string_cstr(file, "X", "12345abcde")) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- result = true;
|
|
|
- } while(false);
|
|
|
-
|
|
|
+bool flipbip_save_settings(const char* settings) {
|
|
|
+ Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
|
|
+ File* settings_file = storage_file_alloc(fs_api);
|
|
|
+ storage_common_mkdir(fs_api, FLIPBIP_APP_BASE_FOLDER);
|
|
|
+ if(storage_file_open(settings_file, FLIPBIP_SETTINGS_PATH, FSAM_WRITE, FSOM_OPEN_ALWAYS)) {
|
|
|
+ storage_file_write(
|
|
|
+ settings_file,
|
|
|
+ settings,
|
|
|
+ strlen(settings));
|
|
|
+ storage_file_write(settings_file, "\n", 1);
|
|
|
+ }
|
|
|
+ storage_file_close(settings_file);
|
|
|
+ storage_file_free(settings_file);
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
- flipper_format_free(file);
|
|
|
- furi_string_free(temp_str);
|
|
|
|
|
|
- return result;
|
|
|
+ return true;
|
|
|
}
|