From 10096ec95a7e7e5ffa27a5f3c818ecce4f50580f Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 28 Mar 2023 00:13:28 +0100 Subject: [PATCH] Store main settings in dedicated ext folder --- .../main/archive/helpers/archive_favorites.c | 7 +++++++ .../main/archive/helpers/archive_favorites.h | 5 +++-- applications/services/bt/bt_service/bt_i.h | 6 ++---- .../services/bt/bt_service/bt_keys_filename.h | 3 --- applications/services/bt/bt_settings.c | 4 ++-- applications/services/bt/bt_settings.h | 4 +--- .../services/bt/bt_settings_filename.h | 3 --- .../services/desktop/desktop_settings.h | 6 ++---- .../desktop/desktop_settings_filename.h | 3 --- .../services/dolphin/helpers/dolphin_state.c | 5 ++--- .../dolphin/helpers/dolphin_state_filename.h | 3 --- applications/services/power/power_settings.h | 5 ++--- .../services/power/power_settings_filename.h | 3 --- .../services/rgb_backlight/rgb_backlight.c | 3 +-- applications/services/storage/storage.h | 2 ++ .../services/storage/storage_processing.c | 8 +++++++ applications/services/xtreme/settings.c | 21 ++++++++++++------- applications/services/xtreme/settings.h | 9 ++++---- .../services/xtreme/settings_filename.h | 4 ---- .../updater/util/update_task_worker_backup.c | 10 +++++++-- lib/update_util/lfs_backup.c | 8 ------- 21 files changed, 58 insertions(+), 64 deletions(-) delete mode 100644 applications/services/bt/bt_service/bt_keys_filename.h delete mode 100644 applications/services/bt/bt_settings_filename.h delete mode 100644 applications/services/desktop/desktop_settings_filename.h delete mode 100644 applications/services/dolphin/helpers/dolphin_state_filename.h delete mode 100644 applications/services/power/power_settings_filename.h delete mode 100644 applications/services/xtreme/settings_filename.h diff --git a/applications/main/archive/helpers/archive_favorites.c b/applications/main/archive/helpers/archive_favorites.c index f395ee5a1..7304be6b4 100644 --- a/applications/main/archive/helpers/archive_favorites.c +++ b/applications/main/archive/helpers/archive_favorites.c @@ -140,6 +140,13 @@ bool archive_favorites_read(void* context) { bool result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING); + if(!result) { + storage_file_close(file); + storage_common_copy(storage, ARCHIVE_FAV_OLD_PATH, ARCHIVE_FAV_PATH); + storage_common_remove(storage, ARCHIVE_FAV_OLD_PATH); + result = storage_file_open(file, ARCHIVE_FAV_PATH, FSAM_READ, FSOM_OPEN_EXISTING); + } + if(result) { while(1) { if(!archive_favorites_read_line(file, buffer)) { diff --git a/applications/main/archive/helpers/archive_favorites.h b/applications/main/archive/helpers/archive_favorites.h index db8943378..e45af92e7 100644 --- a/applications/main/archive/helpers/archive_favorites.h +++ b/applications/main/archive/helpers/archive_favorites.h @@ -2,8 +2,9 @@ #include -#define ARCHIVE_FAV_PATH ANY_PATH("favorites.txt") -#define ARCHIVE_FAV_TEMP_PATH ANY_PATH("favorites.tmp") +#define ARCHIVE_FAV_OLD_PATH EXT_PATH("favorites.txt") +#define ARCHIVE_FAV_PATH CFG_PATH("favorites.txt") +#define ARCHIVE_FAV_TEMP_PATH CFG_PATH("favorites.tmp") uint16_t archive_favorites_count(void* context); bool archive_favorites_read(void* context); diff --git a/applications/services/bt/bt_service/bt_i.h b/applications/services/bt/bt_service/bt_i.h index 92656e791..dc36ea40b 100644 --- a/applications/services/bt/bt_service/bt_i.h +++ b/applications/services/bt/bt_service/bt_i.h @@ -18,10 +18,8 @@ #include #include -#include "bt_keys_filename.h" - -#define BT_KEYS_STORAGE_OLD_PATH INT_PATH(BT_KEYS_STORAGE_FILE_NAME) -#define BT_KEYS_STORAGE_PATH EXT_PATH(BT_KEYS_STORAGE_FILE_NAME) +#define BT_KEYS_STORAGE_OLD_PATH INT_PATH(".bt.keys") +#define BT_KEYS_STORAGE_PATH CFG_PATH("bt.keys") #define BT_API_UNLOCK_EVENT (1UL << 0) diff --git a/applications/services/bt/bt_service/bt_keys_filename.h b/applications/services/bt/bt_service/bt_keys_filename.h deleted file mode 100644 index da1d3f54e..000000000 --- a/applications/services/bt/bt_service/bt_keys_filename.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define BT_KEYS_STORAGE_FILE_NAME ".bt.keys" diff --git a/applications/services/bt/bt_settings.c b/applications/services/bt/bt_settings.c index e7fc65ad7..e2b652025 100644 --- a/applications/services/bt/bt_settings.c +++ b/applications/services/bt/bt_settings.c @@ -4,8 +4,8 @@ #include #include -#define BT_SETTINGS_OLD_PATH INT_PATH(BT_SETTINGS_FILE_NAME) -#define BT_SETTINGS_PATH EXT_PATH(BT_SETTINGS_FILE_NAME) +#define BT_SETTINGS_OLD_PATH INT_PATH(".bt.settings") +#define BT_SETTINGS_PATH CFG_PATH("bt.settings") #define BT_SETTINGS_VERSION (0) #define BT_SETTINGS_MAGIC (0x19) diff --git a/applications/services/bt/bt_settings.h b/applications/services/bt/bt_settings.h index 9ed8be89c..620a3f5a6 100644 --- a/applications/services/bt/bt_settings.h +++ b/applications/services/bt/bt_settings.h @@ -1,7 +1,5 @@ #pragma once -#include "bt_settings_filename.h" - #include #include @@ -19,4 +17,4 @@ bool bt_settings_save(BtSettings* bt_settings); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/bt/bt_settings_filename.h b/applications/services/bt/bt_settings_filename.h deleted file mode 100644 index e5fb7ec48..000000000 --- a/applications/services/bt/bt_settings_filename.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define BT_SETTINGS_FILE_NAME ".bt.settings" diff --git a/applications/services/desktop/desktop_settings.h b/applications/services/desktop/desktop_settings.h index c915e466c..62d4e5aae 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -1,7 +1,5 @@ #pragma once -#include "desktop_settings_filename.h" - #include #include #include @@ -11,8 +9,8 @@ #define DESKTOP_SETTINGS_VER (7) -#define DESKTOP_SETTINGS_OLD_PATH INT_PATH(DESKTOP_SETTINGS_FILE_NAME) -#define DESKTOP_SETTINGS_PATH EXT_PATH(DESKTOP_SETTINGS_FILE_NAME) +#define DESKTOP_SETTINGS_OLD_PATH INT_PATH(".desktop.settings") +#define DESKTOP_SETTINGS_PATH CFG_PATH("desktop.settings") #define DESKTOP_SETTINGS_MAGIC (0x17) #define PIN_MAX_LENGTH 12 diff --git a/applications/services/desktop/desktop_settings_filename.h b/applications/services/desktop/desktop_settings_filename.h deleted file mode 100644 index b9140f24c..000000000 --- a/applications/services/desktop/desktop_settings_filename.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define DESKTOP_SETTINGS_FILE_NAME ".desktop.settings" diff --git a/applications/services/dolphin/helpers/dolphin_state.c b/applications/services/dolphin/helpers/dolphin_state.c index 4ffaaa8ba..190efa5ec 100644 --- a/applications/services/dolphin/helpers/dolphin_state.c +++ b/applications/services/dolphin/helpers/dolphin_state.c @@ -1,6 +1,5 @@ #include "dolphin_state.h" #include "dolphin/helpers/dolphin_deed.h" -#include "dolphin_state_filename.h" #include #include @@ -11,8 +10,8 @@ #define TAG "DolphinState" -#define DOLPHIN_STATE_OLD_PATH INT_PATH(DOLPHIN_STATE_FILE_NAME) -#define DOLPHIN_STATE_PATH EXT_PATH(DOLPHIN_STATE_FILE_NAME) +#define DOLPHIN_STATE_OLD_PATH INT_PATH(".dolphin.state") +#define DOLPHIN_STATE_PATH CFG_PATH("dolphin.state") #define DOLPHIN_STATE_HEADER_MAGIC 0xD0 #define DOLPHIN_STATE_HEADER_VERSION 0x01 diff --git a/applications/services/dolphin/helpers/dolphin_state_filename.h b/applications/services/dolphin/helpers/dolphin_state_filename.h deleted file mode 100644 index 86822c0ac..000000000 --- a/applications/services/dolphin/helpers/dolphin_state_filename.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define DOLPHIN_STATE_FILE_NAME ".dolphin.state" diff --git a/applications/services/power/power_settings.h b/applications/services/power/power_settings.h index 7067521a3..5c079369c 100644 --- a/applications/services/power/power_settings.h +++ b/applications/services/power/power_settings.h @@ -1,11 +1,10 @@ #include #include -#include "power_settings_filename.h" #define POWER_SETTINGS_VER (1) -#define POWER_SETTINGS_OLD_PATH INT_PATH(POWER_SETTINGS_FILE_NAME) -#define POWER_SETTINGS_PATH EXT_PATH(POWER_SETTINGS_FILE_NAME) +#define POWER_SETTINGS_OLD_PATH INT_PATH(".power.settings") +#define POWER_SETTINGS_PATH CFG_PATH("power.settings") #define POWER_SETTINGS_MAGIC (0x21) bool SAVE_POWER_SETTINGS(uint32_t* x); diff --git a/applications/services/power/power_settings_filename.h b/applications/services/power/power_settings_filename.h deleted file mode 100644 index 6a3be534c..000000000 --- a/applications/services/power/power_settings_filename.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define POWER_SETTINGS_FILE_NAME ".power.settings" \ No newline at end of file diff --git a/applications/services/rgb_backlight/rgb_backlight.c b/applications/services/rgb_backlight/rgb_backlight.c index 30c85cbab..d7ab89975 100644 --- a/applications/services/rgb_backlight/rgb_backlight.c +++ b/applications/services/rgb_backlight/rgb_backlight.c @@ -21,8 +21,7 @@ #include #define RGB_BACKLIGHT_SETTINGS_VERSION 5 -#define RGB_BACKLIGHT_SETTINGS_FILE_NAME ".rgb_backlight.settings" -#define RGB_BACKLIGHT_SETTINGS_PATH EXT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) +#define RGB_BACKLIGHT_SETTINGS_PATH CFG_PATH("rgb_backlight.settings") #define COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightColor)) diff --git a/applications/services/storage/storage.h b/applications/services/storage/storage.h index 5991e765f..78dae7a2c 100644 --- a/applications/services/storage/storage.h +++ b/applications/services/storage/storage.h @@ -12,12 +12,14 @@ extern "C" { #define STORAGE_ANY_PATH_PREFIX "/any" #define STORAGE_APP_DATA_PATH_PREFIX "/data" #define STORAGE_APP_ASSETS_PATH_PREFIX "/assets" +#define STORAGE_CFG_PATH_PREFIX STORAGE_EXT_PATH_PREFIX "/.config" #define INT_PATH(path) STORAGE_INT_PATH_PREFIX "/" path #define EXT_PATH(path) STORAGE_EXT_PATH_PREFIX "/" path #define ANY_PATH(path) STORAGE_ANY_PATH_PREFIX "/" path #define APP_DATA_PATH(path) STORAGE_APP_DATA_PATH_PREFIX "/" path #define APP_ASSETS_PATH(path) STORAGE_APP_ASSETS_PATH_PREFIX "/" path +#define CFG_PATH(path) STORAGE_CFG_PATH_PREFIX "/" path #define RECORD_STORAGE "storage" diff --git a/applications/services/storage/storage_processing.c b/applications/services/storage/storage_processing.c index e6b426961..116f67b4f 100644 --- a/applications/services/storage/storage_processing.c +++ b/applications/services/storage/storage_processing.c @@ -500,6 +500,14 @@ void storage_process_alias( furi_string_get_cstr(apps_assets_path_with_appsid)); furi_string_free(apps_assets_path_with_appsid); + } else if(furi_string_start_with(path, STORAGE_CFG_PATH_PREFIX)) { + // Create config folder if it doesn't exist + FuriString* config_path = furi_string_alloc_set(STORAGE_CFG_PATH_PREFIX); + if(create_folders && + storage_process_common_stat(app, config_path, NULL) != FSE_OK) { + storage_process_common_mkdir(app, config_path); + } + furi_string_free(config_path); } } diff --git a/applications/services/xtreme/settings.c b/applications/services/xtreme/settings.c index 292d2880b..799c1a768 100644 --- a/applications/services/xtreme/settings.c +++ b/applications/services/xtreme/settings.c @@ -27,13 +27,23 @@ void XTREME_SETTINGS_LOAD() { sizeof(XtremeSettings), XTREME_SETTINGS_MAGIC, XTREME_SETTINGS_VERSION); + if(!loaded) { + Storage* storage = furi_record_open(RECORD_STORAGE); + storage_common_copy(storage, XTREME_SETTINGS_OLD_PATH, XTREME_SETTINGS_PATH); + storage_common_copy(storage, XTREME_SETTINGS_OLD_INT_PATH, XTREME_SETTINGS_PATH); + storage_common_remove(storage, XTREME_SETTINGS_OLD_PATH); + storage_common_remove(storage, XTREME_SETTINGS_OLD_INT_PATH); + furi_record_close(RECORD_STORAGE); + loaded = saved_struct_load( + XTREME_SETTINGS_PATH, + xtreme_settings, + sizeof(XtremeSettings), + XTREME_SETTINGS_MAGIC, + XTREME_SETTINGS_VERSION); + } } if(!loaded) { - if(!skip) { - storage_simply_remove(furi_record_open(RECORD_STORAGE), XTREME_SETTINGS_PATH_OLD); - furi_record_close(RECORD_STORAGE); - } memset(xtreme_settings, 0, sizeof(XtremeSettings)); strlcpy(xtreme_settings->asset_pack, "", MAX_PACK_NAME_LEN); // SFW xtreme_settings->anim_speed = 100; // 100% @@ -55,9 +65,6 @@ void XTREME_SETTINGS_LOAD() { xtreme_settings->bad_bt_remember = false; // OFF xtreme_settings->butthurt_timer = 43200; // 12 H xtreme_settings->rgb_backlight = false; // OFF - if(!skip) { - XTREME_SETTINGS_SAVE(); - } } } } diff --git a/applications/services/xtreme/settings.h b/applications/services/xtreme/settings.h index 6bbff1a40..ea4838e5a 100644 --- a/applications/services/xtreme/settings.h +++ b/applications/services/xtreme/settings.h @@ -1,7 +1,5 @@ #pragma once -#include "settings_filename.h" - #include #include #include @@ -16,11 +14,12 @@ extern "C" { #define MAX_PACK_NAME_LEN 32 #define XTREME_SETTINGS_VERSION (10) -#define XTREME_SETTINGS_PATH_OLD INT_PATH(XTREME_SETTINGS_FILE_NAME) -#define XTREME_SETTINGS_PATH EXT_PATH(XTREME_SETTINGS_FILE_NAME) #define XTREME_SETTINGS_MAGIC (0x69) +#define XTREME_SETTINGS_OLD_INT_PATH INT_PATH(".xtreme.settings") +#define XTREME_SETTINGS_OLD_PATH EXT_PATH(".xtreme.settings") +#define XTREME_SETTINGS_PATH CFG_PATH("xtreme.settings") -#define XTREME_APPS_PATH EXT_PATH(XTREME_APPS_FILE_NAME) +#define XTREME_APPS_PATH CFG_PATH("xtreme_apps.txt") typedef struct { char asset_pack[MAX_PACK_NAME_LEN]; diff --git a/applications/services/xtreme/settings_filename.h b/applications/services/xtreme/settings_filename.h deleted file mode 100644 index be3c467bc..000000000 --- a/applications/services/xtreme/settings_filename.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#define XTREME_SETTINGS_FILE_NAME ".xtreme.settings" -#define XTREME_APPS_FILE_NAME ".xtreme_apps.txt" diff --git a/applications/system/updater/util/update_task_worker_backup.c b/applications/system/updater/util/update_task_worker_backup.c index 5beeb36ec..313a6fe22 100644 --- a/applications/system/updater/util/update_task_worker_backup.c +++ b/applications/system/updater/util/update_task_worker_backup.c @@ -12,7 +12,8 @@ #include #include #include -#include + +#define XFWFIRSTBOOT_FLAG_PATH CFG_PATH("xfwfirstboot.flag") #define TAG "UpdWorkerBackup" @@ -198,7 +199,12 @@ static bool update_task_post_update(UpdateTask* update_task) { update_task_set_progress(update_task, UpdateTaskStageSplashscreenInstall, 0); FuriString* tmp_path; tmp_path = furi_string_alloc_set(update_task->update_path); - if(storage_common_stat(update_task->storage, XTREME_SETTINGS_PATH, NULL) == FSE_NOT_EXIST) { + if(storage_common_stat(update_task->storage, XFWFIRSTBOOT_FLAG_PATH, NULL) == FSE_NOT_EXIST) { + File* file = storage_file_alloc(update_task->storage); + if(storage_file_open(file, XFWFIRSTBOOT_FLAG_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { + storage_file_close(file); + } + storage_file_free(file); path_append(tmp_path, "xfwfirstboot.bin"); if(storage_common_stat(update_task->storage, furi_string_get_cstr(tmp_path), NULL) != FSE_OK) { furi_string_set(tmp_path, update_task->update_path); diff --git a/lib/update_util/lfs_backup.c b/lib/update_util/lfs_backup.c index 7786524ef..d70e554fa 100644 --- a/lib/update_util/lfs_backup.c +++ b/lib/update_util/lfs_backup.c @@ -2,11 +2,7 @@ #include -#include -#include -#include #include -#include #include #define LFS_BACKUP_DEFAULT_LOCATION EXT_PATH(LFS_BACKUP_DEFAULT_FILENAME) @@ -18,12 +14,8 @@ static void backup_name_converter(FuriString* filename) { /* Filenames are already prefixed with '.' */ const char* const names[] = { - BT_SETTINGS_FILE_NAME, - BT_KEYS_STORAGE_FILE_NAME, - DESKTOP_SETTINGS_FILE_NAME, NOTIFICATION_SETTINGS_FILE_NAME, SLIDESHOW_FILE_NAME, - DOLPHIN_STATE_FILE_NAME, }; for(size_t i = 0; i < COUNT_OF(names); i++) {