Skip to content

Commit 3ef8057

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 3954713 commit 3ef8057

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

FAQ.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Pull the repo with recursive submodule initialization and then run `./build.ps1`
2020

2121
## Where is config file?
2222

23-
At first start app will create new config file (default location is [`/ext/apps/Misc/totp.conf`](https://github.com/akopachov/flipper-zero_authenticator/blob/master/totp/services/config/config.c#:~:text=%23define%20CONFIG_FILE_DIRECTORY_PATH,totp.conf%22)).
23+
At first start app will create new config file (default location is [`/ext/authenticator/totp.conf`](https://github.com/akopachov/flipper-zero_authenticator/blob/master/totp/services/config/config.c#:~:text=%23define%20CONFIG_FILE_DIRECTORY_PATH,totp.conf%22)).
2424

2525
Detailed description of file format can be found [here](docs/conf-file_description.md)
2626

docs/conf-file_description.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Flipper Authenticator config file description
22

3-
By default Flipper Authenticator stores all its settings in [`/ext/apps/Misc/totp.conf`](https://github.com/akopachov/flipper-zero_authenticator/blob/master/totp/services/config/config.c#:~:text=%23define%20CONFIG_FILE_DIRECTORY_PATH,totp.conf%22) file.
3+
By default Flipper Authenticator stores all its settings in [`/ext/authenticator/totp.conf`](https://github.com/akopachov/flipper-zero_authenticator/blob/master/totp/services/config/config.c#:~:text=%23define%20CONFIG_FILE_DIRECTORY_PATH,totp.conf%22) file.
44

55
File format is standard for Flipper Zero device. Each line has one setting identified by key, where key and value are separated by `:` symbol.
66

totp/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)