mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
Linux: improve progess indication
Report data actually written to device instead of to cache.
This commit is contained in:
parent
b08ed20e5f
commit
3248f9f04b
2 changed files with 28 additions and 3 deletions
|
@ -32,7 +32,7 @@ QByteArray DownloadThread::_proxy;
|
||||||
int DownloadThread::_curlCount = 0;
|
int DownloadThread::_curlCount = 0;
|
||||||
|
|
||||||
DownloadThread::DownloadThread(const QByteArray &url, const QByteArray &localfilename, const QByteArray &expectedHash, QObject *parent) :
|
DownloadThread::DownloadThread(const QByteArray &url, const QByteArray &localfilename, const QByteArray &expectedHash, QObject *parent) :
|
||||||
QThread(parent), _startOffset(0), _lastDlTotal(0), _lastDlNow(0), _verifyTotal(0), _lastVerifyNow(0), _bytesWritten(0), _url(url), _filename(localfilename), _expectedHash(expectedHash),
|
QThread(parent), _startOffset(0), _lastDlTotal(0), _lastDlNow(0), _verifyTotal(0), _lastVerifyNow(0), _bytesWritten(0), _sectorsStart(-1), _url(url), _filename(localfilename), _expectedHash(expectedHash),
|
||||||
_firstBlock(nullptr), _cancelled(false), _successful(false), _verifyEnabled(false), _cacheEnabled(false), _lastModified(0), _serverTime(0), _lastFailureTime(0),
|
_firstBlock(nullptr), _cancelled(false), _successful(false), _verifyEnabled(false), _cacheEnabled(false), _lastModified(0), _serverTime(0), _lastFailureTime(0),
|
||||||
_file(NULL), _writehash(OSLIST_HASH_ALGORITHM), _verifyhash(OSLIST_HASH_ALGORITHM), _inputBufferSize(0)
|
_file(NULL), _writehash(OSLIST_HASH_ALGORITHM), _verifyhash(OSLIST_HASH_ALGORITHM), _inputBufferSize(0)
|
||||||
{
|
{
|
||||||
|
@ -253,6 +253,7 @@ bool DownloadThread::_openAndPrepareDevice()
|
||||||
qDebug() << "BLKDISCARD successful";
|
qDebug() << "BLKDISCARD successful";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_sectorsStart = _sectorsWritten();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -288,7 +289,6 @@ void DownloadThread::run()
|
||||||
if (!_proxy.isEmpty())
|
if (!_proxy.isEmpty())
|
||||||
curl_easy_setopt(_c, CURLOPT_PROXY, _proxy.constData());
|
curl_easy_setopt(_c, CURLOPT_PROXY, _proxy.constData());
|
||||||
|
|
||||||
|
|
||||||
_timer.start();
|
_timer.start();
|
||||||
CURLcode ret = curl_easy_perform(_c);
|
CURLcode ret = curl_easy_perform(_c);
|
||||||
|
|
||||||
|
@ -503,7 +503,10 @@ uint64_t DownloadThread::verifyTotal()
|
||||||
|
|
||||||
uint64_t DownloadThread::bytesWritten()
|
uint64_t DownloadThread::bytesWritten()
|
||||||
{
|
{
|
||||||
return _bytesWritten;
|
if (_sectorsStart != -1)
|
||||||
|
return (_sectorsWritten()-_sectorsStart)*512;
|
||||||
|
else
|
||||||
|
return _bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadThread::_onDownloadSuccess()
|
void DownloadThread::_onDownloadSuccess()
|
||||||
|
@ -663,3 +666,23 @@ void DownloadThread::setInputBufferSize(int len)
|
||||||
{
|
{
|
||||||
_inputBufferSize = len;
|
_inputBufferSize = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 DownloadThread::_sectorsWritten()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
if (!_filename.startsWith("/dev/"))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
QFile f("/sys/class/block/"+_filename.mid(5)+"/stat");
|
||||||
|
if (!f.open(f.ReadOnly))
|
||||||
|
return -1;
|
||||||
|
QByteArray ioline = f.readAll().simplified();
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
QList<QByteArray> stats = ioline.split(' ');
|
||||||
|
|
||||||
|
if (stats.count() >= 6)
|
||||||
|
return stats.at(6).toLongLong(); /* write sectors */
|
||||||
|
#endif
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
|
@ -138,6 +138,7 @@ protected:
|
||||||
int _authopen(const QByteArray &filename);
|
int _authopen(const QByteArray &filename);
|
||||||
bool _openAndPrepareDevice();
|
bool _openAndPrepareDevice();
|
||||||
void _writeCache(const char *buf, size_t len);
|
void _writeCache(const char *buf, size_t len);
|
||||||
|
qint64 _sectorsWritten();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* libcurl callbacks
|
* libcurl callbacks
|
||||||
|
@ -153,6 +154,7 @@ protected:
|
||||||
CURL *_c;
|
CURL *_c;
|
||||||
curl_off_t _startOffset;
|
curl_off_t _startOffset;
|
||||||
std::atomic<std::uint64_t> _lastDlTotal, _lastDlNow, _verifyTotal, _lastVerifyNow, _bytesWritten;
|
std::atomic<std::uint64_t> _lastDlTotal, _lastDlNow, _verifyTotal, _lastVerifyNow, _bytesWritten;
|
||||||
|
qint64 _sectorsStart;
|
||||||
QByteArray _url, _useragent, _buf, _filename, _lastError, _expectedHash;
|
QByteArray _url, _useragent, _buf, _filename, _lastError, _expectedHash;
|
||||||
char *_firstBlock;
|
char *_firstBlock;
|
||||||
size_t _firstBlockSize;
|
size_t _firstBlockSize;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue