diff options
author | Arno <arno@disconnect.de> | 2018-11-23 18:01:05 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-11-23 18:01:05 +0100 |
commit | e5274f4c27f847bedaa910a84ed3468d1aba32e1 (patch) | |
tree | 5d6490c1ec081c88539ea9cdf528c9f285b780f0 | |
parent | 7992144aca4a80cd9903a8ea7df0e210087871b1 (diff) | |
download | SheMov-e5274f4c27f847bedaa910a84ed3468d1aba32e1.tar.gz SheMov-e5274f4c27f847bedaa910a84ed3468d1aba32e1.tar.bz2 SheMov-e5274f4c27f847bedaa910a84ed3468d1aba32e1.zip |
Fix helper warnings
Sprinkle some static_casts here and there and fix auto conversions. Also
introduce const ints for what to read for calculating the MD5-Sum of a
file... Seems to work fine.
-rw-r--r-- | helper.cpp | 43 | ||||
-rw-r--r-- | helper.h | 6 |
2 files changed, 27 insertions, 22 deletions
@@ -41,7 +41,7 @@ namespace Helper { magic_t mc = magic_open(MAGIC_MIME_TYPE); QByteArray name = path.toUtf8(); if(mc){ - magic_load(mc, 0); + magic_load(mc, nullptr); const char* magic_c = magic_file(mc, name.constData()); retval = QString(magic_c); magic_close(mc); @@ -49,7 +49,7 @@ namespace Helper { if(retval.toLower().startsWith("application/octet-stream")){ magic_t mc = magic_open(MAGIC_NONE); if(mc){ - magic_load(mc, 0); + magic_load(mc, nullptr); const char* magic_c = magic_file(mc, name.constData()); QString desc(magic_c); magic_close(mc); @@ -67,29 +67,34 @@ namespace Helper { return QString(); } + const int blockSize = 4096; + const int bigBlockSize = 512; QString retval; QCryptographicHash h(QCryptographicHash::Md5); QFile file(path); file.open(QIODevice::ReadOnly); - qint64 read = 0; + int read = 0; + // if the file is smaller than 5MB hash it entirely if(info.size() < (5 * 1024 * 1024)){ - QByteArray data(4096, '\0'); + QByteArray data(blockSize, '\0'); do { - read = file.read(data.data(), 4096); + //read can never be bigger than blockSize, that 4k for now... + read = static_cast<int>(file.read(data.data(), blockSize)); if(read > 0){ h.addData(data.data(), read); } - } while (read == 4096); + } while (read == blockSize); QByteArray res = h.result(); retval = res.toHex().toLower(); + // otherwise hash only parts for performance }else{ - QByteArray data(512, '\0'); - int offset = info.size() / 3; + QByteArray data(bigBlockSize, '\0'); + auto offset = info.size() / 3; file.seek(offset); - int numBytes = 512 * 1024; + int numBytes = bigBlockSize * 1024; int readBytes = 0; do { - read = file.read(data.data(), 512); + read = static_cast<int>(file.read(data.data(), bigBlockSize)); if(read > 0){ readBytes += read; }else{ @@ -192,9 +197,9 @@ namespace Helper { } const QString durationFromSecs(qint64 secs){ - int minutes = secs / 60; - int hours = 0; - int seconds = 0; + qint64 minutes = secs / 60; + qint64 hours = 0; + qint64 seconds = 0; if(minutes > 60){ hours = minutes / 60; minutes -= hours * 60; @@ -202,7 +207,7 @@ namespace Helper { seconds = secs - hours * 60 * 60 - minutes * 60; seconds = (seconds > 60) ? 59 : seconds; QByteArray retval(10, '\0'); - ::snprintf(retval.data(), 9, "%.2d:%.2d:%.2d", hours, minutes, seconds); + ::snprintf(retval.data(), 9, "%lld::%lld:%lld", hours, minutes, seconds); return retval; } @@ -221,7 +226,7 @@ namespace Helper { const QStringList toStringList(const QList<QVariant> &list){ QStringList retval; - foreach(QVariant v, list){ + for(QVariant v : list){ retval << v.toString(); } return retval; @@ -273,8 +278,8 @@ namespace Helper { QPixmap preview(const QString &path){ QVariantMap m = ffmpegData(path); - int secs = m.value("duration").toDouble(); - int interval = secs / 4; + auto secs = m.value("duration").toInt(); + auto interval = secs / 4; QImage retval(640 * 2 + 40, 480 * 2 + 40, QImage::Format_ARGB32); retval.fill(Qt::transparent); QPainter p(&retval); @@ -344,7 +349,7 @@ namespace Helper { try { img.write(outFile.fileName().toStdString()); } - catch(Magick::Exception &e) { + catch(Magick::Exception &) { return retval; } outFile.rename(newFn); @@ -401,7 +406,7 @@ namespace Helper { Duration::Duration() : mHours(0), mMinutes(0), mSeconds(0) {} Duration::Duration(qint64 seconds){ - int sec(0), min(0), h(0); + qint64 sec(0), min(0), h(0); // get hours h = (seconds / 60 / 60); // remaining minutes @@ -64,9 +64,9 @@ namespace Helper { qint64 toSeconds() const; private: - int mHours; - int mMinutes; - int mSeconds; + qint64 mHours; + qint64 mMinutes; + qint64 mSeconds; }; } |