diff --git a/project/backend/app.h b/project/backend/app.h index afe4c46..c9b4e40 100644 --- a/project/backend/app.h +++ b/project/backend/app.h @@ -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 \ No newline at end of file diff --git a/project/backend/store.c b/project/backend/store.c index 6336a85..0456058 100644 --- a/project/backend/store.c +++ b/project/backend/store.c @@ -2,8 +2,30 @@ #include "store.h" #include +// 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,18 +96,15 @@ 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); - furi_string_free(_data); - flipper_format_free(_format); - furi_record_close(RECORD_STORAGE); - return; - } + // Cleanup + furi_string_free(_data); + flipper_format_free(_format); + furi_record_close(RECORD_STORAGE); + return; } // Writing string