From ef43aecaf0258c29060a54c5c1a1fc5dd9987094 Mon Sep 17 00:00:00 2001 From: Maddox Werts Date: Sun, 1 Sep 2024 14:45:37 -0400 Subject: [PATCH] Created default stuff to get ready to read passwords --- project/backend/manager.c | 79 +++++++++++++++++++++++++++++++++++++++ project/backend/manager.h | 24 ++++++++++++ project/backend/ui.c | 15 ++++++-- project/backend/ui.h | 5 ++- project/flippypass.c | 3 ++ 5 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 project/backend/manager.c create mode 100644 project/backend/manager.h diff --git a/project/backend/manager.c b/project/backend/manager.c new file mode 100644 index 0000000..5f41bf8 --- /dev/null +++ b/project/backend/manager.c @@ -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); +} \ No newline at end of file diff --git a/project/backend/manager.h b/project/backend/manager.h new file mode 100644 index 0000000..d7779a8 --- /dev/null +++ b/project/backend/manager.h @@ -0,0 +1,24 @@ +// Define once +#ifndef H_MANAGER +#define H_MANAGER + +// Libraries +#include + +#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 \ No newline at end of file diff --git a/project/backend/ui.c b/project/backend/ui.c index 762f465..b63eb5a 100644 --- a/project/backend/ui.c +++ b/project/backend/ui.c @@ -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; diff --git a/project/backend/ui.h b/project/backend/ui.h index 954bd2e..e057016 100644 --- a/project/backend/ui.h +++ b/project/backend/ui.h @@ -8,8 +8,7 @@ #include #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; diff --git a/project/flippypass.c b/project/flippypass.c index 11d33e4..27c2145 100644 --- a/project/flippypass.c +++ b/project/flippypass.c @@ -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();