mirror of https://github.com/vitalif/grive2
Fix auth segfault, remove 1/1000 progressbar interval (fixes #103)
parent
f27e3724de
commit
67b5b05e17
|
@ -159,13 +159,16 @@ std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, CurlAgent
|
||||||
int CurlAgent::progress_callback( CurlAgent *pthis, curl_off_t totalDownload, curl_off_t finishedDownload, curl_off_t totalUpload, curl_off_t finishedUpload )
|
int CurlAgent::progress_callback( CurlAgent *pthis, curl_off_t totalDownload, curl_off_t finishedDownload, curl_off_t totalUpload, curl_off_t finishedUpload )
|
||||||
{
|
{
|
||||||
// Only report download progress when set explicitly
|
// Only report download progress when set explicitly
|
||||||
totalDownload = pthis->m_pimpl->total_download;
|
if ( pthis->m_pb )
|
||||||
if ( !totalUpload )
|
{
|
||||||
totalUpload = pthis->m_pimpl->total_upload;
|
totalDownload = pthis->m_pimpl->total_download;
|
||||||
pthis->m_pb->reportProgress(
|
if ( !totalUpload )
|
||||||
totalDownload > 0 ? totalDownload : totalUpload,
|
totalUpload = pthis->m_pimpl->total_upload;
|
||||||
totalDownload > 0 ? finishedDownload : finishedUpload
|
pthis->m_pb->reportProgress(
|
||||||
);
|
totalDownload > 0 ? totalDownload : totalUpload,
|
||||||
|
totalDownload > 0 ? finishedDownload : finishedUpload
|
||||||
|
);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
namespace gr
|
namespace gr
|
||||||
{
|
{
|
||||||
|
|
||||||
ProgressBar::ProgressBar(): showProgressBar(false), last(1000)
|
ProgressBar::ProgressBar(): showProgressBar(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,38 +48,33 @@ void ProgressBar::reportProgress(u64_t total, u64_t processed)
|
||||||
double fraction = (double)processed/total;
|
double fraction = (double)processed/total;
|
||||||
|
|
||||||
int point = round(fraction*1000);
|
int point = round(fraction*1000);
|
||||||
if (point != this->last)
|
|
||||||
{
|
|
||||||
// only print progress after >= 0.1% change
|
|
||||||
this->last = point;
|
|
||||||
|
|
||||||
// 10 for prefix of percent and 22 for suffix of file size
|
// 10 for prefix of percent and 22 for suffix of file size
|
||||||
int availableSize = determineTerminalSize() - 32;
|
int availableSize = determineTerminalSize() - 32;
|
||||||
int totalDots;
|
int totalDots;
|
||||||
if (availableSize > 100)
|
if (availableSize > 100)
|
||||||
totalDots = 100;
|
totalDots = 100;
|
||||||
else if (availableSize < 0)
|
else if (availableSize < 0)
|
||||||
totalDots = 10;
|
totalDots = 10;
|
||||||
else
|
else
|
||||||
totalDots = availableSize;
|
totalDots = availableSize;
|
||||||
|
|
||||||
int dotz = round(fraction * totalDots);
|
int dotz = round(fraction * totalDots);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
// delete previous output line
|
// delete previous output line
|
||||||
printf("\r\33[2K [%3.0f%%] [", fraction * 100);
|
printf("\r\33[2K [%3.0f%%] [", fraction * 100);
|
||||||
for (; count < dotz - 1; count++)
|
for (; count < dotz - 1; count++)
|
||||||
putchar('=');
|
putchar('=');
|
||||||
putchar('>');
|
putchar('>');
|
||||||
for (; count < totalDots - 1; count++)
|
for (; count < totalDots - 1; count++)
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
printf("] ");
|
printf("] ");
|
||||||
printBytes(processed);
|
printBytes(processed);
|
||||||
putchar('/');
|
putchar('/');
|
||||||
printBytes(total);
|
printBytes(total);
|
||||||
if (point == 1000)
|
if (point == 1000)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ private:
|
||||||
static unsigned short int determineTerminalSize();
|
static unsigned short int determineTerminalSize();
|
||||||
|
|
||||||
bool showProgressBar;
|
bool showProgressBar;
|
||||||
int last;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue