mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 12:41:21 +00:00
client curl update.
displaying download progress based on a new cvar, 0 by default.
This commit is contained in:
parent
f32d1e2ed7
commit
80ce342557
3 changed files with 27 additions and 1 deletions
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue