Skip to content

Commit 7bb00ea

Browse files
authored
Use dedicated config directory instead of app folder (#48)
Signed-off-by: Kowalski Dragon (kowalski7cc) <kowalski7cc@users.noreply.github.com>
1 parent 805adfe commit 7bb00ea

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

services/config/config.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#include "../../types/token_info.h"
77
#include "migrations/config_migration_v1_to_v2.h"
88

9-
#define CONFIG_FILE_DIRECTORY_PATH "/ext/apps/Misc"
9+
#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator")
1010
#define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf"
1111
#define CONFIG_FILE_BACKUP_PATH CONFIG_FILE_PATH ".backup"
12+
#define CONFIG_FILE_PATH_PREVIOUS EXT_PATH("apps/Misc") "/totp.conf"
1213

1314
static char* token_info_get_algo_as_cstr(const TokenInfo* token_info) {
1415
switch(token_info->algo) {
@@ -53,6 +54,24 @@ FlipperFormat* totp_open_config_file(Storage* storage) {
5354
totp_close_config_file(fff_data_file);
5455
return NULL;
5556
}
57+
} else if(storage_common_stat(storage, CONFIG_FILE_PATH_PREVIOUS, NULL) == FSE_OK) {
58+
FURI_LOG_D(LOGGING_TAG, "Old config file %s found", CONFIG_FILE_PATH_PREVIOUS);
59+
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
60+
FURI_LOG_D(
61+
LOGGING_TAG,
62+
"Directory %s doesn't exist. Will create new.",
63+
CONFIG_FILE_DIRECTORY_PATH);
64+
if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
65+
FURI_LOG_E(LOGGING_TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
66+
return NULL;
67+
}
68+
}
69+
if(storage_common_rename(storage, CONFIG_FILE_PATH_PREVIOUS, CONFIG_FILE_PATH) != FSE_OK) {
70+
FURI_LOG_E(LOGGING_TAG, "Error moving config to %s", CONFIG_FILE_PATH);
71+
return NULL;
72+
}
73+
FURI_LOG_I(LOGGING_TAG, "Applied config file path migration");
74+
return totp_open_config_file(storage);
5675
} else {
5776
FURI_LOG_D(LOGGING_TAG, "Config file %s is not found. Will create new.", CONFIG_FILE_PATH);
5877
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {

0 commit comments

Comments
 (0)