fix: add some more nullptr checks / protection
die sigsegv 🔫
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
a9e8ed5087
commit
f4b207220c
@ -24,8 +24,10 @@ EnsureMetadataTask::EnsureMetadataTask(Mod* mod, QDir dir, ModPlatform::Provider
|
|||||||
: Task(nullptr), m_index_dir(dir), m_provider(prov), m_hashing_task(nullptr), m_current_task(nullptr)
|
: Task(nullptr), m_index_dir(dir), m_provider(prov), m_hashing_task(nullptr), m_current_task(nullptr)
|
||||||
{
|
{
|
||||||
auto hash_task = createNewHash(mod);
|
auto hash_task = createNewHash(mod);
|
||||||
|
if (!hash_task)
|
||||||
|
return;
|
||||||
connect(hash_task.get(), &Task::succeeded, [this, hash_task, mod] { m_mods.insert(hash_task->getResult(), mod); });
|
connect(hash_task.get(), &Task::succeeded, [this, hash_task, mod] { m_mods.insert(hash_task->getResult(), mod); });
|
||||||
connect(hash_task.get(), &Task::failed, [this, hash_task, mod] { emitFail(mod, RemoveFromList::No); });
|
connect(hash_task.get(), &Task::failed, [this, hash_task, mod] { emitFail(mod, "", RemoveFromList::No); });
|
||||||
hash_task->start();
|
hash_task->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,14 +40,14 @@ EnsureMetadataTask::EnsureMetadataTask(QList<Mod*>& mods, QDir dir, ModPlatform:
|
|||||||
if (!hash_task)
|
if (!hash_task)
|
||||||
continue;
|
continue;
|
||||||
connect(hash_task.get(), &Task::succeeded, [this, hash_task, mod] { m_mods.insert(hash_task->getResult(), mod); });
|
connect(hash_task.get(), &Task::succeeded, [this, hash_task, mod] { m_mods.insert(hash_task->getResult(), mod); });
|
||||||
connect(hash_task.get(), &Task::failed, [this, hash_task, mod] { emitFail(mod, RemoveFromList::No); });
|
connect(hash_task.get(), &Task::failed, [this, hash_task, mod] { emitFail(mod, "", RemoveFromList::No); });
|
||||||
m_hashing_task->addTask(hash_task);
|
m_hashing_task->addTask(hash_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Hashing::Hasher::Ptr EnsureMetadataTask::createNewHash(Mod* mod)
|
Hashing::Hasher::Ptr EnsureMetadataTask::createNewHash(Mod* mod)
|
||||||
{
|
{
|
||||||
if (!mod->valid() || mod->type() == Mod::MOD_FOLDER)
|
if (!mod || !mod->valid() || mod->type() == Mod::MOD_FOLDER)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return Hashing::createHasher(mod->fileinfo().absoluteFilePath(), m_provider);
|
return Hashing::createHasher(mod->fileinfo().absoluteFilePath(), m_provider);
|
||||||
@ -120,7 +122,7 @@ void EnsureMetadataTask::executeTask()
|
|||||||
QMutableHashIterator<QString, Mod*> mods_iter(m_mods);
|
QMutableHashIterator<QString, Mod*> mods_iter(m_mods);
|
||||||
while (mods_iter.hasNext()) {
|
while (mods_iter.hasNext()) {
|
||||||
auto mod = mods_iter.next();
|
auto mod = mods_iter.next();
|
||||||
emitFail(mod.value());
|
emitFail(mod.value(), mod.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
@ -168,22 +170,44 @@ void EnsureMetadataTask::executeTask()
|
|||||||
version_task->start();
|
version_task->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnsureMetadataTask::emitReady(Mod* m, RemoveFromList remove)
|
void EnsureMetadataTask::emitReady(Mod* m, QString key, RemoveFromList remove)
|
||||||
{
|
{
|
||||||
|
if (!m) {
|
||||||
|
qCritical() << "Tried to mark a null mod as ready.";
|
||||||
|
if (!key.isEmpty())
|
||||||
|
m_mods.remove(key);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << QString("Generated metadata for %1").arg(m->name());
|
qDebug() << QString("Generated metadata for %1").arg(m->name());
|
||||||
emit metadataReady(m);
|
emit metadataReady(m);
|
||||||
|
|
||||||
if (remove == RemoveFromList::Yes)
|
if (remove == RemoveFromList::Yes) {
|
||||||
m_mods.remove(getExistingHash(m));
|
if (key.isEmpty())
|
||||||
|
key = getExistingHash(m);
|
||||||
|
m_mods.remove(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnsureMetadataTask::emitFail(Mod* m, RemoveFromList remove)
|
void EnsureMetadataTask::emitFail(Mod* m, QString key, RemoveFromList remove)
|
||||||
{
|
{
|
||||||
|
if (!m) {
|
||||||
|
qCritical() << "Tried to mark a null mod as failed.";
|
||||||
|
if (!key.isEmpty())
|
||||||
|
m_mods.remove(key);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << QString("Failed to generate metadata for %1").arg(m->name());
|
qDebug() << QString("Failed to generate metadata for %1").arg(m->name());
|
||||||
emit metadataFailed(m);
|
emit metadataFailed(m);
|
||||||
|
|
||||||
if (remove == RemoveFromList::Yes)
|
if (remove == RemoveFromList::Yes) {
|
||||||
m_mods.remove(getExistingHash(m));
|
if (key.isEmpty())
|
||||||
|
key = getExistingHash(m);
|
||||||
|
m_mods.remove(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modrinth
|
// Modrinth
|
||||||
|
@ -39,8 +39,8 @@ class EnsureMetadataTask : public Task {
|
|||||||
Yes,
|
Yes,
|
||||||
No
|
No
|
||||||
};
|
};
|
||||||
void emitReady(Mod*, RemoveFromList = RemoveFromList::Yes);
|
void emitReady(Mod*, QString key = {}, RemoveFromList = RemoveFromList::Yes);
|
||||||
void emitFail(Mod*, RemoveFromList = RemoveFromList::Yes);
|
void emitFail(Mod*, QString key = {}, RemoveFromList = RemoveFromList::Yes);
|
||||||
|
|
||||||
// Hashes and stuff
|
// Hashes and stuff
|
||||||
auto createNewHash(Mod*) -> Hashing::Hasher::Ptr;
|
auto createNewHash(Mod*) -> Hashing::Hasher::Ptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user