Trouble reading files
This commit is contained in:
parent
629315f348
commit
1c729552ef
8 changed files with 97 additions and 32 deletions
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
#define TAG "FlippyPass"
|
#define TAG "FlippyPass"
|
||||||
#define PATH "/ext/apps_assets/flippypass/user.dat"
|
#define PATH "/ext/apps_data/flippypass/user.dat"
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,10 +1,11 @@
|
||||||
// Header
|
// Header
|
||||||
#include "pass.h"
|
#include "pass.h"
|
||||||
|
#include <furi.h>
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
password* pass_create(char* name, char* user, char* phrase, int folder) {
|
Password* pass_create(char* name, char* user, char* phrase, int folder) {
|
||||||
// Creating a new instance of a password
|
// Creating a new instance of a password
|
||||||
password* result = malloc(sizeof(password));
|
Password* result = malloc(sizeof(Password));
|
||||||
|
|
||||||
// Setting data
|
// Setting data
|
||||||
result->name = name;
|
result->name = name;
|
||||||
|
@ -15,18 +16,8 @@ password* pass_create(char* name, char* user, char* phrase, int folder) {
|
||||||
// Returning result
|
// Returning result
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
password* pass_load(char* path) {
|
|
||||||
// Creating a new instance of a password
|
|
||||||
password* result = malloc(sizeof(password));
|
|
||||||
|
|
||||||
// Not using path right now
|
|
||||||
UNUSED(path);
|
|
||||||
|
|
||||||
// Return Result
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void pass_delete(password* pass){
|
void pass_delete(Password* pass){
|
||||||
free(pass);
|
free(pass);
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
#define H_PASS
|
#define H_PASS
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include <furi.h>
|
#include "store.h"
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -12,13 +12,12 @@ typedef struct {
|
||||||
char* phrase;
|
char* phrase;
|
||||||
|
|
||||||
int folder;
|
int folder;
|
||||||
} password;
|
} Password;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
password* pass_create(char* name, char* user, char* phrase, int folder);
|
Password* pass_create(char* name, char* user, char* phrase, int folder);
|
||||||
password* pass_load(char* path);
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void pass_delete(password* pass);
|
void pass_delete(Password* pass);
|
||||||
|
|
||||||
#endif
|
#endif
|
47
project/backend/store.c
Normal file
47
project/backend/store.c
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// Header
|
||||||
|
#include "store.h"
|
||||||
|
#include <furi.h>
|
||||||
|
#include <flipper_format.h>
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
FStorage* store_load() {
|
||||||
|
// Allocating memory for storage struct
|
||||||
|
FStorage* result = malloc(sizeof(FStorage));
|
||||||
|
|
||||||
|
// Reading storage
|
||||||
|
Storage* _storage = furi_record_open(RECORD_STORAGE);
|
||||||
|
FlipperFormat* _format = flipper_format_file_alloc(_storage);
|
||||||
|
|
||||||
|
FuriString* _data = furi_string_alloc();
|
||||||
|
|
||||||
|
// Opening file
|
||||||
|
if (!flipper_format_file_open_existing(_format, PATH)) {
|
||||||
|
FURI_LOG_E(TAG, "Couldn't open %s", PATH);
|
||||||
|
return NULL;
|
||||||
|
} else if (!flipper_format_read_string(_format, "Data", _data)) {
|
||||||
|
FURI_LOG_E(TAG, "Couldn't read %s", PATH);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy data into result
|
||||||
|
const char* _cstr_data = furi_string_get_cstr(_data);
|
||||||
|
result->data = malloc(strlen(_cstr_data) + 1);
|
||||||
|
strcpy(result->data, _cstr_data);
|
||||||
|
|
||||||
|
// Free the original string
|
||||||
|
furi_string_free(_data);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
flipper_format_free(_format);
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
|
||||||
|
// Returning result
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
void store_unload(FStorage* store) {
|
||||||
|
// Cleaning up memory
|
||||||
|
free(store->data);
|
||||||
|
free(store);
|
||||||
|
}
|
19
project/backend/store.h
Normal file
19
project/backend/store.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// Define once
|
||||||
|
#ifndef H_STORE
|
||||||
|
#define H_STORE
|
||||||
|
|
||||||
|
// Libraries
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
|
// Structures
|
||||||
|
typedef struct {
|
||||||
|
char* data;
|
||||||
|
} FStorage;
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
FStorage* store_load();
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
void store_unload(FStorage* store);
|
||||||
|
|
||||||
|
#endif
|
|
@ -2,9 +2,12 @@
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
uiManager* ui_create() {
|
UIManager* ui_create() {
|
||||||
// Creating the UI Manager
|
// Creating the UI Manager
|
||||||
uiManager* result = malloc(sizeof(uiManager));
|
UIManager* result = malloc(sizeof(UIManager));
|
||||||
|
|
||||||
|
// Creating Storage
|
||||||
|
result->store = store_load();
|
||||||
|
|
||||||
// Defining basic variables
|
// Defining basic variables
|
||||||
result->running = true;
|
result->running = true;
|
||||||
|
@ -29,7 +32,7 @@ uiManager* ui_create() {
|
||||||
|
|
||||||
void ui_input(InputEvent* event, void* ctx) {
|
void ui_input(InputEvent* event, void* ctx) {
|
||||||
// Turning the context back into the UI Manager
|
// Turning the context back into the UI Manager
|
||||||
uiManager* manager = (uiManager*)ctx;
|
UIManager* manager = (UIManager*)ctx;
|
||||||
|
|
||||||
// Getting input
|
// Getting input
|
||||||
if (event->type == InputTypePress
|
if (event->type == InputTypePress
|
||||||
|
@ -66,7 +69,7 @@ void ui_input(InputEvent* event, void* ctx) {
|
||||||
|
|
||||||
void ui_draw(Canvas* canvas, void* ctx) {
|
void ui_draw(Canvas* canvas, void* ctx) {
|
||||||
// Context into Result
|
// Context into Result
|
||||||
uiManager* manager = (uiManager*)ctx;
|
UIManager* manager = (UIManager*)ctx;
|
||||||
|
|
||||||
// Switching page
|
// Switching page
|
||||||
switch(manager->page){
|
switch(manager->page){
|
||||||
|
@ -81,7 +84,7 @@ void ui_draw(Canvas* canvas, void* ctx) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ui_p_mainmenu(Canvas* canvas, uiManager* manager) {
|
void ui_p_mainmenu(Canvas* canvas, UIManager* manager) {
|
||||||
// Menu Options
|
// Menu Options
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str(canvas, 2, 11, "FlippyPass");
|
canvas_draw_str(canvas, 2, 11, "FlippyPass");
|
||||||
|
@ -150,7 +153,7 @@ void ui_p_about(Canvas* canvas) {
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_str(canvas, 3, 32, "Manager for the Flipper-Zero.");
|
canvas_draw_str(canvas, 3, 32, "Manager for the Flipper-Zero.");
|
||||||
}
|
}
|
||||||
void ui_p_view(Canvas* canvas, uiManager* manager){
|
void ui_p_view(Canvas* canvas, UIManager* manager){
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str(canvas, 2, 11, "FlippyPass");
|
canvas_draw_str(canvas, 2, 11, "FlippyPass");
|
||||||
|
|
||||||
|
@ -166,6 +169,9 @@ void ui_p_view(Canvas* canvas, uiManager* manager){
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_str(canvas, 15, 53, "Facebook"); */
|
canvas_draw_str(canvas, 15, 53, "Facebook"); */
|
||||||
|
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
canvas_draw_str(canvas, 15, 23, manager->store->data);
|
||||||
|
|
||||||
if (manager->press_used) {
|
if (manager->press_used) {
|
||||||
manager->press_used = false;
|
manager->press_used = false;
|
||||||
|
|
||||||
|
@ -185,7 +191,7 @@ void ui_p_view(Canvas* canvas, uiManager* manager){
|
||||||
canvas_draw_str(canvas, 106, 62, "1/1");
|
canvas_draw_str(canvas, 106, 62, "1/1");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_delete(uiManager* manager) {
|
void ui_delete(UIManager* manager) {
|
||||||
view_port_enabled_set(manager->canvas, false);
|
view_port_enabled_set(manager->canvas, false);
|
||||||
gui_remove_view_port(manager->gui, manager->canvas);
|
gui_remove_view_port(manager->gui, manager->canvas);
|
||||||
view_port_free(manager->canvas);
|
view_port_free(manager->canvas);
|
||||||
|
|
|
@ -9,9 +9,12 @@
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "pass.h"
|
#include "pass.h"
|
||||||
|
#include "store.h"
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
FStorage* store;
|
||||||
|
|
||||||
ViewPort* canvas;
|
ViewPort* canvas;
|
||||||
Gui* gui;
|
Gui* gui;
|
||||||
enum ui_input {
|
enum ui_input {
|
||||||
|
@ -30,19 +33,19 @@ typedef struct {
|
||||||
bool running;
|
bool running;
|
||||||
bool press_used;
|
bool press_used;
|
||||||
bool press_avail;
|
bool press_avail;
|
||||||
} uiManager;
|
} UIManager;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
uiManager* ui_create();
|
UIManager* ui_create();
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void ui_input(InputEvent* event, void* ctx);
|
void ui_input(InputEvent* event, void* ctx);
|
||||||
|
|
||||||
void ui_draw(Canvas* canvas, void* ctx);
|
void ui_draw(Canvas* canvas, void* ctx);
|
||||||
void ui_p_mainmenu(Canvas* canvas, uiManager* manager);
|
void ui_p_mainmenu(Canvas* canvas, UIManager* manager);
|
||||||
void ui_p_about(Canvas* canvas);
|
void ui_p_about(Canvas* canvas);
|
||||||
void ui_p_view(Canvas* canvas, uiManager* manager);
|
void ui_p_view(Canvas* canvas, UIManager* manager);
|
||||||
|
|
||||||
void ui_delete(uiManager* manager);
|
void ui_delete(UIManager* manager);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -9,7 +9,7 @@ int32_t flippypass_app(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
|
|
||||||
// Creating the UI struct
|
// Creating the UI struct
|
||||||
uiManager* ui = ui_create();
|
UIManager* ui = ui_create();
|
||||||
|
|
||||||
// Drawwing the UI
|
// Drawwing the UI
|
||||||
while(ui->running) {
|
while(ui->running) {
|
||||||
|
|
Loading…
Reference in a new issue