load file on startup if it exists

This commit is contained in:
Zvonimir Rudinski
2024-06-02 06:10:38 +02:00
parent 40f2155a34
commit ec9a455a49

8
main.c
View File

@@ -256,6 +256,12 @@ void load_from_file_handler(void) {
clear_todos(); clear_todos();
FILE *file = fopen(SAVE_FILE, "rb"); FILE *file = fopen(SAVE_FILE, "rb");
// if unable to open the file, return
if (file == NULL) {
return;
}
char magic[5] = {'\0'}; char magic[5] = {'\0'};
int todos_count = 0; int todos_count = 0;
// check the "TODD" (without the \0) magic value // check the "TODD" (without the \0) magic value
@@ -316,6 +322,8 @@ int main(int argc, char **argv) {
snprintf(SAVE_FILE, MAX_PATH_LENGTH, "%s/.todos.todd", homedir); snprintf(SAVE_FILE, MAX_PATH_LENGTH, "%s/.todos.todd", homedir);
} }
// if file exists, load it
load_from_file_handler();
initialize_curses(&terminal_width, &terminal_height); initialize_curses(&terminal_width, &terminal_height);
while (running) { while (running) {