Xfw custom app manager actually save and load list

This commit is contained in:
Willy-JL
2023-03-15 04:53:36 +00:00
parent a5fb4da2f9
commit fd9525976e
4 changed files with 31 additions and 0 deletions

View File

@@ -18,6 +18,19 @@ static bool xtreme_app_back_event_callback(void* context) {
if(!scene_manager_has_previous_scene(app->scene_manager, XtremeAppSceneStart)) { if(!scene_manager_has_previous_scene(app->scene_manager, XtremeAppSceneStart)) {
Storage* storage = furi_record_open(RECORD_STORAGE); Storage* storage = furi_record_open(RECORD_STORAGE);
if(app->save_mainmenu_apps) {
Stream* stream = file_stream_alloc(storage);
if(file_stream_open(stream, XTREME_APPS_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS)){
CharList_it_t it;
CharList_it(it, app->mainmenu_apps_paths);
for(uint i = 0; i < CharList_size(app->mainmenu_apps_paths); i++) {
stream_write_format(stream, "%s\n", *CharList_get(app->mainmenu_apps_paths, i));
}
}
file_stream_close(stream);
stream_free(stream);
}
if(app->save_subghz) { if(app->save_subghz) {
furi_hal_subghz_set_extend_settings(app->subghz_extend, app->subghz_bypass); furi_hal_subghz_set_extend_settings(app->subghz_extend, app->subghz_bypass);
} }
@@ -192,6 +205,20 @@ XtremeApp* xtreme_app_alloc() {
CharList_init(app->mainmenu_apps_names); CharList_init(app->mainmenu_apps_names);
CharList_init(app->mainmenu_apps_paths); CharList_init(app->mainmenu_apps_paths);
Stream* stream = file_stream_alloc(storage);
FuriString* line = furi_string_alloc();
if(file_stream_open(stream, XTREME_APPS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
while(stream_read_line(stream, line)) {
furi_string_replace_all(line, "\r", "");
furi_string_replace_all(line, "\n", "");
CharList_push_back(app->mainmenu_apps_paths, strdup(furi_string_get_cstr(line)));
fap_loader_load_name_and_icon(line, storage, NULL, line);
CharList_push_back(app->mainmenu_apps_names, strdup(furi_string_get_cstr(line)));
}
}
furi_string_free(line);
file_stream_close(stream);
stream_free(stream);
FlipperFormat* file = flipper_format_file_alloc(storage); FlipperFormat* file = flipper_format_file_alloc(storage);
FrequencyList_init(app->subghz_static_frequencies); FrequencyList_init(app->subghz_static_frequencies);

View File

@@ -11,6 +11,7 @@
#include <gui/modules/text_input.h> #include <gui/modules/text_input.h>
#include <gui/modules/popup.h> #include <gui/modules/popup.h>
#include <lib/toolbox/value_index.h> #include <lib/toolbox/value_index.h>
#include <toolbox/stream/file_stream.h>
#include <namechangersrv/namechangersrv.h> #include <namechangersrv/namechangersrv.h>
#include "scenes/xtreme_app_scene.h" #include "scenes/xtreme_app_scene.h"
#include "dolphin/helpers/dolphin_state.h" #include "dolphin/helpers/dolphin_state.h"

View File

@@ -20,6 +20,8 @@ extern "C" {
#define XTREME_SETTINGS_PATH EXT_PATH(XTREME_SETTINGS_FILE_NAME) #define XTREME_SETTINGS_PATH EXT_PATH(XTREME_SETTINGS_FILE_NAME)
#define XTREME_SETTINGS_MAGIC (0x69) #define XTREME_SETTINGS_MAGIC (0x69)
#define XTREME_APPS_PATH EXT_PATH(XTREME_APPS_FILE_NAME)
// Some settings function backwards (logically) in // Some settings function backwards (logically) in
// order to fit the default value we want // order to fit the default value we want
// (values will default to 0 / false) // (values will default to 0 / false)

View File

@@ -1,3 +1,4 @@
#pragma once #pragma once
#define XTREME_SETTINGS_FILE_NAME ".xtreme.settings" #define XTREME_SETTINGS_FILE_NAME ".xtreme.settings"
#define XTREME_APPS_FILE_NAME ".xtreme_apps.txt"