xtruan 2 лет назад
Родитель
Сommit
de105644b9
3 измененных файлов с 84 добавлено и 1 удалено
  1. 73 0
      helpers/flipbip_file.c
  2. 5 0
      helpers/flipbip_file.h
  3. 6 1
      views/flipbip_scene_1.c

+ 73 - 0
helpers/flipbip_file.c

@@ -0,0 +1,73 @@
+#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);
+
+    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;
+        }
+
+        if(!flipper_format_read_string(file, "X", temp_str)) {
+            break;
+        }
+
+        result = true;
+    } while(false);
+
+    furi_record_close(RECORD_STORAGE);
+    flipper_format_free(file);
+    furi_string_free(temp_str);
+
+    return result;
+}
+
+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);
+
+    furi_record_close(RECORD_STORAGE);
+    flipper_format_free(file);
+    furi_string_free(temp_str);
+
+    return result;
+}

+ 5 - 0
helpers/flipbip_file.h

@@ -0,0 +1,5 @@
+#include <stdbool.h>
+#include <stdint.h>
+
+bool flipbip_load_file(const char* file_path);
+bool flipbip_save_file(const char* file_path);

+ 6 - 1
views/flipbip_scene_1.c

@@ -3,11 +3,13 @@
 #include <furi_hal.h>
 #include <furi_hal.h>
 #include <input/input.h>
 #include <input/input.h>
 #include <gui/elements.h>
 #include <gui/elements.h>
-#include <dolphin/dolphin.h>
+//#include <dolphin/dolphin.h>
+#include <storage/storage.h>
 #include "../helpers/flipbip_haptic.h"
 #include "../helpers/flipbip_haptic.h"
 //#include "../helpers/flipbip_speaker.h"
 //#include "../helpers/flipbip_speaker.h"
 #include "../helpers/flipbip_led.h"
 #include "../helpers/flipbip_led.h"
 #include "../helpers/flipbip_string.h"
 #include "../helpers/flipbip_string.h"
+#include "../helpers/flipbip_file.h"
 
 
 #include <string.h>
 #include <string.h>
 #include "../helpers/printf.h"
 #include "../helpers/printf.h"
@@ -271,6 +273,9 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in
     // Generate a random mnemonic using trezor-crypto
     // Generate a random mnemonic using trezor-crypto
     model->strength = strength;
     model->strength = strength;
     model->mnemonic = mnemonic_generate(model->strength);
     model->mnemonic = mnemonic_generate(model->strength);
+
+    flipbip_save_file(EXT_PATH("flipbip.dat"));
+    flipbip_load_file(EXT_PATH("flipbip.dat"));
     
     
     // test mnemonic
     // test mnemonic
     //model->mnemonic = "wealth budget salt video delay obey neutral tail sure soda hold rubber joy movie boat raccoon tornado noise off inmate payment patch group topple";
     //model->mnemonic = "wealth budget salt video delay obey neutral tail sure soda hold rubber joy movie boat raccoon tornado noise off inmate payment patch group topple";