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
|
// Constants
|
||||||
#define TAG "FlippyPass"
|
#define TAG "FlippyPass"
|
||||||
|
#define DIR EXT_PATH("apps_data/fpass")
|
||||||
#define PATH EXT_PATH("apps_data/fpass/data.bin")
|
#define PATH EXT_PATH("apps_data/fpass/data.bin")
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -2,8 +2,30 @@
|
||||||
#include "store.h"
|
#include "store.h"
|
||||||
#include <flipper_format.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
|
// Constructors
|
||||||
FStorage* store_load(char* type) {
|
FStorage* store_load(char* type) {
|
||||||
|
// Init Folders
|
||||||
|
store_folder_init();
|
||||||
|
|
||||||
// Allocating memory for storage struct
|
// Allocating memory for storage struct
|
||||||
FStorage* result = malloc(sizeof(FStorage));
|
FStorage* result = malloc(sizeof(FStorage));
|
||||||
result->valid = false;
|
result->valid = false;
|
||||||
|
@ -74,18 +96,15 @@ void store_save(char* type, char* data) {
|
||||||
furi_string_set_str(_data, data);
|
furi_string_set_str(_data, data);
|
||||||
|
|
||||||
// Opening new file
|
// Opening new file
|
||||||
if (!flipper_format_file_open_existing(_format, PATH)) {
|
if (!flipper_format_file_open_always(_format, PATH)) {
|
||||||
// New user?
|
// DEBUG
|
||||||
FURI_LOG_I(TAG, "File not found, creating user at %s", PATH);
|
FURI_LOG_E(TAG, "Failed to create/open file at %s", PATH);
|
||||||
|
|
||||||
// Trying to create a new file
|
// Cleanup
|
||||||
if (!flipper_format_file_open_new(_format, PATH)) {
|
furi_string_free(_data);
|
||||||
FURI_LOG_E(TAG, "Failed to create new file at %s", PATH);
|
flipper_format_free(_format);
|
||||||
furi_string_free(_data);
|
furi_record_close(RECORD_STORAGE);
|
||||||
flipper_format_free(_format);
|
return;
|
||||||
furi_record_close(RECORD_STORAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writing string
|
// Writing string
|
||||||
|
|
Loading…
Reference in a new issue