fix crash with hash task

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-07-04 16:38:40 +03:00
parent 80243ab554
commit 1dd21a5e4a
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -18,8 +18,7 @@ Hasher::Ptr createHasher(QString file_path, ModPlatform::ResourceProvider provid
case ModPlatform::ResourceProvider::FLAME: case ModPlatform::ResourceProvider::FLAME:
return makeShared<Hasher>(file_path, Algorithm::Murmur2); return makeShared<Hasher>(file_path, Algorithm::Murmur2);
default: default:
qCritical() << "[Hashing]" qCritical() << "[Hashing]" << "Unrecognized mod platform!";
<< "Unrecognized mod platform!";
return nullptr; return nullptr;
} }
} }
@ -129,6 +128,10 @@ QString hash(QString fileName, Algorithm type)
QFile file(fileName); QFile file(fileName);
return hash(&file, type); return hash(&file, type);
} }
QString hashFile(QString fileName, Algorithm type)
{
return hash(fileName, type);
}
QString hash(QByteArray data, Algorithm type) QString hash(QByteArray data, Algorithm type)
{ {
@ -138,7 +141,7 @@ QString hash(QByteArray data, Algorithm type)
void Hasher::executeTask() void Hasher::executeTask()
{ {
m_future = QtConcurrent::run(QThreadPool::globalInstance(), [this]() { return hash(m_path, m_alg); }); m_future = QtConcurrent::run(QThreadPool::globalInstance(), hashFile, m_path, m_alg);
connect(&m_watcher, &QFutureWatcher<QString>::finished, this, [this] { connect(&m_watcher, &QFutureWatcher<QString>::finished, this, [this] {
if (m_future.isCanceled()) { if (m_future.isCanceled()) {
emitAborted(); emitAborted();