mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 15:28:36 -07:00
Use flipper format file for xtreme settings
This commit is contained in:
@@ -5,7 +5,7 @@ App(
|
||||
entry_point="xtreme_srv",
|
||||
cdefines=["SRV_XTREME"],
|
||||
requires=["storage"],
|
||||
stack_size=1 * 1024,
|
||||
stack_size=2 * 1024,
|
||||
order=46,
|
||||
sdk_headers=[
|
||||
"settings.h",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
#define TAG "XtremeSettings"
|
||||
|
||||
XtremeSettings* xtreme_settings = NULL;
|
||||
@@ -14,74 +16,124 @@ XtremeSettings* XTREME_SETTINGS() {
|
||||
void XTREME_SETTINGS_LOAD() {
|
||||
if(xtreme_settings == NULL) {
|
||||
xtreme_settings = malloc(sizeof(XtremeSettings));
|
||||
bool loaded = false;
|
||||
|
||||
// Set default values
|
||||
memset(xtreme_settings, 0, sizeof(XtremeSettings));
|
||||
strlcpy(xtreme_settings->asset_pack, "", MAX_PACK_NAME_LEN); // SFW
|
||||
xtreme_settings->anim_speed = 100; // 100%
|
||||
xtreme_settings->cycle_anims = 0; // Meta.txt
|
||||
xtreme_settings->unlock_anims = false; // OFF
|
||||
xtreme_settings->fallback_anim = true; // ON
|
||||
xtreme_settings->wii_menu = true; // ON
|
||||
xtreme_settings->lockscreen_time = true; // ON
|
||||
xtreme_settings->lockscreen_seconds = false; // OFF
|
||||
xtreme_settings->lockscreen_date = true; // ON
|
||||
xtreme_settings->lockscreen_statusbar = true; // ON
|
||||
xtreme_settings->lockscreen_prompt = true; // ON
|
||||
xtreme_settings->battery_icon = BatteryIconBarPercent; // Bar %
|
||||
xtreme_settings->status_icons = true; // ON
|
||||
xtreme_settings->bar_borders = true; // ON
|
||||
xtreme_settings->bar_background = false; // OFF
|
||||
xtreme_settings->sort_dirs_first = true; // ON
|
||||
xtreme_settings->dark_mode = false; // OFF
|
||||
xtreme_settings->bad_bt = false; // USB
|
||||
xtreme_settings->bad_bt_remember = false; // OFF
|
||||
xtreme_settings->butthurt_timer = 43200; // 12 H
|
||||
xtreme_settings->rgb_backlight = false; // OFF
|
||||
|
||||
if(!furi_hal_is_normal_boot()) {
|
||||
FURI_LOG_W(TAG, "Load skipped. Device is in special startup mode.");
|
||||
loaded = false;
|
||||
} else {
|
||||
loaded = saved_struct_load(
|
||||
XTREME_SETTINGS_PATH,
|
||||
xtreme_settings,
|
||||
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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(!loaded) {
|
||||
memset(xtreme_settings, 0, sizeof(XtremeSettings));
|
||||
strlcpy(xtreme_settings->asset_pack, "", MAX_PACK_NAME_LEN); // SFW
|
||||
xtreme_settings->anim_speed = 100; // 100%
|
||||
xtreme_settings->cycle_anims = 0; // Meta.txt
|
||||
xtreme_settings->unlock_anims = false; // OFF
|
||||
xtreme_settings->fallback_anim = true; // ON
|
||||
xtreme_settings->wii_menu = true; // ON
|
||||
xtreme_settings->lockscreen_time = true; // ON
|
||||
xtreme_settings->lockscreen_seconds = false; // ON
|
||||
xtreme_settings->lockscreen_date = true; // ON
|
||||
xtreme_settings->lockscreen_statusbar = true; // ON
|
||||
xtreme_settings->lockscreen_prompt = true; // ON
|
||||
xtreme_settings->battery_icon = BatteryIconBarPercent; // Bar %
|
||||
xtreme_settings->status_icons = true; // ON
|
||||
xtreme_settings->bar_borders = true; // ON
|
||||
xtreme_settings->bar_background = false; // OFF
|
||||
xtreme_settings->sort_dirs_first = true; // ON
|
||||
xtreme_settings->dark_mode = false; // OFF
|
||||
xtreme_settings->bad_bt = false; // USB
|
||||
xtreme_settings->bad_bt_remember = false; // OFF
|
||||
xtreme_settings->butthurt_timer = 43200; // 12 H
|
||||
xtreme_settings->rgb_backlight = false; // OFF
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
if(flipper_format_file_open_existing(file, XTREME_SETTINGS_PATH)) {
|
||||
FuriString* string = furi_string_alloc();
|
||||
if(flipper_format_read_string(file, "asset_pack", string)) {
|
||||
strlcpy(xtreme_settings->asset_pack, furi_string_get_cstr(string), MAX_PACK_NAME_LEN);
|
||||
}
|
||||
furi_string_free(string);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_uint32(file, "anim_speed", &xtreme_settings->anim_speed, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_int32(file, "cycle_anims", &xtreme_settings->cycle_anims, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "unlock_anims", &xtreme_settings->unlock_anims, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "fallback_anim", &xtreme_settings->fallback_anim, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "wii_menu", &xtreme_settings->wii_menu, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "lockscreen_time", &xtreme_settings->lockscreen_time, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "lockscreen_seconds", &xtreme_settings->lockscreen_seconds, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "lockscreen_date", &xtreme_settings->lockscreen_date, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "lockscreen_statusbar", &xtreme_settings->lockscreen_statusbar, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "lockscreen_prompt", &xtreme_settings->lockscreen_prompt, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_uint32(file, "battery_icon", (uint32_t*)&xtreme_settings->battery_icon, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "status_icons", &xtreme_settings->status_icons, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "bar_borders", &xtreme_settings->bar_borders, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "bar_background", &xtreme_settings->bar_background, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "sort_dirs_first", &xtreme_settings->sort_dirs_first, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "dark_mode", &xtreme_settings->dark_mode, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "bad_bt", &xtreme_settings->bad_bt, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "bad_bt_remember", &xtreme_settings->bad_bt_remember, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_int32(file, "butthurt_timer", &xtreme_settings->butthurt_timer, 1);
|
||||
flipper_format_rewind(file);
|
||||
flipper_format_read_bool(file, "rgb_backlight", &xtreme_settings->rgb_backlight, 1);
|
||||
}
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
}
|
||||
|
||||
bool XTREME_SETTINGS_SAVE() {
|
||||
void XTREME_SETTINGS_SAVE() {
|
||||
if(xtreme_settings == NULL) {
|
||||
XTREME_SETTINGS_LOAD();
|
||||
}
|
||||
|
||||
if(!furi_hal_is_normal_boot()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
return saved_struct_save(
|
||||
XTREME_SETTINGS_PATH,
|
||||
xtreme_settings,
|
||||
sizeof(XtremeSettings),
|
||||
XTREME_SETTINGS_MAGIC,
|
||||
XTREME_SETTINGS_VERSION);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
if(flipper_format_file_open_always(file, XTREME_SETTINGS_PATH)) {
|
||||
flipper_format_write_string_cstr(file, "asset_pack", xtreme_settings->asset_pack);
|
||||
flipper_format_write_uint32(file, "anim_speed", &xtreme_settings->anim_speed, 1);
|
||||
flipper_format_write_int32(file, "cycle_anims", &xtreme_settings->cycle_anims, 1);
|
||||
flipper_format_write_bool(file, "unlock_anims", &xtreme_settings->unlock_anims, 1);
|
||||
flipper_format_write_bool(file, "fallback_anim", &xtreme_settings->fallback_anim, 1);
|
||||
flipper_format_write_bool(file, "wii_menu", &xtreme_settings->wii_menu, 1);
|
||||
flipper_format_write_bool(file, "lockscreen_time", &xtreme_settings->lockscreen_time, 1);
|
||||
flipper_format_write_bool(file, "lockscreen_seconds", &xtreme_settings->lockscreen_seconds, 1);
|
||||
flipper_format_write_bool(file, "lockscreen_date", &xtreme_settings->lockscreen_date, 1);
|
||||
flipper_format_write_bool(file, "lockscreen_statusbar", &xtreme_settings->lockscreen_statusbar, 1);
|
||||
flipper_format_write_bool(file, "lockscreen_prompt", &xtreme_settings->lockscreen_prompt, 1);
|
||||
flipper_format_write_uint32(file, "battery_icon", (uint32_t*)&xtreme_settings->battery_icon, 1);
|
||||
flipper_format_write_bool(file, "status_icons", &xtreme_settings->status_icons, 1);
|
||||
flipper_format_write_bool(file, "bar_borders", &xtreme_settings->bar_borders, 1);
|
||||
flipper_format_write_bool(file, "bar_background", &xtreme_settings->bar_background, 1);
|
||||
flipper_format_write_bool(file, "sort_dirs_first", &xtreme_settings->sort_dirs_first, 1);
|
||||
flipper_format_write_bool(file, "dark_mode", &xtreme_settings->dark_mode, 1);
|
||||
flipper_format_write_bool(file, "bad_bt", &xtreme_settings->bad_bt, 1);
|
||||
flipper_format_write_bool(file, "bad_bt_remember", &xtreme_settings->bad_bt_remember, 1);
|
||||
flipper_format_write_int32(file, "butthurt_timer", &xtreme_settings->butthurt_timer, 1);
|
||||
flipper_format_write_bool(file, "rgb_backlight", &xtreme_settings->rgb_backlight, 1);
|
||||
}
|
||||
flipper_format_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <furi_hal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <toolbox/saved_struct.h>
|
||||
#include <storage/storage.h>
|
||||
#include <power/power_service/power.h>
|
||||
|
||||
@@ -13,17 +12,13 @@ extern "C" {
|
||||
|
||||
#define MAX_PACK_NAME_LEN 32
|
||||
|
||||
#define XTREME_SETTINGS_VERSION (11)
|
||||
#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_SETTINGS_PATH CFG_PATH("xtreme_settings.txt")
|
||||
|
||||
#define XTREME_APPS_PATH CFG_PATH("xtreme_apps.txt")
|
||||
|
||||
typedef struct {
|
||||
char asset_pack[MAX_PACK_NAME_LEN];
|
||||
uint16_t anim_speed;
|
||||
uint32_t anim_speed;
|
||||
int32_t cycle_anims;
|
||||
bool unlock_anims;
|
||||
bool fallback_anim;
|
||||
@@ -49,7 +44,7 @@ XtremeSettings* XTREME_SETTINGS();
|
||||
|
||||
void XTREME_SETTINGS_LOAD();
|
||||
|
||||
bool XTREME_SETTINGS_SAVE();
|
||||
void XTREME_SETTINGS_SAVE();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user