[FL-2432], [FL-2487] Rework bt keys load and save (#1139)

* bt keys: rework load and save with saved_struct
* bt: rename bt keys storage functions
* furi_hal_nfc: allow context switch during emilation
* bt settings: rework with saved struct
* infrared: replace file worker with dialogs and storage
* Core, Loader: fix thread allocation tracking, much better, so wow.

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
gornekich
2022-04-21 18:36:53 +03:00
committed by GitHub
parent df66f4f6ba
commit 7c692a9f36
16 changed files with 112 additions and 134 deletions

View File

@@ -49,12 +49,14 @@ int32_t InfraredApp::run(void* args) {
InfraredApp::InfraredApp() {
furi_check(InfraredAppRemoteManager::max_button_name_length < get_text_store_size());
notification = static_cast<NotificationApp*>(furi_record_open("notification"));
dialogs = static_cast<DialogsApp*>(furi_record_open("dialogs"));
infrared_worker = infrared_worker_alloc();
}
InfraredApp::~InfraredApp() {
infrared_worker_free(infrared_worker);
furi_record_close("notification");
furi_record_close("dialogs");
for(auto& [key, scene] : scenes) delete scene;
}
@@ -248,6 +250,10 @@ void InfraredApp::notify_blink_green() {
notification_message(notification, &sequence);
}
DialogsApp* InfraredApp::get_dialogs() {
return dialogs;
}
void InfraredApp::notify_green_on() {
notification_message(notification, &sequence_set_only_green_255);
}

View File

@@ -9,6 +9,7 @@
#include <forward_list>
#include <stdint.h>
#include <notification/notification_messages.h>
#include <dialogs/dialogs.h>
#include <infrared_worker.h>
#include "scene/infrared_app_scene.h"
@@ -228,6 +229,9 @@ public:
/** Blink green light */
void notify_blink_green();
/** Get Dialogs instance */
DialogsApp* get_dialogs();
/** Text input callback
*
* @param context - context to pass to callback
@@ -286,6 +290,8 @@ private:
/** Notification instance */
NotificationApp* notification;
/** Dialogs instance */
DialogsApp* dialogs;
/** View manager instance */
InfraredAppViewManager view_manager;
/** Remote manager instance */

View File

@@ -5,7 +5,6 @@
#include <memory>
#include <m-string.h>
#include <furi.h>
#include <file_worker_cpp.h>
void InfraredAppBruteForce::add_record(int index, const char* name) {
records[name].index = index;

View File

@@ -1,4 +1,3 @@
#include <file_worker_cpp.h>
#include <flipper_format/flipper_format.h>
#include "infrared_app_remote_manager.h"
#include "infrared/helpers/infrared_parser.h"
@@ -22,26 +21,34 @@ std::string InfraredAppRemoteManager::make_full_name(
}
std::string InfraredAppRemoteManager::find_vacant_remote_name(const std::string& name) {
bool exist = true;
FileWorkerCpp file_worker;
std::string result_name;
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
if(!file_worker.is_file_exist(
make_full_name(InfraredApp::infrared_directory, name).c_str(), &exist)) {
return std::string();
} else if(!exist) {
return name;
FS_Error error = storage_common_stat(
storage, make_full_name(InfraredApp::infrared_directory, name).c_str(), NULL);
if(error == FSE_NOT_EXIST) {
result_name = name;
} else if(error != FSE_OK) {
result_name = std::string();
} else {
/* if suggested name is occupied, try another one (name2, name3, etc) */
uint32_t i = 1;
std::string new_name;
do {
new_name = make_full_name(InfraredApp::infrared_directory, name + std::to_string(++i));
error = storage_common_stat(storage, new_name.c_str(), NULL);
} while(error == FSE_OK);
if(error == FSE_NOT_EXIST) {
result_name = name + std::to_string(i);
} else {
result_name = std::string();
}
}
/* if suggested name is occupied, try another one (name2, name3, etc) */
uint32_t i = 1;
bool file_worker_result = false;
std::string new_name;
do {
new_name = make_full_name(InfraredApp::infrared_directory, name + std::to_string(++i));
file_worker_result = file_worker.is_file_exist(new_name.c_str(), &exist);
} while(file_worker_result && exist);
return !exist ? name + std::to_string(i) : std::string();
furi_record_close("storage");
return result_name;
}
bool InfraredAppRemoteManager::add_button(const char* button_name, const InfraredAppSignal& signal) {
@@ -84,12 +91,14 @@ const InfraredAppSignal& InfraredAppRemoteManager::get_button_data(size_t index)
}
bool InfraredAppRemoteManager::delete_remote() {
bool result;
FileWorkerCpp file_worker;
result = file_worker.remove(make_full_name(remote->path, remote->name).c_str());
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
FS_Error error =
storage_common_remove(storage, make_full_name(remote->path, remote->name).c_str());
reset_remote();
return result;
furi_record_close("storage");
return (error == FSE_OK || error == FSE_NOT_EXIST);
}
void InfraredAppRemoteManager::reset_remote() {
@@ -129,14 +138,15 @@ bool InfraredAppRemoteManager::rename_remote(const char* str) {
return false;
}
FileWorkerCpp file_worker;
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
std::string old_filename = make_full_name(remote->path, remote->name);
std::string new_filename = make_full_name(remote->path, new_name);
bool result = file_worker.rename(old_filename.c_str(), new_filename.c_str());
FS_Error error = storage_common_rename(storage, old_filename.c_str(), new_filename.c_str());
remote->name = new_name;
return result;
furi_record_close("storage");
return (error == FSE_OK || error == FSE_EXIST);
}
bool InfraredAppRemoteManager::rename_button(uint32_t index, const char* str) {
@@ -155,11 +165,10 @@ size_t InfraredAppRemoteManager::get_number_of_buttons() {
bool InfraredAppRemoteManager::store(void) {
bool result = false;
FileWorkerCpp file_worker;
if(!file_worker.mkdir(InfraredApp::infrared_directory)) return false;
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
if(!storage_simply_mkdir(storage, InfraredApp::infrared_directory)) return false;
FlipperFormat* ff = flipper_format_file_alloc(storage);
FURI_LOG_I(

View File

@@ -1,5 +1,4 @@
#include <gui/modules/dialog_ex.h>
#include <file_worker_cpp.h>
#include <memory>
#include <dolphin/dolphin.h>
@@ -88,13 +87,8 @@ bool InfraredAppSceneLearnSuccess::on_event(InfraredApp* app, InfraredAppEvent*
break;
case DialogExResultRight: {
consumed = true;
FileWorkerCpp file_worker;
if(!button_pressed) {
if(file_worker.check_errors()) {
app->switch_to_next_scene(InfraredApp::Scene::LearnEnterName);
} else {
app->switch_to_previous_scene();
}
app->switch_to_next_scene(InfraredApp::Scene::LearnEnterName);
}
break;
}

View File

@@ -1,12 +1,10 @@
#include "../infrared_app.h"
#include "infrared/infrared_app_event.h"
#include <text_store.h>
#include <file_worker_cpp.h>
void InfraredAppSceneRemoteList::on_enter(InfraredApp* app) {
furi_assert(app);
FileWorkerCpp file_worker;
bool result = false;
bool file_select_result;
auto remote_manager = app->get_remote_manager();
@@ -15,13 +13,15 @@ void InfraredAppSceneRemoteList::on_enter(InfraredApp* app) {
last_selected_remote.size() ? last_selected_remote.c_str() : nullptr;
auto filename_ts =
std::make_unique<TextStore>(InfraredAppRemoteManager::max_remote_name_length);
DialogsApp* dialogs = app->get_dialogs();
InfraredAppViewManager* view_manager = app->get_view_manager();
ButtonMenu* button_menu = view_manager->get_button_menu();
button_menu_reset(button_menu);
view_manager->switch_to(InfraredAppViewManager::ViewId::ButtonMenu);
file_select_result = file_worker.file_select(
file_select_result = dialog_file_select_show(
dialogs,
InfraredApp::infrared_directory,
InfraredApp::infrared_extension,
filename_ts->text,