diff --git a/src/misc.c b/src/misc.c index 283f430..4e1b54b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -8,9 +8,17 @@ #include "../include/flags.h" +#define CLEAR_SCREEN "\e[1;1H\e[2J" +#define NOT_FOUND_TRIES 10 + +#define DOWNLOAD_FAILED 1 + void checkVersion() { + //FILE-CHECK VARIABLES + int notFoundBuffer = 0; + //REMOVE versions.json if (access(VERSIONS_NAME, F_OK) == 0) { @@ -32,6 +40,20 @@ checkVersion() curl_easy_cleanup(curl); fclose(fileBuffer); + while (access(VERSIONS_NAME, R_OK) != 0) + { + notFoundBuffer++; + + if (notFoundBuffer == NOT_FOUND_TRIES) + { + fprintf(stderr, "%s'%s' not found!\n", CLEAR_SCREEN, VERSIONS_NAME); + exit(DOWNLOAD_FAILED); + } + + printf("%s'%s' not found (%dx)! Trying again in a second.\n", CLEAR_SCREEN, VERSIONS_NAME, notFoundBuffer); + sleep(1); + } + //JSON VARIABLES fileBuffer = fopen(VERSIONS_NAME, "r"); char buffer[256];