Fixed writing to files
This commit is contained in:
parent
1c06b7b4a7
commit
029da1eb25
2 changed files with 31 additions and 11 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
// Constants
|
||||
#define TAG "FlippyPass"
|
||||
#define DIR EXT_PATH("apps_data/fpass")
|
||||
#define PATH EXT_PATH("apps_data/fpass/data.bin")
|
||||
|
||||
#endif
|
|
@ -2,8 +2,30 @@
|
|||
#include "store.h"
|
||||
#include <flipper_format.h>
|
||||
|
||||
// Functions - Private
|
||||
void store_folder_init() {
|
||||
// Opening storage record
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
// DEBUG
|
||||
FURI_LOG_I(TAG, "Creating FlipperPass Folder");
|
||||
|
||||
// Creating folder
|
||||
if (storage_simply_mkdir(storage, DIR)) {
|
||||
FURI_LOG_I(TAG, "Created FPass Directory");
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "FPass Directory already exists");
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
// Constructors
|
||||
FStorage* store_load(char* type) {
|
||||
// Init Folders
|
||||
store_folder_init();
|
||||
|
||||
// Allocating memory for storage struct
|
||||
FStorage* result = malloc(sizeof(FStorage));
|
||||
result->valid = false;
|
||||
|
@ -74,19 +96,16 @@ void store_save(char* type, char* data) {
|
|||
furi_string_set_str(_data, data);
|
||||
|
||||
// Opening new file
|
||||
if (!flipper_format_file_open_existing(_format, PATH)) {
|
||||
// New user?
|
||||
FURI_LOG_I(TAG, "File not found, creating user at %s", PATH);
|
||||
if (!flipper_format_file_open_always(_format, PATH)) {
|
||||
// DEBUG
|
||||
FURI_LOG_E(TAG, "Failed to create/open file at %s", PATH);
|
||||
|
||||
// Trying to create a new file
|
||||
if (!flipper_format_file_open_new(_format, PATH)) {
|
||||
FURI_LOG_E(TAG, "Failed to create new file at %s", PATH);
|
||||
// Cleanup
|
||||
furi_string_free(_data);
|
||||
flipper_format_free(_format);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Writing string
|
||||
if (!flipper_format_write_string(_format, type, _data)) {
|
||||
|
|
Loading…
Reference in a new issue