Combine all HTTP download quirks into a strict dlquirks_t.

Working with getter and setters was a good idea as long as we had one or
two quirks. Now we're at three with maybe more to come so it's easier to
use a struct to communicate quirks between the precacher and the HTTP
download code.
This commit is contained in:
Yamagi Burmeister 2019-02-17 09:28:26 +01:00
parent b1629fb768
commit f96a82010e
3 changed files with 29 additions and 58 deletions

View file

@ -42,7 +42,7 @@ extern byte *precache_model;
// Forces all downloads to UDP.
qboolean forceudp = false;
/* This - and some more code downn below - are the 'Crazy Fallback
/* This - and some more code down below - is the 'Crazy Fallback
Magic'. First we're trying to download all files over HTTP with
r1q2-style URLs. If we encountered errors we reset the complete
precacher state and retry with HTTP and q2pro-style URLs. If we
@ -74,7 +74,7 @@ CL_RequestNextDownload(void)
{
#if USE_CURL
// r1q2-style URLs.
CL_HTTP_SetDownloadGamedir(cl.gamedir);
Q_strlcpy(dlquirks.gamedir, cl.gamedir, sizeof(dlquirks.gamedir));
#endif
}
else if (precacherIteration == 1)
@ -83,15 +83,15 @@ CL_RequestNextDownload(void)
// q2pro-style URLs.
if (cl.gamedir[0] == '\0')
{
CL_HTTP_SetDownloadGamedir(BASEDIRNAME);
Q_strlcpy(dlquirks.gamedir, BASEDIRNAME, sizeof(dlquirks.gamedir));
}
else
{
CL_HTTP_SetDownloadGamedir(cl.gamedir);
Q_strlcpy(dlquirks.gamedir, cl.gamedir, sizeof(dlquirks.gamedir));
}
// Force another try with the filelist.
CL_HTTP_EnableGenericFilelist();
dlquirks.filelist = true;
gamedirForFilelist = true;
#endif
}
@ -405,8 +405,10 @@ CL_RequestNextDownload(void)
}
if (CL_CheckHTTPError())
if (dlquirks.error)
{
dlquirks.error = false;
/* Mkay, there were download errors. Let's start over. */
precacherIteration++;
CL_ResetPrecacheCheck();
@ -506,7 +508,7 @@ CL_RequestNextDownload(void)
gamedirForFilelist = false;
#ifdef USE_CURL
CL_HTTP_EnableGenericFilelist();
dlquirks.filelist = true;
#endif
CL_RegisterSounds();

View file

@ -36,6 +36,8 @@ cvar_t *cl_http_filelists;
cvar_t *cl_http_proxy;
cvar_t *cl_http_max_connections;
dlquirks_t dlquirks = { .error = false, .filelist = true, .gamedir = '\0' };
typedef enum
{
HTTPDL_ABORT_NONE,
@ -48,9 +50,6 @@ static int handleCount = 0;
static int pendingCount = 0;
static int abortDownloads = HTTPDL_ABORT_NONE;
static qboolean httpDown = false;
static qboolean downloadError = false;
static qboolean downloadFilelist = true;
static char downloadGamedir[MAX_QPATH];
// --------
@ -206,13 +205,13 @@ static void CL_StartHTTPDownload (dlqueue_t *entry, dlhandle_t *dl)
Com_sprintf (dl->filePath, sizeof(dl->filePath), "%s/%s", FS_Gamedir(), entry->quakePath);
// Full path to the remote file.
if (downloadGamedir[0] == '\0')
if (dlquirks.gamedir[0] == '\0')
{
Com_sprintf (tempFile, sizeof(tempFile), "/%s", entry->quakePath);
}
else
{
Com_sprintf (tempFile, sizeof(tempFile), "/%s/%s", downloadGamedir, entry->quakePath);
Com_sprintf (tempFile, sizeof(tempFile), "/%s/%s", dlquirks.gamedir, entry->quakePath);
}
CL_EscapeHTTPPath (tempFile, escapedFilePath);
@ -608,7 +607,7 @@ static void CL_FinishHTTPDownload(void)
// ...and communicate the error.
if (isFile)
{
downloadError = true;
dlquirks.error = true;
isFile = false;
}
@ -930,7 +929,7 @@ void CL_SetHTTPServer (const char *URL)
abortDownloads = HTTPDL_ABORT_NONE;
handleCount = pendingCount = 0;
cls.downloadServerRetry[0] = 0;
downloadError = false;
dlquirks.error = false;
// Remove trailing / from URL if any.
size_t urllen = strlen(URL);
@ -1007,10 +1006,10 @@ qboolean CL_QueueHTTPDownload(const char *quakePath, qboolean gamedirForFilelist
// the generic(!) filelist.
qboolean needList = false;
if (downloadFilelist && cl_http_filelists->value)
if (dlquirks.filelist && cl_http_filelists->value)
{
needList = true;
downloadFilelist = false;
dlquirks.filelist = false;
}
// Queue the download.
@ -1041,7 +1040,7 @@ qboolean CL_QueueHTTPDownload(const char *quakePath, qboolean gamedirForFilelist
{
char fileList[MAX_OSPATH];
Com_sprintf(fileList, sizeof(fileList), "/%s%s", downloadGamedir, ".filelist");
Com_sprintf(fileList, sizeof(fileList), "/%s%s", dlquirks.gamedir, ".filelist");
CL_QueueHTTPDownload(fileList, false);
}
else
@ -1063,13 +1062,13 @@ qboolean CL_QueueHTTPDownload(const char *quakePath, qboolean gamedirForFilelist
char listPath[MAX_OSPATH];
char filePath[MAX_OSPATH];
if (downloadGamedir[0] == '\0')
if (dlquirks.gamedir[0] == '\0')
{
Com_sprintf (filePath, sizeof(filePath), "/%s", quakePath);
}
else
{
Com_sprintf (filePath, sizeof(filePath), "/%s/%s", downloadGamedir, quakePath);
Com_sprintf (filePath, sizeof(filePath), "/%s/%s", dlquirks.gamedir, quakePath);
}
COM_StripExtension (filePath, listPath);
@ -1102,42 +1101,6 @@ qboolean CL_PendingHTTPDownloads(void)
return pendingCount + handleCount;
}
/*
* Checks if there was an error. Returns
* true if yes, and false if not.
*/
qboolean CL_CheckHTTPError(void)
{
if (downloadError)
{
downloadError = false;
return true;
}
else
{
return false;
}
}
/*
* Enables generic file list download starting
* with the next file. Yes, this is dirty.
*/
void CL_HTTP_EnableGenericFilelist(void)
{
downloadFilelist = true;
}
/*
* Sets the gamedir to be used by the URL
* generator to determine the remote file
* path.
*/
void CL_HTTP_SetDownloadGamedir(const char *gamedir)
{
Q_strlcpy(downloadGamedir, gamedir, sizeof(downloadGamedir));
}
/*
* Calls CURL to perform the actual downloads.
* Must be called every frame, otherwise CURL

View file

@ -60,6 +60,15 @@ typedef struct dlhandle_s
char *tempBuffer;
} dlhandle_t;
typedef struct dlquirks_s
{
qboolean error;
qboolean filelist;
char gamedir[MAX_QPATH];
} dlquirks_t;
extern dlquirks_t dlquirks;
extern cvar_t *cl_http_downloads;
extern cvar_t *cl_http_filelists;
extern cvar_t *cl_http_proxy;
@ -72,9 +81,6 @@ void CL_RunHTTPDownloads(void);
qboolean CL_PendingHTTPDownloads(void);
void CL_SetHTTPServer(const char *URL);
void CL_HTTP_Cleanup(qboolean fullShutdown);
qboolean CL_CheckHTTPError();
void CL_HTTP_EnableGenericFilelist(void);
void CL_HTTP_SetDownloadGamedir(const char *gamedir);
#endif // DOWNLOAD_H
#endif // USE_CURL