diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index 40bf8e4096..eaf1710d8f 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include "ui_qt.h" #include "qt/gridview.h" @@ -82,6 +83,7 @@ extern "C" { #include "../../command.h" #include "../ui_companion_driver.h" #include "../../configuration.h" +#include "../../encodings/crc32.h" #include "../../frontend/frontend.h" #include "../../frontend/frontend_driver.h" #include "../../file_path_special.h" @@ -2599,7 +2601,7 @@ void MainWindow::onFileDoubleClicked(const QModelIndex &proxyIndex) if (m_fileModel->isDir(index)) m_dirTree->setCurrentIndex(m_dirModel->index(m_fileModel->filePath(index))); else - loadContent(getFileContentHash(index)); + loadContent(getFileContentHashWithCRC32(index)); } void MainWindow::selectBrowserDir(QString path) @@ -2670,6 +2672,29 @@ QHash MainWindow::getFileContentHash(const QModelIndex &index) return hash; } +QHash MainWindow::getFileContentHashWithCRC32(const QModelIndex &index) +{ + QHash hash = getFileContentHash(index); + hash["crc32"] = getFileCRC32(hash["path"]); + return hash; +} + +QString MainWindow::getFileCRC32(const QString &path) +{ + QString crc32; + QFile file(path); + if (file.exists() && file.open(QIODevice::ReadOnly)) { + const QByteArray buf = file.readAll(); + file.close(); + crc32 = QString::number(encoding_crc32(0, (const uint8_t *) buf.data(), buf.size()), 16).toUpper(); + while (crc32.length() < 8) { + crc32 = crc32.prepend('0'); + } + } + + return crc32; +} + void MainWindow::onContentItemDoubleClicked(const QModelIndex &index) { Q_UNUSED(index); @@ -2933,7 +2958,7 @@ void MainWindow::onRunClicked() switch (m_currentBrowser) { case BROWSER_TYPE_FILES: - contentHash = getFileContentHash( + contentHash = getFileContentHashWithCRC32( m_proxyFileModel->mapToSource(m_fileTableView->currentIndex())); break; case BROWSER_TYPE_PLAYLISTS: diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 3763dd4a98..469fdea2c2 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -398,6 +398,8 @@ public: QModelIndex getCurrentContentIndex(); QHash getCurrentContentHash(); QHash getFileContentHash(const QModelIndex &index); + QHash getFileContentHashWithCRC32(const QModelIndex &index); + QString getFileCRC32(const QString &path); static double lerp(double x, double y, double a, double b, double d); QString getSpecialPlaylistPath(SpecialPlaylist playlist); QVector > getPlaylists();