diff --git a/main.cpp b/main.cpp index 6e34731..e70e452 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,15 @@ struct Input { size_t bin_count; }; +static int progress_callback(void* clientp, double dltotal, double dlnow, double ultotal, double ulnow) { + if (dltotal <= 0) return 0; + + int progress = static_cast((dlnow / dltotal) * 100); + cerr << "Progress: " << progress << "%\r"; + cerr.flush(); + return 0; +} + Input input_data(istream& in, bool prompt) { Input inp; size_t number_count; @@ -35,34 +44,36 @@ Input input_data(istream& in, bool prompt) { return inp; } -size_t -write_data(void* items, size_t item_size, size_t item_count, void* ctx) { +size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) { stringstream* buffer = reinterpret_cast(ctx); size_t data_size = item_size * item_count; (*buffer).write(reinterpret_cast(items), data_size); return data_size; } -Input -download(const string& adress){ +Input download(const string& address){ stringstream buffer; CURL* curl = curl_easy_init(); if(curl) { - CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, adress.c_str()); + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); + res = curl_easy_perform(curl); if (res != CURLE_OK){ cerr << curl_easy_strerror(res); exit(1); } curl_easy_cleanup(curl); + cerr << endl; } return input_data(buffer, false); } + int main(int argc, char* argv[]) { Input input; if (argc > 1) {