| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <QCryptographicHash>
|
| | #include <QDateTime>
|
| | #include <QFileInfo>
|
| | #include <QString>
|
| | #include <QTimeZone>
|
| | #include <QUrl>
|
| | #include <fmt/format.h>
|
| |
|
| | #include "FileUtilities.h"
|
| | #include <Base/TimeInfo.h>
|
| |
|
| |
|
| | void Start::createThumbnailsDir()
|
| | {
|
| | if (!thumbnailsParentDir.exists(defaultThumbnailName)) {
|
| | thumbnailsParentDir.mkpath(defaultThumbnailName);
|
| | }
|
| | }
|
| |
|
| | QString Start::getMD5Hash(const QString& path)
|
| | {
|
| |
|
| |
|
| | QUrl url(path);
|
| | url.setScheme(QStringLiteral("file"));
|
| | QCryptographicHash hash(QCryptographicHash::Md5);
|
| | hash.addData(url.toEncoded());
|
| | const QByteArray ba = hash.result().toHex();
|
| | return QString::fromLatin1(ba);
|
| | }
|
| |
|
| | QString Start::getPathToCachedThumbnail(const QString& path)
|
| | {
|
| | const QString md5 = getMD5Hash(path) + QLatin1String(".png");
|
| | return thumbnailsDir.absoluteFilePath(md5);
|
| | }
|
| |
|
| | bool Start::useCachedThumbnail(const QString& image, const QString& project)
|
| | {
|
| | const QFileInfo f1(image);
|
| | const QFileInfo f2(project);
|
| | if (!f1.exists()) {
|
| | return false;
|
| | }
|
| | if (!f2.exists()) {
|
| | return false;
|
| | }
|
| |
|
| | return f1.lastModified() > f2.lastModified();
|
| | }
|
| |
|
| | std::string Start::humanReadableSize(uint64_t bytes)
|
| | {
|
| | if (bytes == 0) {
|
| | return "0 B";
|
| | }
|
| |
|
| |
|
| | constexpr std::array units {"B", "kB", "MB", "GB", "TB", "PB", "EB"};
|
| | constexpr double unitFactor = 1000.0;
|
| |
|
| | const double logBaseFactor = std::log10(unitFactor);
|
| | const auto unitIndex = static_cast<size_t>(std::log10(bytes) / logBaseFactor);
|
| |
|
| |
|
| |
|
| | const auto unit = units.at(unitIndex);
|
| |
|
| | const double scaledValue = static_cast<double>(bytes) / std::pow(unitFactor, unitIndex);
|
| |
|
| | const bool isByteUnit = unitIndex == 0;
|
| | const size_t precision = isByteUnit ? 0 : 1;
|
| | return fmt::format("{:.{}f} {}", scaledValue, precision, unit);
|
| | }
|
| |
|
| | std::string Start::getLastModifiedAsString(const Base::FileInfo& file)
|
| | {
|
| | Base::TimeInfo lastModified = file.lastModified();
|
| | return QDateTime::fromSecsSinceEpoch(lastModified.getTime_t())
|
| | .toTimeZone(QTimeZone::utc())
|
| | .toString(Qt::ISODate)
|
| | .toStdString();
|
| | }
|
| |
|