From 7bb00eaa44b8b88655baa254e921a84d538d52ef Mon Sep 17 00:00:00 2001 From: Kowalski Dragon Date: Mon, 12 Dec 2022 14:20:14 +0100 Subject: [PATCH] Use dedicated config directory instead of app folder (#48) Signed-off-by: Kowalski Dragon (kowalski7cc) --- services/config/config.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/services/config/config.c b/services/config/config.c index ff7e4eb2d38..7a7d3bb3a93 100644 --- a/services/config/config.c +++ b/services/config/config.c @@ -6,9 +6,10 @@ #include "../../types/token_info.h" #include "migrations/config_migration_v1_to_v2.h" -#define CONFIG_FILE_DIRECTORY_PATH "/ext/apps/Misc" +#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator") #define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf" #define CONFIG_FILE_BACKUP_PATH CONFIG_FILE_PATH ".backup" +#define CONFIG_FILE_PATH_PREVIOUS EXT_PATH("apps/Misc") "/totp.conf" static char* token_info_get_algo_as_cstr(const TokenInfo* token_info) { switch(token_info->algo) { @@ -53,6 +54,24 @@ FlipperFormat* totp_open_config_file(Storage* storage) { totp_close_config_file(fff_data_file); return NULL; } + } else if(storage_common_stat(storage, CONFIG_FILE_PATH_PREVIOUS, NULL) == FSE_OK) { + FURI_LOG_D(LOGGING_TAG, "Old config file %s found", CONFIG_FILE_PATH_PREVIOUS); + if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) { + FURI_LOG_D( + LOGGING_TAG, + "Directory %s doesn't exist. Will create new.", + CONFIG_FILE_DIRECTORY_PATH); + if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) { + FURI_LOG_E(LOGGING_TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH); + return NULL; + } + } + if(storage_common_rename(storage, CONFIG_FILE_PATH_PREVIOUS, CONFIG_FILE_PATH) != FSE_OK) { + FURI_LOG_E(LOGGING_TAG, "Error moving config to %s", CONFIG_FILE_PATH); + return NULL; + } + FURI_LOG_I(LOGGING_TAG, "Applied config file path migration"); + return totp_open_config_file(storage); } else { FURI_LOG_D(LOGGING_TAG, "Config file %s is not found. Will create new.", CONFIG_FILE_PATH); if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {