Migrate files for int on ext, no more .config

This commit is contained in:
Willy-JL
2024-08-11 01:49:11 +02:00
parent de940394c9
commit cf5846979f
8 changed files with 83 additions and 63 deletions

View File

@@ -33,21 +33,24 @@ static void flipper_print_version(const char* target, const Version* version) {
}
#ifndef FURI_RAM_EXEC
#include <applications/main/archive/helpers/archive_favorites.h>
#include <applications/main/infrared/infrared_app.h>
#include <applications/main/u2f/u2f_data.h>
#include <furi_hal.h>
#include <assets_icons.h>
#include <bt/bt_service/bt_i.h>
#include <bt/bt_settings.h>
#include <desktop/desktop_settings.h>
#include <dolphin/helpers/dolphin_state.h>
#include <expansion/expansion_settings_filename.h>
#include <loader/loader_menu.h>
#include <momentum/asset_packs.h>
#include <momentum/namespoof.h>
#include <momentum/settings_i.h>
#include <notification/notification_app.h>
#include <power/power_settings.h>
#include <applications/main/archive/helpers/archive_favorites.h>
#include <bt/bt_service/bt_keys_filename.h>
#include <bt/bt_settings_filename.h>
#include <desktop/desktop_keybinds_filename.h>
#include <desktop/desktop_settings_filename.h>
#include <dolphin/helpers/dolphin_state_filename.h>
#include <expansion/expansion_settings_filename.h>
#include <loader/loader_menu.h>
#include <notification/notification_settings_filename.h>
#include <power/power_settings_filename.h>
#include <applications/main/infrared/infrared_app.h>
#include <applications/main/u2f/u2f_data.h>
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");