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
|
||||
#define TAG "FlippyPass"
|
||||
#define PATH "/ext/apps_assets/flippypass/user.dat"
|
||||
#define PATH "/ext/apps_data/flippypass/user.dat"
|
||||
|
||||
#endif
|
|
@ -1,10 +1,11 @@
|
|||
// Header
|
||||
#include "pass.h"
|
||||
#include <furi.h>
|
||||
|
||||
// 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
|
||||
password* result = malloc(sizeof(password));
|
||||
Password* result = malloc(sizeof(Password));
|
||||
|
||||
// Setting data
|
||||
result->name = name;
|
||||
|
@ -15,18 +16,8 @@ password* pass_create(char* name, char* user, char* phrase, int folder) {
|
|||
// Returning 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
|
||||
void pass_delete(password* pass){
|
||||
void pass_delete(Password* pass){
|
||||
free(pass);
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
#define H_PASS
|
||||
|
||||
// Libraries
|
||||
#include <furi.h>
|
||||
#include "store.h"
|
||||
|
||||
// Structures
|
||||
typedef struct {
|
||||
|
@ -12,13 +12,12 @@ typedef struct {
|
|||
char* phrase;
|
||||
|
||||
int folder;
|
||||
} password;
|
||||
} Password;
|
||||
|
||||
// Constructors
|
||||
password* pass_create(char* name, char* user, char* phrase, int folder);
|
||||
password* pass_load(char* path);
|
||||
Password* pass_create(char* name, char* user, char* phrase, int folder);
|
||||
|
||||
// Functions
|
||||
void pass_delete(password* pass);
|
||||
void pass_delete(Password* pass);
|
||||
|
||||
#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"
|
||||
|
||||
// Functions
|
||||
uiManager* ui_create() {
|
||||
UIManager* ui_create() {
|
||||
// Creating the UI Manager
|
||||
uiManager* result = malloc(sizeof(uiManager));
|
||||
UIManager* result = malloc(sizeof(UIManager));
|
||||
|
||||
// Creating Storage
|
||||
result->store = store_load();
|
||||
|
||||
// Defining basic variables
|
||||
result->running = true;
|
||||
|
@ -29,7 +32,7 @@ uiManager* ui_create() {
|
|||
|
||||
void ui_input(InputEvent* event, void* ctx) {
|
||||
// Turning the context back into the UI Manager
|
||||
uiManager* manager = (uiManager*)ctx;
|
||||
UIManager* manager = (UIManager*)ctx;
|
||||
|
||||
// Getting input
|
||||
if (event->type == InputTypePress
|
||||
|
@ -66,7 +69,7 @@ void ui_input(InputEvent* event, void* ctx) {
|
|||
|
||||
void ui_draw(Canvas* canvas, void* ctx) {
|
||||
// Context into Result
|
||||
uiManager* manager = (uiManager*)ctx;
|
||||
UIManager* manager = (UIManager*)ctx;
|
||||
|
||||
// Switching page
|
||||
switch(manager->page){
|
||||
|
@ -81,7 +84,7 @@ void ui_draw(Canvas* canvas, void* ctx) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
void ui_p_mainmenu(Canvas* canvas, uiManager* manager) {
|
||||
void ui_p_mainmenu(Canvas* canvas, UIManager* manager) {
|
||||
// Menu Options
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 11, "FlippyPass");
|
||||
|
@ -150,7 +153,7 @@ void ui_p_about(Canvas* canvas) {
|
|||
canvas_set_font(canvas, FontSecondary);
|
||||
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_draw_str(canvas, 2, 11, "FlippyPass");
|
||||
|
||||
|
@ -166,6 +169,9 @@ void ui_p_view(Canvas* canvas, uiManager* manager){
|
|||
canvas_set_font(canvas, FontSecondary);
|
||||
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) {
|
||||
manager->press_used = false;
|
||||
|
||||
|
@ -185,7 +191,7 @@ void ui_p_view(Canvas* canvas, uiManager* manager){
|
|||
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);
|
||||
gui_remove_view_port(manager->gui, manager->canvas);
|
||||
view_port_free(manager->canvas);
|
||||
|
|
|
@ -9,9 +9,12 @@
|
|||
|
||||
#include "app.h"
|
||||
#include "pass.h"
|
||||
#include "store.h"
|
||||
|
||||
// Structures
|
||||
typedef struct {
|
||||
FStorage* store;
|
||||
|
||||
ViewPort* canvas;
|
||||
Gui* gui;
|
||||
enum ui_input {
|
||||
|
@ -30,19 +33,19 @@ typedef struct {
|
|||
bool running;
|
||||
bool press_used;
|
||||
bool press_avail;
|
||||
} uiManager;
|
||||
} UIManager;
|
||||
|
||||
// Constructors
|
||||
uiManager* ui_create();
|
||||
UIManager* ui_create();
|
||||
|
||||
// Functions
|
||||
void ui_input(InputEvent* event, 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_view(Canvas* canvas, uiManager* manager);
|
||||
void ui_p_view(Canvas* canvas, UIManager* manager);
|
||||
|
||||
void ui_delete(uiManager* manager);
|
||||
void ui_delete(UIManager* manager);
|
||||
|
||||
#endif
|
|
@ -9,7 +9,7 @@ int32_t flippypass_app(void* p) {
|
|||
UNUSED(p);
|
||||
|
||||
// Creating the UI struct
|
||||
uiManager* ui = ui_create();
|
||||
UIManager* ui = ui_create();
|
||||
|
||||
// Drawwing the UI
|
||||
while(ui->running) {
|
||||
|
|
Loading…
Reference in a new issue