From fae65ade05705ccd29ae58fe6f69d803bd27d9dd Mon Sep 17 00:00:00 2001 From: GordiyevskikDA Date: Sun, 12 May 2024 15:24:57 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BE=D0=B4=20=D0=B4=D0=BB=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LABA1.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/LABA1.cpp b/LABA1.cpp index bbf9077..1d61138 100644 --- a/LABA1.cpp +++ b/LABA1.cpp @@ -6,9 +6,14 @@ #include #include #include +#include using namespace std; +struct progress { + char* privat; + size_t size; +}; void svg_begin(double width, double height) { cout << "\n"; @@ -97,15 +102,31 @@ size_t write_header(char* buffer, size_t size, size_t nitems, void* userdata) return size * nitems; } +static size_t progress_callback(void* clientp, + double dltotal, + double dlnow, + double ultotal, + double ulnow) +{ + struct progress* memory = (progress*)clientp; + cerr << "Progress: " << (dlnow / dltotal) * 100 << "%\n"; + //cerr << "Progress: " << memory->privat << "\n"; + return 0; /* all is good */ +} + Input download(const string& address) { stringstream buffer; + struct progress data; CURL* curl = curl_easy_init(); if (curl) { CURLcode res; curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_header); curl_easy_setopt(curl, CURLOPT_HEADERDATA, NULL); res = curl_easy_perform(curl);