瀏覽代碼

Use dedicated config directory instead of app folder (#48)

Signed-off-by: Kowalski Dragon (kowalski7cc) <kowalski7cc@users.noreply.github.com>
Kowalski Dragon 3 年之前
父節點
當前提交
3ef8057b9c
共有 3 個文件被更改,包括 22 次插入3 次删除
  1. 1 1
      FAQ.md
  2. 1 1
      docs/conf-file_description.md
  3. 20 1
      totp/services/config/config.c

+ 1 - 1
FAQ.md

@@ -20,7 +20,7 @@ Pull the repo with recursive submodule initialization and then run `./build.ps1`
 
 
 ## Where is config file?
 ## Where is config file?
 
 
-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)).
+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)).
 
 
 Detailed description of file format can be found [here](docs/conf-file_description.md)
 Detailed description of file format can be found [here](docs/conf-file_description.md)
 
 

+ 1 - 1
docs/conf-file_description.md

@@ -1,6 +1,6 @@
 # Flipper Authenticator config file description
 # Flipper Authenticator config file description
 
 
-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.
+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.
 
 
 File format is standard for Flipper Zero device. Each line has one setting identified by key, where key and value are separated by `:` symbol.
 File format is standard for Flipper Zero device. Each line has one setting identified by key, where key and value are separated by `:` symbol.
 
 

+ 20 - 1
totp/services/config/config.c

@@ -6,9 +6,10 @@
 #include "../../types/token_info.h"
 #include "../../types/token_info.h"
 #include "migrations/config_migration_v1_to_v2.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_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf"
 #define CONFIG_FILE_BACKUP_PATH CONFIG_FILE_PATH ".backup"
 #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) {
 static char* token_info_get_algo_as_cstr(const TokenInfo* token_info) {
     switch(token_info->algo) {
     switch(token_info->algo) {
@@ -53,6 +54,24 @@ FlipperFormat* totp_open_config_file(Storage* storage) {
             totp_close_config_file(fff_data_file);
             totp_close_config_file(fff_data_file);
             return NULL;
             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 {
     } else {
         FURI_LOG_D(LOGGING_TAG, "Config file %s is not found. Will create new.", CONFIG_FILE_PATH);
         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) {
         if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {