Skip to content

Commit f431a06

Browse files
added failsafe
1 parent 3ad4ae9 commit f431a06

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

helpers/evil_portal_storage.c

+32-30
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ void evil_portal_read_index_html(void *context) {
3333
}
3434
storage_file_close(index_html);
3535
storage_file_free(index_html);
36+
} else {
37+
char * html_error = "Something went wrong with reading the html file.\n"
38+
"Is the SD Card set up correctly?";
39+
app->index_html = (uint8_t *)html_error;
3640
}
3741

3842
evil_portal_close_storage();
@@ -63,48 +67,46 @@ void evil_portal_read_ap_name(void *context) {
6367
}
6468
storage_file_close(ap_name);
6569
storage_file_free(ap_name);
70+
} else {
71+
char * app_default = "Evil Portal";
72+
app->ap_name = (uint8_t *)app_default;
6673
}
6774
evil_portal_close_storage();
6875
}
6976

70-
char* sequential_file_resolve_path(
71-
Storage* storage,
72-
const char* dir,
73-
const char* prefix,
74-
const char* extension) {
75-
if(storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {
76-
return NULL;
77-
}
77+
char *sequential_file_resolve_path(Storage *storage, const char *dir,
78+
const char *prefix, const char *extension) {
79+
if (storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {
80+
return NULL;
81+
}
7882

79-
char file_path[256];
80-
int file_index = 0;
83+
char file_path[256];
84+
int file_index = 0;
8185

82-
do {
83-
if(snprintf(
84-
file_path, sizeof(file_path), "%s/%s_%d.%s", dir, prefix, file_index, extension) <
85-
0) {
86-
return NULL;
87-
}
88-
file_index++;
89-
} while(storage_file_exists(storage, file_path));
86+
do {
87+
if (snprintf(file_path, sizeof(file_path), "%s/%s_%d.%s", dir, prefix,
88+
file_index, extension) < 0) {
89+
return NULL;
90+
}
91+
file_index++;
92+
} while (storage_file_exists(storage, file_path));
9093

91-
return strdup(file_path);
94+
return strdup(file_path);
9295
}
9396

94-
95-
void write_logs(char* portal_logs) {
97+
void write_logs(char *portal_logs) {
9698
Storage *storage = evil_portal_open_storage();
9799

98-
char* seq_file_path = sequential_file_resolve_path(storage, EVIL_PORTAL_LOG_SAVE_PATH, "log", "txt");
99-
100-
File* file = storage_file_alloc(storage);
100+
char *seq_file_path = sequential_file_resolve_path(
101+
storage, EVIL_PORTAL_LOG_SAVE_PATH, "log", "txt");
101102

102-
if (storage_file_open(file, seq_file_path, FSAM_WRITE,
103-
FSOM_CREATE_ALWAYS)) {
104-
storage_file_write(file, portal_logs, strlen(portal_logs));
105-
}
106-
storage_file_close(file);
107-
storage_file_free(file);
103+
File *file = storage_file_alloc(storage);
104+
105+
if (storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
106+
storage_file_write(file, portal_logs, strlen(portal_logs));
107+
}
108+
storage_file_close(file);
109+
storage_file_free(file);
108110
evil_portal_close_storage();
109111

110112
portal_logs = "";

0 commit comments

Comments
 (0)