[FL-1061] iButton save and load from sd card (#394)

* SD App: fix queue adresses
* sd-filesystem: fix making path on file select event
* ibutton: add key reading from sd card
* ibutton: save ibutton key to sd card
* ibutton: add deleting keys from sd card
* ibutton: remove KeyStore from application
* ibutton: make directory if necessary on key save

Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich
2021-03-31 20:47:32 +03:00
committed by GitHub
parent 6375f21cf5
commit 5309bfae41
15 changed files with 132 additions and 256 deletions

View File

@@ -3,6 +3,7 @@
#include "../ibutton-view-manager.h"
#include "../ibutton-event.h"
#include <callback-connector.h>
#include <filesystem-api.h>
typedef enum {
SubmenuIndexRead,
@@ -30,9 +31,40 @@ bool iButtonSceneStart::on_event(iButtonApp* app, iButtonEvent* event) {
case SubmenuIndexRead:
app->switch_to_next_scene(iButtonApp::Scene::SceneRead);
break;
case SubmenuIndexSaved:
app->switch_to_next_scene(iButtonApp::Scene::SceneSavedList);
break;
case SubmenuIndexSaved: {
bool res = app->get_sd_ex_api()->file_select(
app->get_sd_ex_api()->context,
"ibutton",
"*",
app->get_file_name(),
app->get_file_name_size());
if(res) {
string_t key_str;
string_init_set_str(key_str, "ibutton/");
string_cat_str(key_str, app->get_file_name());
File key_file;
uint8_t key_data[IBUTTON_KEY_SIZE + 1] = {};
// Read data from file
// TODO handle false return
res = app->get_fs_api()->file.open(
&key_file, string_get_cstr(key_str), FSAM_READ, FSOM_OPEN_EXISTING);
res = app->get_fs_api()->file.read(&key_file, key_data, IBUTTON_KEY_SIZE + 1);
res = app->get_fs_api()->file.close(&key_file);
string_clear(key_str);
// Set key
iButtonKeyType key_type = static_cast<iButtonKeyType>(key_data[0]);
if(key_type > iButtonKeyType::KeyMetakom) {
app->switch_to_next_scene(iButtonApp::Scene::SceneStart);
}
app->get_key()->set_name(app->get_file_name());
app->get_key()->set_type(key_type);
app->get_key()->set_data(key_data + 1, IBUTTON_KEY_SIZE);
app->switch_to_next_scene(iButtonApp::Scene::SceneSavedKeyMenu);
} else {
// TODO add error scene
app->switch_to_next_scene(iButtonApp::Scene::SceneStart);
}
}; break;
case SubmenuIndexAdd:
app->switch_to_next_scene(iButtonApp::Scene::SceneAddType);
break;