Merge pull request #775 from devnexen/curl_update_progress

client curl update proposal.
This commit is contained in:
Yamagi 2021-12-24 08:52:55 +01:00 committed by GitHub
commit d8c8bb0ba7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View file

@ -553,6 +553,7 @@ CL_InitLocal(void)
cl_http_filelists = Cvar_Get("cl_http_filelists", "1", 0);
cl_http_downloads = Cvar_Get("cl_http_downloads", "1", CVAR_ARCHIVE);
cl_http_max_connections = Cvar_Get("cl_http_max_connections", "4", 0);
cl_http_show_dw_progress = Cvar_Get("cl_http_show_dw_progress", "0", 0);
#endif
/* register our commands */

View file

@ -35,6 +35,7 @@ cvar_t *cl_http_downloads;
cvar_t *cl_http_filelists;
cvar_t *cl_http_proxy;
cvar_t *cl_http_max_connections;
cvar_t *cl_http_show_dw_progress;
dlquirks_t dlquirks = { .error = false, .filelist = true, .gamedir = {'\0'} };
@ -52,6 +53,16 @@ static int abortDownloads = HTTPDL_ABORT_NONE;
static qboolean downloadingPak = false;
static qboolean httpDown = false;
#if defined(CURLOPT_XFERINFODATA)
typedef curl_off_t CL_Progresstype;
#define PROGRESSDATA CURLOPT_XFERINFODATA
#define PROGRESSFUNCTION CURLOPT_XFERINFOFUNCTION
#else
typedef double CL_Progresstype;
#define PROGRESSDATA CURLOPT_PROGRESSDATA
#define PROGRESSFUNCTION CURLOPT_PROGRESSFUNCTION
#endif
// --------
// CURL callback functions
@ -109,6 +120,15 @@ static size_t CL_HTTP_CurlWriteCB(char* data, size_t size, size_t nmemb, void* u
return fwrite(data, size, nmemb, dl->file);
}
static int CL_HTTP_CurlProgressCB(void* ptr, CL_Progresstype total /* unused */, CL_Progresstype now,
CL_Progresstype uptotal /* unused */, CL_Progresstype upnow /* unused */)
{
dlhandle_t *dl = (dlhandle_t *)ptr;
dl->fileDownloadedSize = (size_t)now;
Com_DPrintf("CL_HTTP_CurlProgressCB: Downloaded %zu/%zu\n", dl->fileDownloadedSize, dl->fileSize);
return 0;
}
// --------
// Helper functions
@ -244,6 +264,7 @@ static void CL_StartHTTPDownload (dlqueue_t *entry, dlhandle_t *dl)
dl->tempBuffer = NULL;
dl->fileSize = 0;
dl->position = 0;
dl->fileDownloadedSize = 0;
dl->queueEntry = entry;
// Setup and configure the CURL part of our download handle.
@ -269,7 +290,9 @@ static void CL_StartHTTPDownload (dlqueue_t *entry, dlhandle_t *dl)
qcurl_easy_setopt(dl->curl, CURLOPT_PROXY, cl_http_proxy->string);
qcurl_easy_setopt(dl->curl, CURLOPT_FOLLOWLOCATION, 1);
qcurl_easy_setopt(dl->curl, CURLOPT_MAXREDIRS, 5);
qcurl_easy_setopt(dl->curl, CURLOPT_PROGRESSDATA, dl);
qcurl_easy_setopt(dl->curl, CURLOPT_NOPROGRESS, (cl_http_show_dw_progress->value != 1.0));
qcurl_easy_setopt(dl->curl, PROGRESSDATA, dl);
qcurl_easy_setopt(dl->curl, PROGRESSFUNCTION, CL_HTTP_CurlProgressCB);
qcurl_easy_setopt(dl->curl, CURLOPT_USERAGENT, Cvar_VariableString ("version"));
qcurl_easy_setopt(dl->curl, CURLOPT_REFERER, cls.downloadReferer);
qcurl_easy_setopt(dl->curl, CURLOPT_URL, dl->URL);

View file

@ -56,6 +56,7 @@ typedef struct dlhandle_s
dlqueue_t *queueEntry;
size_t fileSize;
size_t position;
size_t fileDownloadedSize;
char URL[576];
char *tempBuffer;
} dlhandle_t;
@ -73,6 +74,7 @@ extern cvar_t *cl_http_downloads;
extern cvar_t *cl_http_filelists;
extern cvar_t *cl_http_proxy;
extern cvar_t *cl_http_max_connections;
extern cvar_t *cl_http_show_dw_progress;
void CL_CancelHTTPDownloads(qboolean permKill);
void CL_InitHTTPDownloads(void);