Skip to content

Commit de10564

Browse files
committed
storage stubs
1 parent 4ea47f6 commit de10564

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

helpers/flipbip_file.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "flipbip_file.h"
2+
3+
#include "../flipbip.h"
4+
5+
#include <storage/storage.h>
6+
#include <lib/flipper_format/flipper_format.h>
7+
8+
bool flipbip_load_file(const char* file_path) {
9+
furi_assert(file_path);
10+
11+
bool result = false;
12+
FuriString* temp_str;
13+
temp_str = furi_string_alloc();
14+
15+
Storage* storage = furi_record_open(RECORD_STORAGE);
16+
FlipperFormat* file = flipper_format_file_alloc(storage);
17+
18+
do {
19+
if(!flipper_format_file_open_existing(file, file_path)) break;
20+
21+
uint32_t version = 0;
22+
if(!flipper_format_read_header(file, temp_str, &version)) break;
23+
if(furi_string_cmp_str(temp_str, "FlipBIP") ||
24+
(version != 1)) {
25+
break;
26+
}
27+
28+
if(!flipper_format_read_string(file, "X", temp_str)) {
29+
break;
30+
}
31+
32+
result = true;
33+
} while(false);
34+
35+
furi_record_close(RECORD_STORAGE);
36+
flipper_format_free(file);
37+
furi_string_free(temp_str);
38+
39+
return result;
40+
}
41+
42+
bool flipbip_save_file(const char* file_path) {
43+
furi_assert(file_path);
44+
45+
bool result = false;
46+
FuriString* temp_str;
47+
temp_str = furi_string_alloc();
48+
49+
Storage* storage = furi_record_open(RECORD_STORAGE);
50+
FlipperFormat* file = flipper_format_file_alloc(storage);
51+
52+
do {
53+
if(!flipper_format_file_open_existing(file, file_path) ||
54+
!flipper_format_file_open_new(file, file_path)) break;
55+
56+
//uint32_t version = 1;
57+
//temp_str = "FlipBIP";
58+
if(!flipper_format_write_header_cstr(file, "FlipBIP", 1)) break;
59+
60+
//temp_str = "12345abcde";
61+
if(!flipper_format_write_string_cstr(file, "X", "12345abcde")) {
62+
break;
63+
}
64+
65+
result = true;
66+
} while(false);
67+
68+
furi_record_close(RECORD_STORAGE);
69+
flipper_format_free(file);
70+
furi_string_free(temp_str);
71+
72+
return result;
73+
}

helpers/flipbip_file.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
4+
bool flipbip_load_file(const char* file_path);
5+
bool flipbip_save_file(const char* file_path);

views/flipbip_scene_1.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#include <furi_hal.h>
44
#include <input/input.h>
55
#include <gui/elements.h>
6-
#include <dolphin/dolphin.h>
6+
//#include <dolphin/dolphin.h>
7+
#include <storage/storage.h>
78
#include "../helpers/flipbip_haptic.h"
89
//#include "../helpers/flipbip_speaker.h"
910
#include "../helpers/flipbip_led.h"
1011
#include "../helpers/flipbip_string.h"
12+
#include "../helpers/flipbip_file.h"
1113

1214
#include <string.h>
1315
#include "../helpers/printf.h"
@@ -271,6 +273,9 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in
271273
// Generate a random mnemonic using trezor-crypto
272274
model->strength = strength;
273275
model->mnemonic = mnemonic_generate(model->strength);
276+
277+
flipbip_save_file(EXT_PATH("flipbip.dat"));
278+
flipbip_load_file(EXT_PATH("flipbip.dat"));
274279

275280
// test mnemonic
276281
//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";

0 commit comments

Comments
 (0)