Вызываю:
for(int i = 0; i<count_to_download; i++){
//downloading
if(save_file(tracks_to_download[i].url, tracks_to_download[i].title, tracks_to_download[i].artist, settings[2])){
cout<<"Success with download "<<tracks_to_download[i].title<<endl;
}
}
bool save_file(string url, string title, string artist, string path){
//curl things
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func); //statusbar
//curl things
}
Функция:
int progress_func(void* ptr, double TotalToDownload, double NowDownloaded,
double TotalToUpload, double NowUploaded)
{
// how wide you want the progress meter to be
int totaldotz=40;
double fractiondownloaded = 0.0;
//avoiding NaN in fractiondownloaded
if(NowDownloaded!=0){
fractiondownloaded = NowDownloaded / TotalToDownload;
}
// part of the progressmeter that's already "full"
int dotz = round(fractiondownloaded * totaldotz);
cout.sync_with_stdio(false);
// create the "meter"
int ii=0;
// part that's full already
for ( ; ii < dotz;ii++) {
cout<<".";
}
// remaining part (spaces)
for ( ; ii < totaldotz;ii++) {
cout<<" ";
}
//avoiding 0 at right
if(fractiondownloaded!=0){
cout.precision(3);
cout<<fractiondownloaded*100<<"%"; //why it showing three "%" ?
}
cout<<"\r";
// and back to line begin - do not forget the fflush to avoid output buffering problems!
cout.flush();
return 0;
}
Показывает:
......................................100%%%%