mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Move config file migration to flipper init
This commit is contained in:
@@ -140,13 +140,6 @@ 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)) {
|
||||
|
||||
@@ -28,11 +28,6 @@ U2fApp* u2f_app_alloc() {
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
app->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_rename(storage, U2F_CNT_OLD_FILE, U2F_CNT_FILE);
|
||||
storage_common_copy(storage, U2F_KEY_OLD_FILE, U2F_KEY_FILE);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
app->scene_manager = scene_manager_alloc(&u2f_scene_handlers, app);
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
|
||||
@@ -126,10 +126,6 @@ Bt* bt_alloc() {
|
||||
bt_settings_save(&bt->bt_settings);
|
||||
}
|
||||
// Keys storage
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_copy(storage, BT_KEYS_STORAGE_OLD_PATH, BT_KEYS_STORAGE_PATH);
|
||||
storage_common_remove(storage, BT_KEYS_STORAGE_OLD_PATH);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
bt->keys_storage = bt_keys_storage_alloc(BT_KEYS_STORAGE_PATH);
|
||||
// Alloc queue
|
||||
bt->message_queue = furi_message_queue_alloc(8, sizeof(BtMessage));
|
||||
|
||||
@@ -4,31 +4,14 @@
|
||||
#include <lib/toolbox/saved_struct.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#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)
|
||||
|
||||
bool bt_settings_load(BtSettings* bt_settings) {
|
||||
furi_assert(bt_settings);
|
||||
|
||||
bool ret = saved_struct_load(
|
||||
return saved_struct_load(
|
||||
BT_SETTINGS_PATH, bt_settings, sizeof(BtSettings), BT_SETTINGS_MAGIC, BT_SETTINGS_VERSION);
|
||||
|
||||
if(!ret) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_copy(storage, BT_SETTINGS_OLD_PATH, BT_SETTINGS_PATH);
|
||||
storage_common_remove(storage, BT_SETTINGS_OLD_PATH);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
ret = saved_struct_load(
|
||||
BT_SETTINGS_PATH,
|
||||
bt_settings,
|
||||
sizeof(BtSettings),
|
||||
BT_SETTINGS_MAGIC,
|
||||
BT_SETTINGS_VERSION);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool bt_settings_save(BtSettings* bt_settings) {
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BT_SETTINGS_OLD_PATH INT_PATH(".bt.settings")
|
||||
#define BT_SETTINGS_PATH CFG_PATH("bt.settings")
|
||||
|
||||
typedef struct {
|
||||
bool enabled;
|
||||
} BtSettings;
|
||||
|
||||
@@ -10,25 +10,10 @@ bool DESKTOP_SETTINGS_SAVE(DesktopSettings* x) {
|
||||
}
|
||||
|
||||
bool DESKTOP_SETTINGS_LOAD(DesktopSettings* x) {
|
||||
bool ret = saved_struct_load(
|
||||
return saved_struct_load(
|
||||
DESKTOP_SETTINGS_PATH,
|
||||
x,
|
||||
sizeof(DesktopSettings),
|
||||
DESKTOP_SETTINGS_MAGIC,
|
||||
DESKTOP_SETTINGS_VER);
|
||||
|
||||
if(!ret) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_copy(storage, DESKTOP_SETTINGS_OLD_PATH, DESKTOP_SETTINGS_PATH);
|
||||
storage_common_remove(storage, DESKTOP_SETTINGS_OLD_PATH);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
ret = saved_struct_load(
|
||||
DESKTOP_SETTINGS_PATH,
|
||||
x,
|
||||
sizeof(DesktopSettings),
|
||||
DESKTOP_SETTINGS_MAGIC,
|
||||
DESKTOP_SETTINGS_VER);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
#define TAG "DolphinState"
|
||||
|
||||
#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
|
||||
|
||||
@@ -61,19 +59,6 @@ bool dolphin_state_load(DolphinState* dolphin_state) {
|
||||
DOLPHIN_STATE_HEADER_MAGIC,
|
||||
DOLPHIN_STATE_HEADER_VERSION);
|
||||
|
||||
if(!success) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_copy(storage, DOLPHIN_STATE_OLD_PATH, DOLPHIN_STATE_PATH);
|
||||
storage_common_remove(storage, DOLPHIN_STATE_OLD_PATH);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
success = saved_struct_load(
|
||||
DOLPHIN_STATE_PATH,
|
||||
&dolphin_state->data,
|
||||
sizeof(DolphinStoreData),
|
||||
DOLPHIN_STATE_HEADER_MAGIC,
|
||||
DOLPHIN_STATE_HEADER_VERSION);
|
||||
}
|
||||
|
||||
if(success) {
|
||||
if((dolphin_state->data.butthurt > BUTTHURT_MAX) ||
|
||||
(dolphin_state->data.butthurt < BUTTHURT_MIN)) {
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define DOLPHIN_STATE_OLD_PATH INT_PATH(".dolphin.state")
|
||||
#define DOLPHIN_STATE_PATH CFG_PATH("dolphin.state")
|
||||
|
||||
#define DOLPHIN_LEVEL_COUNT 29
|
||||
|
||||
typedef struct DolphinState DolphinState;
|
||||
|
||||
@@ -421,27 +421,12 @@ static bool notification_save_settings(NotificationApp* app) {
|
||||
}
|
||||
|
||||
static bool notification_load_settings(NotificationApp* app) {
|
||||
bool ret = saved_struct_load(
|
||||
return saved_struct_load(
|
||||
NOTIFICATION_SETTINGS_PATH,
|
||||
&app->settings,
|
||||
sizeof(NotificationSettings),
|
||||
NOTIFICATION_SETTINGS_MAGIC,
|
||||
NOTIFICATION_SETTINGS_VERSION);
|
||||
|
||||
if(!ret) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_copy(storage, NOTIFICATION_SETTINGS_OLD_PATH, NOTIFICATION_SETTINGS_PATH);
|
||||
storage_common_remove(storage, NOTIFICATION_SETTINGS_OLD_PATH);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
ret = saved_struct_load(
|
||||
NOTIFICATION_SETTINGS_PATH,
|
||||
&app->settings,
|
||||
sizeof(NotificationSettings),
|
||||
NOTIFICATION_SETTINGS_MAGIC,
|
||||
NOTIFICATION_SETTINGS_VERSION);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void input_event_callback(const void* value, void* context) {
|
||||
|
||||
@@ -6,17 +6,6 @@ bool SAVE_POWER_SETTINGS(uint32_t* x) {
|
||||
}
|
||||
|
||||
bool LOAD_POWER_SETTINGS(uint32_t* x) {
|
||||
bool ret = saved_struct_load(
|
||||
return saved_struct_load(
|
||||
POWER_SETTINGS_PATH, x, sizeof(uint32_t), POWER_SETTINGS_MAGIC, POWER_SETTINGS_VER);
|
||||
|
||||
if(!ret) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
storage_common_copy(storage, POWER_SETTINGS_OLD_PATH, POWER_SETTINGS_PATH);
|
||||
storage_common_remove(storage, POWER_SETTINGS_OLD_PATH);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
ret = saved_struct_load(
|
||||
POWER_SETTINGS_PATH, x, sizeof(uint32_t), POWER_SETTINGS_MAGIC, POWER_SETTINGS_VER);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,15 @@
|
||||
#include <furi_hal_version.h>
|
||||
#include <furi_hal_memory.h>
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <storage/storage.h>
|
||||
#include <bt/bt_settings.h>
|
||||
#include <bt/bt_service/bt_i.h>
|
||||
#include <power/power_settings.h>
|
||||
#include <desktop/desktop_settings.h>
|
||||
#include <notification/notification_app.h>
|
||||
#include <dolphin/helpers/dolphin_state.h>
|
||||
#include <applications/main/u2f/u2f_data.h>
|
||||
#include <applications/main/archive/helpers/archive_favorites.h>
|
||||
#include <xtreme/private.h>
|
||||
|
||||
#define TAG "Flipper"
|
||||
@@ -28,6 +37,39 @@ static void flipper_print_version(const char* target, const Version* version) {
|
||||
}
|
||||
}
|
||||
|
||||
void flipper_migrate_files() {
|
||||
if(!furi_hal_is_normal_boot()) return;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
// Revert cringe
|
||||
storage_common_remove(storage, INT_PATH(".passport.settings"));
|
||||
|
||||
// Migrate files
|
||||
storage_common_copy(storage, ARCHIVE_FAV_OLD_PATH, ARCHIVE_FAV_PATH);
|
||||
storage_common_remove(storage, ARCHIVE_FAV_OLD_PATH);
|
||||
storage_common_copy(storage, BT_SETTINGS_OLD_PATH, BT_SETTINGS_PATH);
|
||||
storage_common_remove(storage, BT_SETTINGS_OLD_PATH);
|
||||
storage_common_copy(storage, DOLPHIN_STATE_OLD_PATH, DOLPHIN_STATE_PATH);
|
||||
storage_common_remove(storage, DOLPHIN_STATE_OLD_PATH);
|
||||
storage_common_copy(storage, POWER_SETTINGS_OLD_PATH, POWER_SETTINGS_PATH);
|
||||
storage_common_remove(storage, POWER_SETTINGS_OLD_PATH);
|
||||
storage_common_copy(storage, BT_KEYS_STORAGE_OLD_PATH, BT_KEYS_STORAGE_PATH);
|
||||
storage_common_remove(storage, BT_KEYS_STORAGE_OLD_PATH);
|
||||
storage_common_copy(storage, DESKTOP_SETTINGS_OLD_PATH, DESKTOP_SETTINGS_PATH);
|
||||
storage_common_remove(storage, DESKTOP_SETTINGS_OLD_PATH);
|
||||
storage_common_copy(storage, NOTIFICATION_SETTINGS_OLD_PATH, NOTIFICATION_SETTINGS_PATH);
|
||||
storage_common_remove(storage, NOTIFICATION_SETTINGS_OLD_PATH);
|
||||
|
||||
// Special care for U2F
|
||||
if(storage_common_exists(storage, U2F_CNT_OLD_FILE)) { // Is on Int
|
||||
storage_common_remove(storage, U2F_CNT_FILE); // Remove outdated on Ext
|
||||
storage_common_rename(storage, U2F_CNT_OLD_FILE, U2F_CNT_FILE); // Int -> Ext
|
||||
}
|
||||
storage_common_copy(storage, U2F_KEY_OLD_FILE, U2F_KEY_FILE); // Ext -> Int
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
void flipper_start_service(const FlipperApplication* service) {
|
||||
FURI_LOG_D(TAG, "Starting service %s", service->name);
|
||||
|
||||
@@ -47,6 +89,8 @@ void flipper_init() {
|
||||
// Start storage service first, thanks OFW :/
|
||||
flipper_start_service(&FLIPPER_SERVICES[0]);
|
||||
|
||||
flipper_migrate_files();
|
||||
|
||||
NAMESPOOF_INIT();
|
||||
XTREME_SETTINGS_LOAD();
|
||||
XTREME_ASSETS_LOAD();
|
||||
|
||||
Reference in New Issue
Block a user