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