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
+ }
0 commit comments