Skip to content

Commit

Permalink
storage stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 4, 2023
1 parent 4ea47f6 commit de10564
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
73 changes: 73 additions & 0 deletions helpers/flipbip_file.c
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions helpers/flipbip_file.h
Original file line number Diff line number Diff line change
@@ -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);
7 changes: 6 additions & 1 deletion views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include <furi_hal.h>
#include <input/input.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_speaker.h"
#include "../helpers/flipbip_led.h"
#include "../helpers/flipbip_string.h"
#include "../helpers/flipbip_file.h"

#include <string.h>
#include "../helpers/printf.h"
Expand Down Expand Up @@ -271,6 +273,9 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in
// Generate a random mnemonic using trezor-crypto
model->strength = strength;
model->mnemonic = mnemonic_generate(model->strength);

flipbip_save_file(EXT_PATH("flipbip.dat"));
flipbip_load_file(EXT_PATH("flipbip.dat"));

// 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";
Expand Down

0 comments on commit de10564

Please sign in to comment.