Created default stuff to get ready to read passwords

This commit is contained in:
Maddox Werts 2024-09-01 14:45:37 -04:00
parent 4a7c0f689e
commit ef43aecaf0
5 changed files with 120 additions and 6 deletions

79
project/backend/manager.c Normal file
View file

@ -0,0 +1,79 @@
// Header
#include "manager.h"
// Functions - Private
char** split_string(const char* str, char delimiter, int* count) {
// Calculate how many substrings will be created
int i, numSubstrings = 1;
for (i = 0; str[i] != '\0'; i++) {
if (str[i] == delimiter) {
numSubstrings++;
}
}
// Allocate memory for the array of strings
char** result = malloc(numSubstrings * sizeof(char*));
*count = numSubstrings;
// Split the string
int start = 0, substringIndex = 0;
for (i = 0; str[i] != '\0'; i++) {
if (str[i] == delimiter) {
int length = i - start;
result[substringIndex] = malloc((length + 1) * sizeof(char));
strncpy(result[substringIndex], str + start, length);
result[substringIndex][length] = '\0';
start = i + 1;
substringIndex++;
}
}
// Add the last substring
int length = i - start;
result[substringIndex] = malloc((length + 1) * sizeof(char));
strncpy(result[substringIndex], str + start, length);
result[substringIndex][length] = '\0';
return result;
}
// Constructors
Manager* manager_create() {
// Creating result in memory
Manager* result = malloc(sizeof(Manager));
// Returning manager
return result;
}
// Functions
void manager_loadnames(Manager* manager, int page){
// Relieving unused parameters
UNUSED(manager);
UNUSED(page);
// Loading the next four passwords
char* data = store_load("Data");
// Splitting string
int count = 0;
char** split = split_string(data, '|', &count);
// Temporary variables
// Going through split string
for (int i = 0; i < count; i++) {
// Checking if it's the 4th number
if (i % 4 == 0) {
FURI_LOG_I(TAG, "\nName:");
}
FURI_LOG_I(TAG, "(%i): %s", i, split[i]);
}
// Cleanup
free(split);
free(data);
}
void manager_delete(Manager* manager) {
free(manager);
}

24
project/backend/manager.h Normal file
View file

@ -0,0 +1,24 @@
// Define once
#ifndef H_MANAGER
#define H_MANAGER
// Libraries
#include <furi.h>
#include "app.h"
#include "pass.h"
#include "store.h"
// Structures
typedef struct {
char* names[4];
} Manager;
// Constructors
Manager* manager_create();
// Functions
void manager_loadnames(Manager* manager, int page);
void manager_delete(Manager* manager);
#endif

View file

@ -6,6 +6,10 @@ UIManager* ui_create() {
// Creating the UI Manager
UIManager* result = malloc(sizeof(UIManager));
// Creating the manager
result->manager = manager_create();
manager_loadnames(result->manager, result->page);
// Defining basic variables
result->running = true;
result->selection = 0;
@ -176,10 +180,13 @@ void ui_p_view(Canvas* canvas, UIManager* manager){
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 15, 53, "Facebook"); */
// Loading data storage
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 15, 23, "TODO: Create Manager");
// Counting through password names
for (int i = 0; i < 4; i++) {
if (manager->manager->names[i] != NULL) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 15, 23 + (i * 10), manager->manager->names[i]);
}
}
if (manager->is_pressing) {
manager->is_pressing = false;

View file

@ -8,8 +8,7 @@
#include <gui/icon.h>
#include "app.h"
#include "pass.h"
#include "store.h"
#include "manager.h"
// Structures
typedef struct {
@ -25,6 +24,8 @@ typedef struct {
Back
} input;
Manager* manager;
int selection;
int page;

View file

@ -8,6 +8,9 @@ int32_t flippypass_app(void* p) {
// Not using P Parameter
UNUSED(p);
// Saving to a default file:
store_save("Data", "Apple|example@objnull.net|password|0|Microsoft|person@objnull.net|password|0");
// Creating the UI struct
UIManager* ui = ui_create();