From a04da40120fe0981a8e7a65e77c16f1e541693e0 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 29 Apr 2022 17:31:01 +0200 Subject: [PATCH] created code for checking versions.json is avaible --- src/misc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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];