Fixed going from View to Create then crash
This commit is contained in:
parent
89e49adf5a
commit
736277bc76
4 changed files with 52 additions and 41 deletions
|
@ -1 +0,0 @@
|
||||||
Data: Q|A|S|0
|
|
|
@ -36,6 +36,9 @@ char** split_string(const char* str, char delimiter, int* count) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
void string_append(char* first, const char* second) {
|
void string_append(char* first, const char* second) {
|
||||||
|
// Store first index
|
||||||
|
char* i_first = first;
|
||||||
|
|
||||||
// Get to the end of string 1
|
// Get to the end of string 1
|
||||||
while (*first) {
|
while (*first) {
|
||||||
++first;
|
++first;
|
||||||
|
@ -45,6 +48,9 @@ void string_append(char* first, const char* second) {
|
||||||
while (*second) {
|
while (*second) {
|
||||||
*first++ = *second++;
|
*first++ = *second++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset index
|
||||||
|
first = i_first;
|
||||||
}
|
}
|
||||||
void manager_loadnames(Manager* manager){
|
void manager_loadnames(Manager* manager){
|
||||||
// Loading the names of all passwords
|
// Loading the names of all passwords
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// Structures
|
// Structures
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Password* current;
|
Password* current;
|
||||||
|
Password* new;
|
||||||
|
|
||||||
char** names;
|
char** names;
|
||||||
int count;
|
int count;
|
||||||
|
|
|
@ -229,46 +229,56 @@ void FP_Scene_Enter_Create(void* context) {
|
||||||
// Reset page
|
// Reset page
|
||||||
submenu_reset(app->submenu);
|
submenu_reset(app->submenu);
|
||||||
|
|
||||||
// Did we already start a password?
|
|
||||||
if (!app->manager->current) {
|
|
||||||
app->manager->current = malloc(sizeof(Password));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking if we typed something before
|
// Checking if we typed something before
|
||||||
if (app->temp) {
|
if (app->temp) {
|
||||||
// Checking what we selected
|
// Boolean
|
||||||
switch (app->selection) {
|
bool is_field = true;
|
||||||
case 0: // Name
|
|
||||||
// Does name already exist?
|
// Checking if it's any of the following:
|
||||||
if (app->manager->current->name) {
|
if (!strcmp(app->temp, "Username")) {is_field = false;}
|
||||||
free(app->manager->current->name);
|
if (!strcmp(app->temp, "Password")) {is_field = false;}
|
||||||
|
|
||||||
|
// We're good!
|
||||||
|
if(is_field) {
|
||||||
|
// Did we already start a password?
|
||||||
|
if (!app->manager->new) {
|
||||||
|
app->manager->new = malloc(sizeof(Password));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copying it
|
// Checking what we selected
|
||||||
app->manager->current->name = malloc(sizeof(char*));
|
switch (app->selection) {
|
||||||
strcpy(app->manager->current->name, app->temp);
|
case 0: // Name
|
||||||
|
// Does name already exist?
|
||||||
|
if (app->manager->new->name) {
|
||||||
|
free(app->manager->new->name);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
// Copying it
|
||||||
case 1: // Username
|
app->manager->new->name = malloc(sizeof(char*));
|
||||||
// Does user already exist?
|
strcpy(app->manager->new->name, app->temp);
|
||||||
if (app->manager->current->user) {
|
|
||||||
free(app->manager->current->user);
|
break;
|
||||||
|
case 1: // Username
|
||||||
|
// Does user already exist?
|
||||||
|
if (app->manager->new->user) {
|
||||||
|
free(app->manager->new->user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copying it
|
||||||
|
app->manager->new->user = malloc(sizeof(char*));
|
||||||
|
strcpy(app->manager->new->user, app->temp);
|
||||||
|
break;
|
||||||
|
case 2: // Password
|
||||||
|
// Does phrase already exist?
|
||||||
|
if (app->manager->new->phrase) {
|
||||||
|
free(app->manager->new->phrase);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copying it
|
||||||
|
app->manager->new->phrase = malloc(sizeof(char*));
|
||||||
|
strcpy(app->manager->new->phrase, app->temp);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copying it
|
|
||||||
app->manager->current->user = malloc(sizeof(char*));
|
|
||||||
strcpy(app->manager->current->user, app->temp);
|
|
||||||
break;
|
|
||||||
case 2: // Password
|
|
||||||
// Does phrase already exist?
|
|
||||||
if (app->manager->current->phrase) {
|
|
||||||
free(app->manager->current->phrase);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copying it
|
|
||||||
app->manager->current->phrase = malloc(sizeof(char*));
|
|
||||||
strcpy(app->manager->current->phrase, app->temp);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Freeing temp
|
// Freeing temp
|
||||||
|
@ -518,12 +528,7 @@ bool FP_Scene_Event_Create(void* context, SceneManagerEvent event) {
|
||||||
break;
|
break;
|
||||||
case FP_Scene_Create_Event_Done:
|
case FP_Scene_Create_Event_Done:
|
||||||
// Save the password
|
// Save the password
|
||||||
manager_savepass(app->manager, app->manager->current);
|
manager_savepass(app->manager, app->manager->new);
|
||||||
|
|
||||||
// Freeing temp string
|
|
||||||
if (app->temp) {
|
|
||||||
free(app->temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reload manager
|
// Reload manager
|
||||||
manager_free(app->manager);
|
manager_free(app->manager);
|
||||||
|
|
Loading…
Reference in a new issue