ensure history list will contain crc32 (#13883)

This commit is contained in:
Alexander Trufanov 2022-04-25 16:53:23 +03:00 committed by GitHub
parent f377c0d041
commit 141bba0464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -45,6 +45,7 @@
#include <QDropEvent>
#include <QtConcurrentRun>
#include <QtNetwork>
#include <QFile>
#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<QString, QString> MainWindow::getFileContentHash(const QModelIndex &index)
return hash;
}
QHash<QString, QString> MainWindow::getFileContentHashWithCRC32(const QModelIndex &index)
{
QHash<QString, QString> 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:

View File

@ -398,6 +398,8 @@ public:
QModelIndex getCurrentContentIndex();
QHash<QString, QString> getCurrentContentHash();
QHash<QString, QString> getFileContentHash(const QModelIndex &index);
QHash<QString, QString> 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<QPair<QString, QString> > getPlaylists();