From cf5846979f9de08af201d8fb7781748f67dedcb2 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 11 Aug 2024 01:49:11 +0200 Subject: [PATCH] Migrate files for int on ext, no more .config --- applications/main/infrared/infrared_app.h | 2 +- applications/main/u2f/u2f_data.h | 2 +- .../services/desktop/desktop_keybinds.c | 50 +++++------ .../desktop/desktop_keybinds_filename.h | 3 + applications/services/power/power_settings.c | 1 + applications/services/power/power_settings.h | 1 - .../services/power/power_settings_filename.h | 3 + furi/flipper.c | 84 +++++++++++-------- 8 files changed, 83 insertions(+), 63 deletions(-) create mode 100644 applications/services/power/power_settings_filename.h diff --git a/applications/main/infrared/infrared_app.h b/applications/main/infrared/infrared_app.h index 545fada9f..fedfd8af9 100644 --- a/applications/main/infrared/infrared_app.h +++ b/applications/main/infrared/infrared_app.h @@ -17,7 +17,7 @@ typedef struct InfraredApp InfraredApp; #include #include -#define INFRARED_SETTINGS_PATH EXT_PATH("infrared/.infrared.settings") +#define INFRARED_SETTINGS_PATH INT_PATH(".infrared.settings") #define INFRARED_SETTINGS_VERSION (1) #define INFRARED_SETTINGS_MAGIC (0x1F) diff --git a/applications/main/u2f/u2f_data.h b/applications/main/u2f/u2f_data.h index 54428acf9..41e0d9447 100644 --- a/applications/main/u2f/u2f_data.h +++ b/applications/main/u2f/u2f_data.h @@ -9,8 +9,8 @@ extern "C" { #define U2F_DATA_FOLDER EXT_PATH("u2f/") #define U2F_CERT_FILE U2F_DATA_FOLDER "assets/cert.der" #define U2F_CERT_KEY_FILE U2F_DATA_FOLDER "assets/cert_key.u2f" +#define U2F_KEY_FILE U2F_DATA_FOLDER "key.u2f" #define U2F_CNT_FILE U2F_DATA_FOLDER "cnt.u2f" -#define U2F_KEY_FILE INT_PATH(".key.u2f") bool u2f_data_check(bool cert_only); diff --git a/applications/services/desktop/desktop_keybinds.c b/applications/services/desktop/desktop_keybinds.c index c7416523d..f4d2af883 100644 --- a/applications/services/desktop/desktop_keybinds.c +++ b/applications/services/desktop/desktop_keybinds.c @@ -12,7 +12,7 @@ #define OLD_DESKTOP_KEYBINDS_VER (1) #define OLD_DESKTOP_KEYBINDS_MAGIC (0x14) -#define OLD_DESKTOP_KEYBINDS_PATH INT_PATH(".desktop.keybinds") // Moved from .config by migrate +#define OLD_DESKTOP_KEYBINDS_PATH DESKTOP_KEYBINDS_PATH_MIGRATE #define OLD_MAX_KEYBIND_LENGTH (64) typedef struct { @@ -22,33 +22,35 @@ typedef struct { typedef OldKeybind OldKeybinds[DesktopKeybindTypeMAX][DesktopKeybindKeyMAX]; void desktop_keybinds_migrate(Desktop* desktop) { - OldKeybinds old; - const bool success = saved_struct_load( - OLD_DESKTOP_KEYBINDS_PATH, - &old, - sizeof(old), - OLD_DESKTOP_KEYBINDS_MAGIC, - OLD_DESKTOP_KEYBINDS_VER); + if(!storage_common_exists(desktop->storage, DESKTOP_KEYBINDS_PATH)) { + OldKeybinds old; + const bool success = saved_struct_load( + OLD_DESKTOP_KEYBINDS_PATH, + &old, + sizeof(old), + OLD_DESKTOP_KEYBINDS_MAGIC, + OLD_DESKTOP_KEYBINDS_VER); - if(success) { - DesktopKeybinds new; - for(DesktopKeybindType type = 0; type < DesktopKeybindTypeMAX; type++) { - for(DesktopKeybindKey key = 0; key < DesktopKeybindKeyMAX; key++) { - FuriString* keybind = furi_string_alloc_set(old[type][key].data); - if(furi_string_equal(keybind, EXT_PATH("apps/Misc/nightstand.fap"))) { - furi_string_set(keybind, "Clock"); - } else if(furi_string_equal(keybind, "RFID")) { - furi_string_set(keybind, "125 kHz RFID"); - } else if(furi_string_equal(keybind, "SubGHz")) { - furi_string_set(keybind, "Sub-GHz"); - } else if(furi_string_equal(keybind, "Xtreme")) { - furi_string_set(keybind, "Momentum"); + if(success) { + DesktopKeybinds new; + for(DesktopKeybindType type = 0; type < DesktopKeybindTypeMAX; type++) { + for(DesktopKeybindKey key = 0; key < DesktopKeybindKeyMAX; key++) { + FuriString* keybind = furi_string_alloc_set(old[type][key].data); + if(furi_string_equal(keybind, EXT_PATH("apps/Misc/nightstand.fap"))) { + furi_string_set(keybind, "Clock"); + } else if(furi_string_equal(keybind, "RFID")) { + furi_string_set(keybind, "125 kHz RFID"); + } else if(furi_string_equal(keybind, "SubGHz")) { + furi_string_set(keybind, "Sub-GHz"); + } else if(furi_string_equal(keybind, "Xtreme")) { + furi_string_set(keybind, "Momentum"); + } + new[type][key] = keybind; } - new[type][key] = keybind; } + desktop_keybinds_save(desktop, &new); + desktop_keybinds_free(&new); } - desktop_keybinds_save(desktop, &new); - desktop_keybinds_free(&new); } storage_common_remove(desktop->storage, OLD_DESKTOP_KEYBINDS_PATH); diff --git a/applications/services/desktop/desktop_keybinds_filename.h b/applications/services/desktop/desktop_keybinds_filename.h index b68b65870..71c2056eb 100644 --- a/applications/services/desktop/desktop_keybinds_filename.h +++ b/applications/services/desktop/desktop_keybinds_filename.h @@ -1,3 +1,6 @@ #pragma once #define DESKTOP_KEYBINDS_PATH INT_PATH(".desktop_keybinds.txt") + +// Moved from .config by migrate, then converted to Flipper Format by Desktop +#define DESKTOP_KEYBINDS_PATH_MIGRATE INT_PATH(".desktop.keybinds") diff --git a/applications/services/power/power_settings.c b/applications/services/power/power_settings.c index b98c382c0..b9d5b6dc7 100644 --- a/applications/services/power/power_settings.c +++ b/applications/services/power/power_settings.c @@ -1,4 +1,5 @@ #include "power_settings.h" +#include "power_settings_filename.h" bool SAVE_POWER_SETTINGS(uint32_t* x) { return saved_struct_save( diff --git a/applications/services/power/power_settings.h b/applications/services/power/power_settings.h index e797a5b44..2377df970 100644 --- a/applications/services/power/power_settings.h +++ b/applications/services/power/power_settings.h @@ -3,7 +3,6 @@ #define POWER_SETTINGS_VER (1) -#define POWER_SETTINGS_PATH INT_PATH(".power.settings") #define POWER_SETTINGS_MAGIC (0x21) #ifdef __cplusplus diff --git a/applications/services/power/power_settings_filename.h b/applications/services/power/power_settings_filename.h new file mode 100644 index 000000000..6aa7c65c1 --- /dev/null +++ b/applications/services/power/power_settings_filename.h @@ -0,0 +1,3 @@ +#pragma once + +#define POWER_SETTINGS_PATH INT_PATH(".power.settings") diff --git a/furi/flipper.c b/furi/flipper.c index 2a0194679..4cf8ab91b 100644 --- a/furi/flipper.c +++ b/furi/flipper.c @@ -33,21 +33,24 @@ static void flipper_print_version(const char* target, const Version* version) { } #ifndef FURI_RAM_EXEC -#include -#include -#include +#include #include -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include void flipper_migrate_files() { Storage* storage = furi_record_open(RECORD_STORAGE); @@ -58,43 +61,52 @@ void flipper_migrate_files() { // Migrate files FURI_LOG_I(TAG, "Migrate: Rename old paths"); + // If multiple have same destination, first match that exists is kept and others deleted const struct { const char* src; const char* dst; - bool delete; } renames[] = { - // Renames on ext - {EXT_PATH(".config/favorites.txt"), ARCHIVE_FAV_PATH, true}, // Adapt to OFW/UL - {EXT_PATH(".config/.desktop.keybinds"), DESKTOP_KEYBINDS_PATH, true}, // Old naming - {EXT_PATH(".config/xtreme_menu.txt"), MAINMENU_APPS_PATH, false}, // Keep both - {EXT_PATH(".config/xtreme_settings.txt"), MOMENTUM_SETTINGS_PATH, false}, // Keep both - // Int -> Ext - {INT_PATH(".bt.settings"), BT_SETTINGS_PATH, true}, - {INT_PATH(".dolphin.state"), DOLPHIN_STATE_PATH, true}, - {INT_PATH(".power.settings"), POWER_SETTINGS_PATH, true}, - {INT_PATH(".bt.keys"), BT_KEYS_STORAGE_PATH, true}, - {INT_PATH(".expansion.settings"), EXPANSION_SETTINGS_PATH, true}, - {INT_PATH(".notification.settings"), NOTIFICATION_SETTINGS_PATH, true}, - {INT_PATH(".infrared.settings"), INFRARED_SETTINGS_PATH, true}, - // Ext -> Int - {EXT_PATH(".config/desktop.settings"), DESKTOP_SETTINGS_PATH, true}, + // Renames on Ext + {EXT_PATH(".config/favorites.txt"), ARCHIVE_FAV_PATH}, // Adapt to OFW/UL + // Ext -> "Int" + {EXT_PATH(".config/bt.keys"), BT_KEYS_STORAGE_PATH}, + {EXT_PATH(".config/bt.settings"), BT_SETTINGS_PATH}, + {EXT_PATH(".config/desktop.keybinds"), DESKTOP_KEYBINDS_PATH_MIGRATE}, + {EXT_PATH(".config/.desktop.keybinds"), DESKTOP_KEYBINDS_PATH_MIGRATE}, // Old naming + {EXT_PATH(".config/desktop.settings"), DESKTOP_SETTINGS_PATH}, + {EXT_PATH(".config/dolphin.state"), DOLPHIN_STATE_PATH}, + {EXT_PATH(".config/expansion.settings"), EXPANSION_SETTINGS_PATH}, + {EXT_PATH(".config/mainmenu_apps.txt"), MAINMENU_APPS_PATH}, + {EXT_PATH(".config/xtreme_menu.txt"), MAINMENU_APPS_PATH}, + {EXT_PATH(".config/momentum_settings.txt"), MOMENTUM_SETTINGS_PATH}, + {EXT_PATH(".config/xtreme_settings.txt"), MOMENTUM_SETTINGS_PATH}, + {EXT_PATH(".config/notification.settings"), NOTIFICATION_SETTINGS_PATH}, + {EXT_PATH(".config/power.settings"), POWER_SETTINGS_PATH}, + {EXT_PATH("infrared/.infrared.settings"), INFRARED_SETTINGS_PATH}, // Adapt to OFW }; for(size_t i = 0; i < COUNT_OF(renames); ++i) { // Use copy+remove to not overwrite dst but still delete src storage_common_copy(storage, renames[i].src, renames[i].dst); - if(renames[i].delete) { - storage_common_remove(storage, renames[i].src); - } + storage_common_remove(storage, renames[i].src); } - // Special care for U2F + // Int -> Ext for U2F FURI_LOG_I(TAG, "Migrate: U2F"); - FileInfo file_info; - if(storage_common_stat(storage, INT_PATH(".cnt.u2f"), &file_info) == FSE_OK && - file_info.size > 200) { // Is on Int and has content - storage_common_rename(storage, INT_PATH(".cnt.u2f"), U2F_CNT_FILE); // Int -> Ext + if(storage_common_exists(storage, INT_PATH(".cnt.u2f"))) { + const char* cnt_dst = storage_common_exists(storage, U2F_CNT_FILE) ? U2F_CNT_FILE ".old" : + U2F_CNT_FILE; + storage_common_rename(storage, INT_PATH(".cnt.u2f"), cnt_dst); + } + if(storage_common_exists(storage, INT_PATH(".key.u2f"))) { + const char* key_dst = storage_common_exists(storage, U2F_KEY_FILE) ? U2F_KEY_FILE ".old" : + U2F_KEY_FILE; + storage_common_rename(storage, INT_PATH(".key.u2f"), key_dst); + } + + // Remove obsolete .config folder after migration + if(!storage_simply_remove(storage, EXT_PATH(".config"))) { + FURI_LOG_W(TAG, "Can't remove /ext/.config/, probably not empty"); } - storage_common_copy(storage, U2F_DATA_FOLDER "key.u2f", U2F_KEY_FILE); // Ext -> Int // Asset packs migrate, merges together FURI_LOG_I(TAG, "Migrate: Asset Packs");