diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 76dc2e052..61be402bd 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "notification.h" #include "notification_messages.h" @@ -410,78 +411,37 @@ void notification_process_internal_message(NotificationApp* app, NotificationApp } } -static bool notification_load_settings(NotificationApp* app) { - NotificationSettings settings; - File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); - const size_t settings_size = sizeof(NotificationSettings); - - FURI_LOG_I(TAG, "loading settings from \"%s\"", NOTIFICATION_SETTINGS_PATH); - bool fs_result = - storage_file_open(file, NOTIFICATION_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING); - - if(fs_result) { - uint16_t bytes_count = storage_file_read(file, &settings, settings_size); - - if(bytes_count != settings_size) { - fs_result = false; - } - } - - if(fs_result) { - FURI_LOG_I(TAG, "load success"); - - if(settings.version != NOTIFICATION_SETTINGS_VERSION) { - FURI_LOG_E( - TAG, "version(%d != %d) mismatch", settings.version, NOTIFICATION_SETTINGS_VERSION); - } else { - furi_kernel_lock(); - memcpy(&app->settings, &settings, settings_size); - furi_kernel_unlock(); - } - } else { - FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file)); - } - - storage_file_close(file); - storage_file_free(file); - furi_record_close(RECORD_STORAGE); - - return fs_result; +static bool notification_save_settings(NotificationApp* app) { + return saved_struct_save( + NOTIFICATION_SETTINGS_PATH, + &app->settings, + sizeof(NotificationSettings), + NOTIFICATION_SETTINGS_MAGIC, + NOTIFICATION_SETTINGS_VERSION); } -static bool notification_save_settings(NotificationApp* app) { - NotificationSettings settings; - File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); - const size_t settings_size = sizeof(NotificationSettings); +static bool notification_load_settings(NotificationApp* app) { + bool ret = saved_struct_load( + NOTIFICATION_SETTINGS_PATH, + &app->settings, + sizeof(NotificationSettings), + NOTIFICATION_SETTINGS_MAGIC, + NOTIFICATION_SETTINGS_VERSION); - FURI_LOG_I(TAG, "saving settings to \"%s\"", NOTIFICATION_SETTINGS_PATH); - - furi_kernel_lock(); - memcpy(&settings, &app->settings, settings_size); - furi_kernel_unlock(); - - bool fs_result = - storage_file_open(file, NOTIFICATION_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS); - - if(fs_result) { - uint16_t bytes_count = storage_file_write(file, &settings, settings_size); - - if(bytes_count != settings_size) { - fs_result = false; - } + 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); } - if(fs_result) { - FURI_LOG_I(TAG, "save success"); - } else { - FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file)); - } - - storage_file_close(file); - storage_file_free(file); - furi_record_close(RECORD_STORAGE); - - return fs_result; + return ret; } static void input_event_callback(const void* value, void* context) { diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index 88194bfbd..92a668ee9 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -2,7 +2,6 @@ #include #include "notification.h" #include "notification_messages.h" -#include "notification_settings_filename.h" #define NOTIFICATION_LED_COUNT 3 #define NOTIFICATION_EVENT_COMPLETE 0x00000001U @@ -33,7 +32,9 @@ typedef struct { } NotificationLedLayer; #define NOTIFICATION_SETTINGS_VERSION 0x01 -#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME) +#define NOTIFICATION_SETTINGS_MAGIC 0x16 +#define NOTIFICATION_SETTINGS_OLD_PATH INT_PATH(".notification.settings") +#define NOTIFICATION_SETTINGS_PATH CFG_PATH("notification.settings") typedef struct { uint8_t version; diff --git a/applications/services/notification/notification_settings_filename.h b/applications/services/notification/notification_settings_filename.h deleted file mode 100644 index d9ed596ec..000000000 --- a/applications/services/notification/notification_settings_filename.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define NOTIFICATION_SETTINGS_FILE_NAME ".notification.settings" diff --git a/lib/update_util/lfs_backup.c b/lib/update_util/lfs_backup.c index b299a9d32..a441ccabd 100644 --- a/lib/update_util/lfs_backup.c +++ b/lib/update_util/lfs_backup.c @@ -2,28 +2,8 @@ #include -#include - #define LFS_BACKUP_DEFAULT_LOCATION EXT_PATH(LFS_BACKUP_DEFAULT_FILENAME) -static void backup_name_converter(FuriString* filename) { - if(furi_string_empty(filename) || (furi_string_get_char(filename, 0) == '.')) { - return; - } - - /* Filenames are already prefixed with '.' */ - const char* const names[] = { - NOTIFICATION_SETTINGS_FILE_NAME, - }; - - for(size_t i = 0; i < COUNT_OF(names); i++) { - if(furi_string_equal(filename, &names[i][1])) { - furi_string_set(filename, names[i]); - return; - } - } -} - bool lfs_backup_create(Storage* storage, const char* destination) { const char* final_destination = destination && strlen(destination) ? destination : LFS_BACKUP_DEFAULT_LOCATION; @@ -37,5 +17,5 @@ bool lfs_backup_exists(Storage* storage, const char* source) { bool lfs_backup_unpack(Storage* storage, const char* source) { const char* final_source = source && strlen(source) ? source : LFS_BACKUP_DEFAULT_LOCATION; - return storage_int_restore(storage, final_source, backup_name_converter) == FSE_OK; + return storage_int_restore(storage, final_source, NULL) == FSE_OK; }