Skip to content

Commit

Permalink
Use dedicated config directory instead of app folder (#48)
Browse files Browse the repository at this point in the history
Signed-off-by: Kowalski Dragon (kowalski7cc) <kowalski7cc@users.noreply.github.com>
  • Loading branch information
kowalski7cc committed Dec 12, 2022
1 parent 805adfe commit 7bb00ea
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion services/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7bb00ea

Please sign in to comment.