created code for checking versions.json is avaible

This commit is contained in:
Václav Šmejkal 2022-04-29 17:31:01 +02:00
parent d3a03a08b2
commit a04da40120

View File

@ -8,9 +8,17 @@
#include "../include/flags.h" #include "../include/flags.h"
#define CLEAR_SCREEN "\e[1;1H\e[2J"
#define NOT_FOUND_TRIES 10
#define DOWNLOAD_FAILED 1
void void
checkVersion() checkVersion()
{ {
//FILE-CHECK VARIABLES
int notFoundBuffer = 0;
//REMOVE versions.json //REMOVE versions.json
if (access(VERSIONS_NAME, F_OK) == 0) if (access(VERSIONS_NAME, F_OK) == 0)
{ {
@ -32,6 +40,20 @@ checkVersion()
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
fclose(fileBuffer); 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 //JSON VARIABLES
fileBuffer = fopen(VERSIONS_NAME, "r"); fileBuffer = fopen(VERSIONS_NAME, "r");
char buffer[256]; char buffer[256];