Merge pull request #1083 from Ryex/fix/memory-leaks-develop
This commit is contained in:
commit
ce2d58bb7d
@ -34,7 +34,7 @@ class InstanceCreationTask : public InstanceTask {
|
|||||||
QString getError() const { return m_error_message; }
|
QString getError() const { return m_error_message; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setError(QString message) { m_error_message = message; };
|
void setError(const QString& message) { m_error_message = message; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_abort = false;
|
bool m_abort = false;
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
#include "NullInstance.h"
|
#include "NullInstance.h"
|
||||||
|
|
||||||
|
#include "QObjectPtr.h"
|
||||||
#include "icons/IconList.h"
|
#include "icons/IconList.h"
|
||||||
#include "icons/IconUtils.h"
|
#include "icons/IconUtils.h"
|
||||||
|
|
||||||
@ -260,7 +261,7 @@ void InstanceImportTask::extractFinished()
|
|||||||
|
|
||||||
void InstanceImportTask::processFlame()
|
void InstanceImportTask::processFlame()
|
||||||
{
|
{
|
||||||
FlameCreationTask* inst_creation_task = nullptr;
|
shared_qobject_ptr<FlameCreationTask> inst_creation_task = nullptr;
|
||||||
if (!m_extra_info.isEmpty()) {
|
if (!m_extra_info.isEmpty()) {
|
||||||
auto pack_id_it = m_extra_info.constFind("pack_id");
|
auto pack_id_it = m_extra_info.constFind("pack_id");
|
||||||
Q_ASSERT(pack_id_it != m_extra_info.constEnd());
|
Q_ASSERT(pack_id_it != m_extra_info.constEnd());
|
||||||
@ -275,10 +276,10 @@ void InstanceImportTask::processFlame()
|
|||||||
if (original_instance_id_it != m_extra_info.constEnd())
|
if (original_instance_id_it != m_extra_info.constEnd())
|
||||||
original_instance_id = original_instance_id_it.value();
|
original_instance_id = original_instance_id_it.value();
|
||||||
|
|
||||||
inst_creation_task = new FlameCreationTask(m_stagingPath, m_globalSettings, m_parent, pack_id, pack_version_id, original_instance_id);
|
inst_creation_task = makeShared<FlameCreationTask>(m_stagingPath, m_globalSettings, m_parent, pack_id, pack_version_id, original_instance_id);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: Find a way to get IDs in directly imported ZIPs
|
// FIXME: Find a way to get IDs in directly imported ZIPs
|
||||||
inst_creation_task = new FlameCreationTask(m_stagingPath, m_globalSettings, m_parent, {}, {});
|
inst_creation_task = makeShared<FlameCreationTask>(m_stagingPath, m_globalSettings, m_parent, QString(), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
inst_creation_task->setName(*this);
|
inst_creation_task->setName(*this);
|
||||||
@ -286,20 +287,19 @@ void InstanceImportTask::processFlame()
|
|||||||
inst_creation_task->setGroup(m_instGroup);
|
inst_creation_task->setGroup(m_instGroup);
|
||||||
inst_creation_task->setConfirmUpdate(shouldConfirmUpdate());
|
inst_creation_task->setConfirmUpdate(shouldConfirmUpdate());
|
||||||
|
|
||||||
connect(inst_creation_task, &Task::succeeded, this, [this, inst_creation_task] {
|
connect(inst_creation_task.get(), &Task::succeeded, this, [this, inst_creation_task] {
|
||||||
setOverride(inst_creation_task->shouldOverride(), inst_creation_task->originalInstanceID());
|
setOverride(inst_creation_task->shouldOverride(), inst_creation_task->originalInstanceID());
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
});
|
});
|
||||||
connect(inst_creation_task, &Task::failed, this, &InstanceImportTask::emitFailed);
|
connect(inst_creation_task.get(), &Task::failed, this, &InstanceImportTask::emitFailed);
|
||||||
connect(inst_creation_task, &Task::progress, this, &InstanceImportTask::setProgress);
|
connect(inst_creation_task.get(), &Task::progress, this, &InstanceImportTask::setProgress);
|
||||||
connect(inst_creation_task, &Task::stepProgress, this, &InstanceImportTask::propogateStepProgress);
|
connect(inst_creation_task.get(), &Task::stepProgress, this, &InstanceImportTask::propogateStepProgress);
|
||||||
connect(inst_creation_task, &Task::status, this, &InstanceImportTask::setStatus);
|
connect(inst_creation_task.get(), &Task::status, this, &InstanceImportTask::setStatus);
|
||||||
connect(inst_creation_task, &Task::details, this, &InstanceImportTask::setDetails);
|
connect(inst_creation_task.get(), &Task::details, this, &InstanceImportTask::setDetails);
|
||||||
connect(inst_creation_task, &Task::finished, inst_creation_task, &InstanceCreationTask::deleteLater);
|
|
||||||
|
|
||||||
connect(this, &Task::aborted, inst_creation_task, &InstanceCreationTask::abort);
|
connect(this, &Task::aborted, inst_creation_task.get(), &InstanceCreationTask::abort);
|
||||||
connect(inst_creation_task, &Task::aborted, this, &Task::abort);
|
connect(inst_creation_task.get(), &Task::aborted, this, &Task::abort);
|
||||||
connect(inst_creation_task, &Task::abortStatusChanged, this, &Task::setAbortable);
|
connect(inst_creation_task.get(), &Task::abortStatusChanged, this, &Task::setAbortable);
|
||||||
|
|
||||||
inst_creation_task->start();
|
inst_creation_task->start();
|
||||||
}
|
}
|
||||||
|
@ -1109,79 +1109,79 @@ JavaVersion MinecraftInstance::getJavaVersion()
|
|||||||
return JavaVersion(settings()->get("JavaVersion").toString());
|
return JavaVersion(settings()->get("JavaVersion").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList() const
|
std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList()
|
||||||
{
|
{
|
||||||
if (!m_loader_mod_list)
|
if (!m_loader_mod_list)
|
||||||
{
|
{
|
||||||
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
||||||
m_loader_mod_list.reset(new ModFolderModel(modsRoot(), shared_from_this(), is_indexed));
|
m_loader_mod_list.reset(new ModFolderModel(modsRoot(), this, is_indexed));
|
||||||
m_loader_mod_list->disableInteraction(isRunning());
|
m_loader_mod_list->disableInteraction(isRunning());
|
||||||
connect(this, &BaseInstance::runningStatusChanged, m_loader_mod_list.get(), &ModFolderModel::disableInteraction);
|
connect(this, &BaseInstance::runningStatusChanged, m_loader_mod_list.get(), &ModFolderModel::disableInteraction);
|
||||||
}
|
}
|
||||||
return m_loader_mod_list;
|
return m_loader_mod_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList() const
|
std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList()
|
||||||
{
|
{
|
||||||
if (!m_core_mod_list)
|
if (!m_core_mod_list)
|
||||||
{
|
{
|
||||||
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
||||||
m_core_mod_list.reset(new ModFolderModel(coreModsDir(), shared_from_this(), is_indexed));
|
m_core_mod_list.reset(new ModFolderModel(coreModsDir(), this, is_indexed));
|
||||||
m_core_mod_list->disableInteraction(isRunning());
|
m_core_mod_list->disableInteraction(isRunning());
|
||||||
connect(this, &BaseInstance::runningStatusChanged, m_core_mod_list.get(), &ModFolderModel::disableInteraction);
|
connect(this, &BaseInstance::runningStatusChanged, m_core_mod_list.get(), &ModFolderModel::disableInteraction);
|
||||||
}
|
}
|
||||||
return m_core_mod_list;
|
return m_core_mod_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList() const
|
std::shared_ptr<ModFolderModel> MinecraftInstance::nilModList()
|
||||||
{
|
{
|
||||||
if (!m_nil_mod_list)
|
if (!m_nil_mod_list)
|
||||||
{
|
{
|
||||||
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
|
||||||
m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), shared_from_this(), is_indexed, false));
|
m_nil_mod_list.reset(new ModFolderModel(nilModsDir(), this, is_indexed, false));
|
||||||
m_nil_mod_list->disableInteraction(isRunning());
|
m_nil_mod_list->disableInteraction(isRunning());
|
||||||
connect(this, &BaseInstance::runningStatusChanged, m_nil_mod_list.get(), &ModFolderModel::disableInteraction);
|
connect(this, &BaseInstance::runningStatusChanged, m_nil_mod_list.get(), &ModFolderModel::disableInteraction);
|
||||||
}
|
}
|
||||||
return m_nil_mod_list;
|
return m_nil_mod_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ResourcePackFolderModel> MinecraftInstance::resourcePackList() const
|
std::shared_ptr<ResourcePackFolderModel> MinecraftInstance::resourcePackList()
|
||||||
{
|
{
|
||||||
if (!m_resource_pack_list)
|
if (!m_resource_pack_list)
|
||||||
{
|
{
|
||||||
m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir(), shared_from_this()));
|
m_resource_pack_list.reset(new ResourcePackFolderModel(resourcePacksDir(), this));
|
||||||
}
|
}
|
||||||
return m_resource_pack_list;
|
return m_resource_pack_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TexturePackFolderModel> MinecraftInstance::texturePackList() const
|
std::shared_ptr<TexturePackFolderModel> MinecraftInstance::texturePackList()
|
||||||
{
|
{
|
||||||
if (!m_texture_pack_list)
|
if (!m_texture_pack_list)
|
||||||
{
|
{
|
||||||
m_texture_pack_list.reset(new TexturePackFolderModel(texturePacksDir(), shared_from_this()));
|
m_texture_pack_list.reset(new TexturePackFolderModel(texturePacksDir(), this));
|
||||||
}
|
}
|
||||||
return m_texture_pack_list;
|
return m_texture_pack_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList() const
|
std::shared_ptr<ShaderPackFolderModel> MinecraftInstance::shaderPackList()
|
||||||
{
|
{
|
||||||
if (!m_shader_pack_list)
|
if (!m_shader_pack_list)
|
||||||
{
|
{
|
||||||
m_shader_pack_list.reset(new ShaderPackFolderModel(shaderPacksDir(), shared_from_this()));
|
m_shader_pack_list.reset(new ShaderPackFolderModel(shaderPacksDir(), this));
|
||||||
}
|
}
|
||||||
return m_shader_pack_list;
|
return m_shader_pack_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<WorldList> MinecraftInstance::worldList() const
|
std::shared_ptr<WorldList> MinecraftInstance::worldList()
|
||||||
{
|
{
|
||||||
if (!m_world_list)
|
if (!m_world_list)
|
||||||
{
|
{
|
||||||
m_world_list.reset(new WorldList(worldDir(), shared_from_this()));
|
m_world_list.reset(new WorldList(worldDir(), this));
|
||||||
}
|
}
|
||||||
return m_world_list;
|
return m_world_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<GameOptions> MinecraftInstance::gameOptionsModel() const
|
std::shared_ptr<GameOptions> MinecraftInstance::gameOptionsModel()
|
||||||
{
|
{
|
||||||
if (!m_game_options)
|
if (!m_game_options)
|
||||||
{
|
{
|
||||||
|
@ -115,14 +115,14 @@ public:
|
|||||||
std::shared_ptr<PackProfile> getPackProfile() const;
|
std::shared_ptr<PackProfile> getPackProfile() const;
|
||||||
|
|
||||||
////// Mod Lists //////
|
////// Mod Lists //////
|
||||||
std::shared_ptr<ModFolderModel> loaderModList() const;
|
std::shared_ptr<ModFolderModel> loaderModList();
|
||||||
std::shared_ptr<ModFolderModel> coreModList() const;
|
std::shared_ptr<ModFolderModel> coreModList();
|
||||||
std::shared_ptr<ModFolderModel> nilModList() const;
|
std::shared_ptr<ModFolderModel> nilModList();
|
||||||
std::shared_ptr<ResourcePackFolderModel> resourcePackList() const;
|
std::shared_ptr<ResourcePackFolderModel> resourcePackList();
|
||||||
std::shared_ptr<TexturePackFolderModel> texturePackList() const;
|
std::shared_ptr<TexturePackFolderModel> texturePackList();
|
||||||
std::shared_ptr<ShaderPackFolderModel> shaderPackList() const;
|
std::shared_ptr<ShaderPackFolderModel> shaderPackList();
|
||||||
std::shared_ptr<WorldList> worldList() const;
|
std::shared_ptr<WorldList> worldList();
|
||||||
std::shared_ptr<GameOptions> gameOptionsModel() const;
|
std::shared_ptr<GameOptions> gameOptionsModel();
|
||||||
|
|
||||||
////// Launch stuff //////
|
////// Launch stuff //////
|
||||||
Task::Ptr createUpdateTask(Net::Mode mode) override;
|
Task::Ptr createUpdateTask(Net::Mode mode) override;
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
WorldList::WorldList(const QString &dir, std::shared_ptr<const BaseInstance> instance)
|
WorldList::WorldList(const QString &dir, BaseInstance* instance)
|
||||||
: QAbstractListModel(), m_instance(instance), m_dir(dir)
|
: QAbstractListModel(), m_instance(instance), m_dir(dir)
|
||||||
{
|
{
|
||||||
FS::ensureFolderPathExists(m_dir.absolutePath());
|
FS::ensureFolderPathExists(m_dir.absolutePath());
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
IconFileRole
|
IconFileRole
|
||||||
};
|
};
|
||||||
|
|
||||||
WorldList(const QString &dir, std::shared_ptr<const BaseInstance> instance);
|
WorldList(const QString &dir, BaseInstance* instance);
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ signals:
|
|||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<const BaseInstance> m_instance;
|
BaseInstance* m_instance;
|
||||||
QFileSystemWatcher *m_watcher;
|
QFileSystemWatcher *m_watcher;
|
||||||
bool is_watching;
|
bool is_watching;
|
||||||
QDir m_dir;
|
QDir m_dir;
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
#include "minecraft/mod/tasks/ModFolderLoadTask.h"
|
#include "minecraft/mod/tasks/ModFolderLoadTask.h"
|
||||||
#include "modplatform/ModIndex.h"
|
#include "modplatform/ModIndex.h"
|
||||||
|
|
||||||
ModFolderModel::ModFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance, bool is_indexed, bool create_dir)
|
ModFolderModel::ModFolderModel(const QString& dir, BaseInstance* instance, bool is_indexed, bool create_dir)
|
||||||
: ResourceFolderModel(QDir(dir), instance, nullptr, create_dir), m_is_indexed(is_indexed)
|
: ResourceFolderModel(QDir(dir), instance, nullptr, create_dir), m_is_indexed(is_indexed)
|
||||||
{
|
{
|
||||||
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER };
|
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::VERSION, SortType::DATE, SortType::PROVIDER };
|
||||||
|
@ -75,7 +75,7 @@ public:
|
|||||||
Enable,
|
Enable,
|
||||||
Toggle
|
Toggle
|
||||||
};
|
};
|
||||||
ModFolderModel(const QString &dir, std::shared_ptr<const BaseInstance> instance, bool is_indexed = false, bool create_dir = true);
|
ModFolderModel(const QString &dir, BaseInstance* instance, bool is_indexed = false, bool create_dir = true);
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
ResourceFolderModel::ResourceFolderModel(QDir dir, std::shared_ptr<const BaseInstance> instance, QObject* parent, bool create_dir)
|
ResourceFolderModel::ResourceFolderModel(QDir dir, BaseInstance* instance, QObject* parent, bool create_dir)
|
||||||
: QAbstractListModel(parent), m_dir(dir), m_instance(instance), m_watcher(this)
|
: QAbstractListModel(parent), m_dir(dir), m_instance(instance), m_watcher(this)
|
||||||
{
|
{
|
||||||
if (create_dir) {
|
if (create_dir) {
|
||||||
|
@ -26,7 +26,7 @@ class QSortFilterProxyModel;
|
|||||||
class ResourceFolderModel : public QAbstractListModel {
|
class ResourceFolderModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ResourceFolderModel(QDir, std::shared_ptr<const BaseInstance>, QObject* parent = nullptr, bool create_dir = true);
|
ResourceFolderModel(QDir, BaseInstance* instance, QObject* parent = nullptr, bool create_dir = true);
|
||||||
~ResourceFolderModel() override;
|
~ResourceFolderModel() override;
|
||||||
|
|
||||||
/** Starts watching the paths for changes.
|
/** Starts watching the paths for changes.
|
||||||
@ -191,7 +191,7 @@ class ResourceFolderModel : public QAbstractListModel {
|
|||||||
bool m_can_interact = true;
|
bool m_can_interact = true;
|
||||||
|
|
||||||
QDir m_dir;
|
QDir m_dir;
|
||||||
std::shared_ptr<const BaseInstance> m_instance;
|
BaseInstance* m_instance;
|
||||||
QFileSystemWatcher m_watcher;
|
QFileSystemWatcher m_watcher;
|
||||||
bool m_is_watching = false;
|
bool m_is_watching = false;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
|
#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
|
||||||
#include "minecraft/mod/tasks/LocalResourcePackParseTask.h"
|
#include "minecraft/mod/tasks/LocalResourcePackParseTask.h"
|
||||||
|
|
||||||
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance)
|
ResourcePackFolderModel::ResourcePackFolderModel(const QString& dir, BaseInstance* instance)
|
||||||
: ResourceFolderModel(QDir(dir), instance)
|
: ResourceFolderModel(QDir(dir), instance)
|
||||||
{
|
{
|
||||||
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE };
|
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::PACK_FORMAT, SortType::DATE };
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
NUM_COLUMNS
|
NUM_COLUMNS
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ResourcePackFolderModel(const QString &dir, std::shared_ptr<const BaseInstance> instance);
|
explicit ResourcePackFolderModel(const QString &dir, BaseInstance* instance);
|
||||||
|
|
||||||
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ class ShaderPackFolderModel : public ResourceFolderModel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ShaderPackFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance)
|
explicit ShaderPackFolderModel(const QString& dir, BaseInstance* instance)
|
||||||
: ResourceFolderModel(QDir(dir), instance)
|
: ResourceFolderModel(QDir(dir), instance)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
|
#include "minecraft/mod/tasks/BasicFolderLoadTask.h"
|
||||||
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
|
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
|
||||||
|
|
||||||
TexturePackFolderModel::TexturePackFolderModel(const QString& dir, std::shared_ptr<const BaseInstance> instance)
|
TexturePackFolderModel::TexturePackFolderModel(const QString& dir, BaseInstance* instance)
|
||||||
: ResourceFolderModel(QDir(dir), instance)
|
: ResourceFolderModel(QDir(dir), instance)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class TexturePackFolderModel : public ResourceFolderModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TexturePackFolderModel(const QString &dir, std::shared_ptr<const BaseInstance> instance);
|
explicit TexturePackFolderModel(const QString &dir, BaseInstance* instance);
|
||||||
[[nodiscard]] Task* createUpdateTask() override;
|
[[nodiscard]] Task* createUpdateTask() override;
|
||||||
[[nodiscard]] Task* createParseTask(Resource&) override;
|
[[nodiscard]] Task* createParseTask(Resource&) override;
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class QIODevice;
|
class QIODevice;
|
||||||
|
|
||||||
@ -83,6 +84,8 @@ struct ExtraPackData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct IndexedPack {
|
struct IndexedPack {
|
||||||
|
using Ptr = std::shared_ptr<IndexedPack>;
|
||||||
|
|
||||||
QVariant addonId;
|
QVariant addonId;
|
||||||
ResourceProvider provider;
|
ResourceProvider provider;
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -35,7 +35,29 @@ void Flame::FileResolvingTask::executeTask()
|
|||||||
QByteArray data = Json::toText(object);
|
QByteArray data = Json::toText(object);
|
||||||
auto dl = Net::Upload::makeByteArray(QUrl("https://api.curseforge.com/v1/mods/files"), result.get(), data);
|
auto dl = Net::Upload::makeByteArray(QUrl("https://api.curseforge.com/v1/mods/files"), result.get(), data);
|
||||||
m_dljob->addNetAction(dl);
|
m_dljob->addNetAction(dl);
|
||||||
connect(m_dljob.get(), &NetJob::finished, this, &Flame::FileResolvingTask::netJobFinished);
|
|
||||||
|
auto step_progress = std::make_shared<TaskStepProgress>();
|
||||||
|
connect(m_dljob.get(), &NetJob::finished, this, [this, step_progress]() {
|
||||||
|
step_progress->state = TaskStepState::Succeeded;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
netJobFinished();
|
||||||
|
});
|
||||||
|
connect(m_dljob.get(), &NetJob::failed, this, [this, step_progress](QString reason) {
|
||||||
|
step_progress->state = TaskStepState::Failed;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
emitFailed(reason);
|
||||||
|
});
|
||||||
|
connect(m_dljob.get(), &NetJob::stepProgress, this, &FileResolvingTask::propogateStepProgress);
|
||||||
|
connect(m_dljob.get(), &NetJob::progress, this, [this, step_progress](qint64 current, qint64 total) {
|
||||||
|
qDebug() << "Resolve slug progress" << current << total;
|
||||||
|
step_progress->update(current, total);
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
});
|
||||||
|
connect(m_dljob.get(), &NetJob::status, this, [this, step_progress](QString status) {
|
||||||
|
step_progress->status = status;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
});
|
||||||
|
|
||||||
m_dljob->start();
|
m_dljob->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +66,7 @@ void Flame::FileResolvingTask::netJobFinished()
|
|||||||
setProgress(1, 3);
|
setProgress(1, 3);
|
||||||
// job to check modrinth for blocked projects
|
// job to check modrinth for blocked projects
|
||||||
m_checkJob.reset(new NetJob("Modrinth check", m_network));
|
m_checkJob.reset(new NetJob("Modrinth check", m_network));
|
||||||
blockedProjects = QMap<File *,QByteArray *>();
|
blockedProjects = QMap<File*, std::shared_ptr<QByteArray>>();
|
||||||
|
|
||||||
QJsonDocument doc;
|
QJsonDocument doc;
|
||||||
QJsonArray array;
|
QJsonArray array;
|
||||||
@ -71,8 +93,8 @@ void Flame::FileResolvingTask::netJobFinished()
|
|||||||
auto hash = out.hash;
|
auto hash = out.hash;
|
||||||
if(!hash.isEmpty()) {
|
if(!hash.isEmpty()) {
|
||||||
auto url = QString("https://api.modrinth.com/v2/version_file/%1?algorithm=sha1").arg(hash);
|
auto url = QString("https://api.modrinth.com/v2/version_file/%1?algorithm=sha1").arg(hash);
|
||||||
auto output = new QByteArray();
|
auto output = std::make_shared<QByteArray>();
|
||||||
auto dl = Net::Download::makeByteArray(QUrl(url), output);
|
auto dl = Net::Download::makeByteArray(QUrl(url), output.get());
|
||||||
QObject::connect(dl.get(), &Net::Download::succeeded, [&out]() {
|
QObject::connect(dl.get(), &Net::Download::succeeded, [&out]() {
|
||||||
out.resolved = true;
|
out.resolved = true;
|
||||||
});
|
});
|
||||||
@ -82,7 +104,27 @@ void Flame::FileResolvingTask::netJobFinished()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connect(m_checkJob.get(), &NetJob::finished, this, &Flame::FileResolvingTask::modrinthCheckFinished);
|
auto step_progress = std::make_shared<TaskStepProgress>();
|
||||||
|
connect(m_checkJob.get(), &NetJob::finished, this, [this, step_progress]() {
|
||||||
|
step_progress->state = TaskStepState::Succeeded;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
modrinthCheckFinished();
|
||||||
|
});
|
||||||
|
connect(m_checkJob.get(), &NetJob::failed, this, [this, step_progress](QString reason) {
|
||||||
|
step_progress->state = TaskStepState::Failed;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
emitFailed(reason);
|
||||||
|
});
|
||||||
|
connect(m_checkJob.get(), &NetJob::stepProgress, this, &FileResolvingTask::propogateStepProgress);
|
||||||
|
connect(m_checkJob.get(), &NetJob::progress, this, [this, step_progress](qint64 current, qint64 total) {
|
||||||
|
qDebug() << "Resolve slug progress" << current << total;
|
||||||
|
step_progress->update(current, total);
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
});
|
||||||
|
connect(m_checkJob.get(), &NetJob::status, this, [this, step_progress](QString status) {
|
||||||
|
step_progress->status = status;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
});
|
||||||
|
|
||||||
m_checkJob->start();
|
m_checkJob->start();
|
||||||
}
|
}
|
||||||
@ -95,7 +137,6 @@ void Flame::FileResolvingTask::modrinthCheckFinished() {
|
|||||||
auto &out = *it;
|
auto &out = *it;
|
||||||
auto bytes = blockedProjects[out];
|
auto bytes = blockedProjects[out];
|
||||||
if (!out->resolved) {
|
if (!out->resolved) {
|
||||||
delete bytes;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,11 +153,9 @@ void Flame::FileResolvingTask::modrinthCheckFinished() {
|
|||||||
} else {
|
} else {
|
||||||
out->resolved = false;
|
out->resolved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete bytes;
|
|
||||||
}
|
}
|
||||||
//copy to an output list and filter out projects found on modrinth
|
//copy to an output list and filter out projects found on modrinth
|
||||||
auto block = new QList<File *>();
|
auto block = std::make_shared<QList<File*>>();
|
||||||
auto it = blockedProjects.keys();
|
auto it = blockedProjects.keys();
|
||||||
std::copy_if(it.begin(), it.end(), std::back_inserter(*block), [](File *f) {
|
std::copy_if(it.begin(), it.end(), std::back_inserter(*block), [](File *f) {
|
||||||
return !f->resolved;
|
return !f->resolved;
|
||||||
@ -124,32 +163,48 @@ void Flame::FileResolvingTask::modrinthCheckFinished() {
|
|||||||
//Display not found mods early
|
//Display not found mods early
|
||||||
if (!block->empty()) {
|
if (!block->empty()) {
|
||||||
//blocked mods found, we need the slug for displaying.... we need another job :D !
|
//blocked mods found, we need the slug for displaying.... we need another job :D !
|
||||||
auto slugJob = new NetJob("Slug Job", m_network);
|
m_slugJob.reset(new NetJob("Slug Job", m_network));
|
||||||
auto slugs = QVector<QByteArray>(block->size());
|
int index = 0;
|
||||||
auto index = 0;
|
for (auto mod : *block) {
|
||||||
for (auto fileInfo: *block) {
|
auto projectId = mod->projectId;
|
||||||
auto projectId = fileInfo->projectId;
|
auto output = std::make_shared<QByteArray>();
|
||||||
slugs[index] = QByteArray();
|
|
||||||
auto url = QString("https://api.curseforge.com/v1/mods/%1").arg(projectId);
|
auto url = QString("https://api.curseforge.com/v1/mods/%1").arg(projectId);
|
||||||
auto dl = Net::Download::makeByteArray(url, &slugs[index]);
|
auto dl = Net::Download::makeByteArray(url, output.get());
|
||||||
slugJob->addNetAction(dl);
|
qDebug() << "Fetching url slug for file:" << mod->fileName;
|
||||||
index++;
|
QObject::connect(dl.get(), &Net::Download::succeeded, [block, index, output]() {
|
||||||
}
|
auto mod = block->at(index); // use the shared_ptr so it is captured and only freed when we are done
|
||||||
connect(slugJob, &NetJob::succeeded, this, [slugs, this, slugJob, block]() {
|
auto json = QJsonDocument::fromJson(*output);
|
||||||
slugJob->deleteLater();
|
|
||||||
auto index = 0;
|
|
||||||
for (const auto &slugResult: slugs) {
|
|
||||||
auto json = QJsonDocument::fromJson(slugResult);
|
|
||||||
auto base = Json::requireString(Json::requireObject(Json::requireObject(Json::requireObject(json),"data"),"links"),
|
auto base = Json::requireString(Json::requireObject(Json::requireObject(Json::requireObject(json),"data"),"links"),
|
||||||
"websiteUrl");
|
"websiteUrl");
|
||||||
auto mod = block->at(index);
|
|
||||||
auto link = QString("%1/download/%2").arg(base, QString::number(mod->fileId));
|
auto link = QString("%1/download/%2").arg(base, QString::number(mod->fileId));
|
||||||
mod->websiteUrl = link;
|
mod->websiteUrl = link;
|
||||||
|
});
|
||||||
|
m_slugJob->addNetAction(dl);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
auto step_progress = std::make_shared<TaskStepProgress>();
|
||||||
|
connect(m_slugJob.get(), &NetJob::succeeded, this, [this, step_progress]() {
|
||||||
|
step_progress->state = TaskStepState::Succeeded;
|
||||||
|
stepProgress(*step_progress);
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
});
|
});
|
||||||
slugJob->start();
|
connect(m_slugJob.get(), &NetJob::failed, this, [this, step_progress](QString reason) {
|
||||||
|
step_progress->state = TaskStepState::Failed;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
emitFailed(reason);
|
||||||
|
});
|
||||||
|
connect(m_slugJob.get(), &NetJob::stepProgress, this, &FileResolvingTask::propogateStepProgress);
|
||||||
|
connect(m_slugJob.get(), &NetJob::progress, this, [this, step_progress](qint64 current, qint64 total) {
|
||||||
|
qDebug() << "Resolve slug progress" << current << total;
|
||||||
|
step_progress->update(current, total);
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
});
|
||||||
|
connect(m_slugJob.get(), &NetJob::status, this, [this, step_progress](QString status) {
|
||||||
|
step_progress->status = status;
|
||||||
|
stepProgress(*step_progress);
|
||||||
|
});
|
||||||
|
|
||||||
|
m_slugJob->start();
|
||||||
} else {
|
} else {
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "tasks/Task.h"
|
|
||||||
#include "net/NetJob.h"
|
|
||||||
#include "PackManifest.h"
|
#include "PackManifest.h"
|
||||||
|
#include "net/NetJob.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
namespace Flame
|
namespace Flame {
|
||||||
{
|
class FileResolvingTask : public Task {
|
||||||
class FileResolvingTask : public Task
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FileResolvingTask(const shared_qobject_ptr<QNetworkAccessManager>& network, Flame::Manifest& toProcess);
|
explicit FileResolvingTask(const shared_qobject_ptr<QNetworkAccessManager>& network, Flame::Manifest& toProcess);
|
||||||
@ -16,10 +14,7 @@ public:
|
|||||||
bool canAbort() const override { return true; }
|
bool canAbort() const override { return true; }
|
||||||
bool abort() override;
|
bool abort() override;
|
||||||
|
|
||||||
const Flame::Manifest &getResults() const
|
const Flame::Manifest& getResults() const { return m_toProcess; }
|
||||||
{
|
|
||||||
return m_toProcess;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
@ -33,9 +28,10 @@ private: /* data */
|
|||||||
std::shared_ptr<QByteArray> result;
|
std::shared_ptr<QByteArray> result;
|
||||||
NetJob::Ptr m_dljob;
|
NetJob::Ptr m_dljob;
|
||||||
NetJob::Ptr m_checkJob;
|
NetJob::Ptr m_checkJob;
|
||||||
|
NetJob::Ptr m_slugJob;
|
||||||
|
|
||||||
void modrinthCheckFinished();
|
void modrinthCheckFinished();
|
||||||
|
|
||||||
QMap<File *, QByteArray *> blockedProjects;
|
QMap<File*, std::shared_ptr<QByteArray>> blockedProjects;
|
||||||
};
|
};
|
||||||
}
|
} // namespace Flame
|
||||||
|
@ -38,14 +38,14 @@ auto FlameAPI::getModFileChangelog(int modId, int fileId) -> QString
|
|||||||
QEventLoop lock;
|
QEventLoop lock;
|
||||||
QString changelog;
|
QString changelog;
|
||||||
|
|
||||||
auto* netJob = new NetJob(QString("Flame::FileChangelog"), APPLICATION->network());
|
auto netJob = makeShared<NetJob>(QString("Flame::FileChangelog"), APPLICATION->network());
|
||||||
auto* response = new QByteArray();
|
auto response = std::make_shared<QByteArray>();
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(
|
netJob->addNetAction(Net::Download::makeByteArray(
|
||||||
QString("https://api.curseforge.com/v1/mods/%1/files/%2/changelog")
|
QString("https://api.curseforge.com/v1/mods/%1/files/%2/changelog")
|
||||||
.arg(QString::fromStdString(std::to_string(modId)), QString::fromStdString(std::to_string(fileId))),
|
.arg(QString::fromStdString(std::to_string(modId)), QString::fromStdString(std::to_string(fileId))),
|
||||||
response));
|
response.get()));
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::succeeded, [netJob, response, &changelog] {
|
QObject::connect(netJob.get(), &NetJob::succeeded, [&netJob, response, &changelog] {
|
||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
@ -60,10 +60,7 @@ auto FlameAPI::getModFileChangelog(int modId, int fileId) -> QString
|
|||||||
changelog = Json::ensureString(doc.object(), "data");
|
changelog = Json::ensureString(doc.object(), "data");
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::finished, [response, &lock] {
|
QObject::connect(netJob.get(), &NetJob::finished, [&lock] { lock.quit(); });
|
||||||
delete response;
|
|
||||||
lock.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
netJob->start();
|
netJob->start();
|
||||||
lock.exec();
|
lock.exec();
|
||||||
@ -76,13 +73,12 @@ auto FlameAPI::getModDescription(int modId) -> QString
|
|||||||
QEventLoop lock;
|
QEventLoop lock;
|
||||||
QString description;
|
QString description;
|
||||||
|
|
||||||
auto* netJob = new NetJob(QString("Flame::ModDescription"), APPLICATION->network());
|
auto netJob = makeShared<NetJob>(QString("Flame::ModDescription"), APPLICATION->network());
|
||||||
auto* response = new QByteArray();
|
auto response = std::make_shared<QByteArray>();
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(
|
netJob->addNetAction(Net::Download::makeByteArray(
|
||||||
QString("https://api.curseforge.com/v1/mods/%1/description")
|
QString("https://api.curseforge.com/v1/mods/%1/description").arg(QString::number(modId)), response.get()));
|
||||||
.arg(QString::number(modId)), response));
|
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::succeeded, [netJob, response, &description] {
|
QObject::connect(netJob.get(), &NetJob::succeeded, [&netJob, response, &description] {
|
||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
@ -97,10 +93,7 @@ auto FlameAPI::getModDescription(int modId) -> QString
|
|||||||
description = Json::ensureString(doc.object(), "data");
|
description = Json::ensureString(doc.object(), "data");
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::finished, [response, &lock] {
|
QObject::connect(netJob.get(), &NetJob::finished, [&lock] { lock.quit(); });
|
||||||
delete response;
|
|
||||||
lock.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
netJob->start();
|
netJob->start();
|
||||||
lock.exec();
|
lock.exec();
|
||||||
@ -118,13 +111,13 @@ auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::Indexe
|
|||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
||||||
auto netJob = new NetJob(QString("Flame::GetLatestVersion(%1)").arg(args.pack.name), APPLICATION->network());
|
auto netJob = makeShared<NetJob>(QString("Flame::GetLatestVersion(%1)").arg(args.pack.name), APPLICATION->network());
|
||||||
auto response = new QByteArray();
|
auto response = std::make_shared<QByteArray>();
|
||||||
ModPlatform::IndexedVersion ver;
|
ModPlatform::IndexedVersion ver;
|
||||||
|
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(versions_url, response));
|
netJob->addNetAction(Net::Download::makeByteArray(versions_url, response.get()));
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::succeeded, [response, args, &ver] {
|
QObject::connect(netJob.get(), &NetJob::succeeded, [response, args, &ver] {
|
||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
@ -158,11 +151,7 @@ auto FlameAPI::getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::Indexe
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(netJob, &NetJob::finished, [response, netJob, &loop] {
|
QObject::connect(netJob.get(), &NetJob::finished, [&loop] { loop.quit(); });
|
||||||
netJob->deleteLater();
|
|
||||||
delete response;
|
|
||||||
loop.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
netJob->start();
|
netJob->start();
|
||||||
|
|
||||||
|
@ -384,6 +384,7 @@ bool FlameCreationTask::createInstance()
|
|||||||
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::progress, this, &FlameCreationTask::setProgress);
|
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::progress, this, &FlameCreationTask::setProgress);
|
||||||
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::status, this, &FlameCreationTask::setStatus);
|
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::status, this, &FlameCreationTask::setStatus);
|
||||||
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::stepProgress, this, &FlameCreationTask::propogateStepProgress);
|
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::stepProgress, this, &FlameCreationTask::propogateStepProgress);
|
||||||
|
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::details, this, &FlameCreationTask::setDetails);
|
||||||
m_mod_id_resolver->start();
|
m_mod_id_resolver->start();
|
||||||
|
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
@ -24,7 +24,7 @@ Task::Ptr NetworkResourceAPI::searchProjects(SearchArgs&& args, SearchCallbacks&
|
|||||||
|
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(QUrl(search_url), response));
|
netJob->addNetAction(Net::Download::makeByteArray(QUrl(search_url), response));
|
||||||
|
|
||||||
QObject::connect(netJob.get(), &NetJob::succeeded, [=]{
|
QObject::connect(netJob.get(), &NetJob::succeeded, [this, response, callbacks]{
|
||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
@ -40,16 +40,20 @@ Task::Ptr NetworkResourceAPI::searchProjects(SearchArgs&& args, SearchCallbacks&
|
|||||||
callbacks.on_succeed(doc);
|
callbacks.on_succeed(doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(netJob.get(), &NetJob::failed, [=](QString reason){
|
QObject::connect(netJob.get(), &NetJob::failed, [&netJob, callbacks](QString reason){
|
||||||
int network_error_code = -1;
|
int network_error_code = -1;
|
||||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action && failed_action->m_reply)
|
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action && failed_action->m_reply)
|
||||||
network_error_code = failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
network_error_code = failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
||||||
callbacks.on_fail(reason, network_error_code);
|
callbacks.on_fail(reason, network_error_code);
|
||||||
});
|
});
|
||||||
QObject::connect(netJob.get(), &NetJob::aborted, [=]{
|
QObject::connect(netJob.get(), &NetJob::aborted, [callbacks]{
|
||||||
callbacks.on_abort();
|
callbacks.on_abort();
|
||||||
});
|
});
|
||||||
|
QObject::connect(netJob.get(), &NetJob::finished, [response] {
|
||||||
|
delete response;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return netJob;
|
return netJob;
|
||||||
}
|
}
|
||||||
@ -88,7 +92,7 @@ Task::Ptr NetworkResourceAPI::getProjectVersions(VersionSearchArgs&& args, Versi
|
|||||||
|
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(versions_url, response));
|
netJob->addNetAction(Net::Download::makeByteArray(versions_url, response));
|
||||||
|
|
||||||
QObject::connect(netJob.get(), &NetJob::succeeded, [=] {
|
QObject::connect(netJob.get(), &NetJob::succeeded, [response, callbacks, args] {
|
||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
|
@ -134,11 +134,14 @@ void Download::executeTask()
|
|||||||
request.setRawHeader("Authorization", token.toUtf8());
|
request.setRawHeader("Authorization", token.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||||
|
request.setTransferTimeout();
|
||||||
|
#endif
|
||||||
|
|
||||||
m_last_progress_time = m_clock.now();
|
m_last_progress_time = m_clock.now();
|
||||||
m_last_progress_bytes = 0;
|
m_last_progress_bytes = 0;
|
||||||
|
|
||||||
QNetworkReply* rep = m_network->get(request);
|
QNetworkReply* rep = m_network->get(request);
|
||||||
|
|
||||||
m_reply.reset(rep);
|
m_reply.reset(rep);
|
||||||
connect(rep, &QNetworkReply::downloadProgress, this, &Download::downloadProgress);
|
connect(rep, &QNetworkReply::downloadProgress, this, &Download::downloadProgress);
|
||||||
connect(rep, &QNetworkReply::finished, this, &Download::downloadFinished);
|
connect(rep, &QNetworkReply::finished, this, &Download::downloadFinished);
|
||||||
|
@ -138,7 +138,7 @@ void ConcurrentTask::startNext()
|
|||||||
connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); });
|
connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); });
|
||||||
|
|
||||||
m_doing.insert(next.get(), next);
|
m_doing.insert(next.get(), next);
|
||||||
auto task_progress = std::make_shared<TaskStepProgress>(TaskStepProgress({ next->getUid() }));
|
auto task_progress = std::make_shared<TaskStepProgress>(next->getUid());
|
||||||
m_task_progress.insert(next->getUid(), task_progress);
|
m_task_progress.insert(next->getUid(), task_progress);
|
||||||
|
|
||||||
updateState();
|
updateState();
|
||||||
@ -166,9 +166,9 @@ void ConcurrentTask::subTaskSucceeded(Task::Ptr task)
|
|||||||
|
|
||||||
disconnect(task.get(), 0, this, 0);
|
disconnect(task.get(), 0, this, 0);
|
||||||
|
|
||||||
emit stepProgress(*task_progress.get());
|
emit stepProgress(*task_progress);
|
||||||
updateState();
|
updateState();
|
||||||
updateStepProgress(*task_progress.get(), Operation::REMOVED);
|
updateStepProgress(*task_progress, Operation::REMOVED);
|
||||||
startNext();
|
startNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,9 +184,9 @@ void ConcurrentTask::subTaskFailed(Task::Ptr task, const QString& msg)
|
|||||||
|
|
||||||
disconnect(task.get(), 0, this, 0);
|
disconnect(task.get(), 0, this, 0);
|
||||||
|
|
||||||
emit stepProgress(*task_progress.get());
|
emit stepProgress(*task_progress);
|
||||||
updateState();
|
updateState();
|
||||||
updateStepProgress(*task_progress.get(), Operation::REMOVED);
|
updateStepProgress(*task_progress, Operation::REMOVED);
|
||||||
startNext();
|
startNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ void ConcurrentTask::subTaskStatus(Task::Ptr task, const QString& msg)
|
|||||||
task_progress->status = msg;
|
task_progress->status = msg;
|
||||||
task_progress->state = TaskStepState::Running;
|
task_progress->state = TaskStepState::Running;
|
||||||
|
|
||||||
emit stepProgress(*task_progress.get());
|
emit stepProgress(*task_progress);
|
||||||
|
|
||||||
if (totalSize() == 1) {
|
if (totalSize() == 1) {
|
||||||
setStatus(msg);
|
setStatus(msg);
|
||||||
@ -209,7 +209,7 @@ void ConcurrentTask::subTaskDetails(Task::Ptr task, const QString& msg)
|
|||||||
task_progress->details = msg;
|
task_progress->details = msg;
|
||||||
task_progress->state = TaskStepState::Running;
|
task_progress->state = TaskStepState::Running;
|
||||||
|
|
||||||
emit stepProgress(*task_progress.get());
|
emit stepProgress(*task_progress);
|
||||||
|
|
||||||
if (totalSize() == 1) {
|
if (totalSize() == 1) {
|
||||||
setDetails(msg);
|
setDetails(msg);
|
||||||
@ -220,15 +220,10 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota
|
|||||||
{
|
{
|
||||||
auto task_progress = m_task_progress.value(task->getUid());
|
auto task_progress = m_task_progress.value(task->getUid());
|
||||||
|
|
||||||
task_progress->old_current = task_progress->current;
|
task_progress->update(current, total);
|
||||||
task_progress->old_total = task_progress->old_total;
|
|
||||||
|
|
||||||
task_progress->current = current;
|
emit stepProgress(*task_progress);
|
||||||
task_progress->total = total;
|
updateStepProgress(*task_progress, Operation::CHANGED);
|
||||||
task_progress->state = TaskStepState::Running;
|
|
||||||
|
|
||||||
emit stepProgress(*task_progress.get());
|
|
||||||
updateStepProgress(*task_progress.get(), Operation::CHANGED);
|
|
||||||
updateState();
|
updateState();
|
||||||
|
|
||||||
if (totalSize() == 1) {
|
if (totalSize() == 1) {
|
||||||
|
@ -109,7 +109,7 @@ void Task::start()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NOTE: only fall thorugh to here in end states
|
// NOTE: only fall through to here in end states
|
||||||
m_state = State::Running;
|
m_state = State::Running;
|
||||||
emit started();
|
emit started();
|
||||||
executeTask();
|
executeTask();
|
||||||
|
@ -64,7 +64,21 @@ struct TaskStepProgress {
|
|||||||
QString status = "";
|
QString status = "";
|
||||||
QString details = "";
|
QString details = "";
|
||||||
TaskStepState state = TaskStepState::Waiting;
|
TaskStepState state = TaskStepState::Waiting;
|
||||||
|
TaskStepProgress() {
|
||||||
|
this->uid = QUuid::createUuid();
|
||||||
|
}
|
||||||
|
TaskStepProgress(QUuid uid) {
|
||||||
|
this->uid = uid;
|
||||||
|
}
|
||||||
bool isDone() const { return (state == TaskStepState::Failed) || (state == TaskStepState::Succeeded); }
|
bool isDone() const { return (state == TaskStepState::Failed) || (state == TaskStepState::Succeeded); }
|
||||||
|
void update(qint64 current, qint64 total) {
|
||||||
|
this->old_current = this->current;
|
||||||
|
this->old_total = this->total;
|
||||||
|
|
||||||
|
this->current = current;
|
||||||
|
this->total = total;
|
||||||
|
this->state = TaskStepState::Running;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(TaskStepProgress)
|
Q_DECLARE_METATYPE(TaskStepProgress)
|
||||||
|
@ -99,7 +99,7 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString
|
|||||||
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below.
|
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below.
|
||||||
m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
m_container = new PageContainer(this);
|
m_container = new PageContainer(this, {}, this);
|
||||||
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
|
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
|
||||||
m_container->layout()->setContentsMargins(0, 0, 0, 0);
|
m_container->layout()->setContentsMargins(0, 0, 0, 0);
|
||||||
ui->verticalLayout->insertWidget(2, m_container);
|
ui->verticalLayout->insertWidget(2, m_container);
|
||||||
|
@ -89,7 +89,7 @@ void ResourceDownloadDialog::reject()
|
|||||||
// won't work with subclasses if we put it in this ctor.
|
// won't work with subclasses if we put it in this ctor.
|
||||||
void ResourceDownloadDialog::initializeContainer()
|
void ResourceDownloadDialog::initializeContainer()
|
||||||
{
|
{
|
||||||
m_container = new PageContainer(this);
|
m_container = new PageContainer(this, {}, this);
|
||||||
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
|
m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
|
||||||
m_container->layout()->setContentsMargins(0, 0, 0, 0);
|
m_container->layout()->setContentsMargins(0, 0, 0, 0);
|
||||||
m_vertical_layout.addWidget(m_container);
|
m_vertical_layout.addWidget(m_container);
|
||||||
|
@ -30,8 +30,6 @@ class NoBigComboBoxStyle : public QProxyStyle {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {}
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
int styleHint(QStyle::StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override
|
int styleHint(QStyle::StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override
|
||||||
{
|
{
|
||||||
@ -41,6 +39,37 @@ class NoBigComboBoxStyle : public QProxyStyle {
|
|||||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||||
}
|
}
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Something about QProxyStyle and QStyle objects means they can't be free'd just
|
||||||
|
* because all the widgets using them are gone.
|
||||||
|
* They seems to be tied to the QApplicaiton lifecycle.
|
||||||
|
* So make singletons tied to the lifetime of the application to clean them up and ensure they aren't
|
||||||
|
* being remade over and over again, thus leaking memory.
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
static NoBigComboBoxStyle* getInstance(QStyle* style)
|
||||||
|
{
|
||||||
|
static QHash<QStyle*, NoBigComboBoxStyle*> s_singleton_instances_ = {};
|
||||||
|
static std::mutex s_singleton_instances_mutex_;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(s_singleton_instances_mutex_);
|
||||||
|
auto inst_iter = s_singleton_instances_.constFind(style);
|
||||||
|
NoBigComboBoxStyle* inst = nullptr;
|
||||||
|
if (inst_iter == s_singleton_instances_.constEnd() || *inst_iter == nullptr) {
|
||||||
|
inst = new NoBigComboBoxStyle(style);
|
||||||
|
inst->setParent(APPLICATION);
|
||||||
|
s_singleton_instances_.insert(style, inst);
|
||||||
|
qDebug() << "QProxyStyle NoBigComboBox created for" << style->objectName() << style;
|
||||||
|
} else {
|
||||||
|
inst = *inst_iter;
|
||||||
|
}
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
NoBigComboBoxStyle(QStyle* style) : QProxyStyle(style) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent)
|
ManagedPackPage* ManagedPackPage::createPage(BaseInstance* inst, QString type, QWidget* parent)
|
||||||
@ -62,8 +91,10 @@ ManagedPackPage::ManagedPackPage(BaseInstance* inst, InstanceWindow* instance_wi
|
|||||||
|
|
||||||
// NOTE: GTK2 themes crash with the proxy style.
|
// NOTE: GTK2 themes crash with the proxy style.
|
||||||
// This seems like an upstream bug, so there's not much else that can be done.
|
// This seems like an upstream bug, so there's not much else that can be done.
|
||||||
if (!QStyleFactory::keys().contains("gtk2"))
|
if (!QStyleFactory::keys().contains("gtk2")){
|
||||||
ui->versionsComboBox->setStyle(new NoBigComboBoxStyle(ui->versionsComboBox->style()));
|
auto comboStyle = NoBigComboBoxStyle::getInstance(ui->versionsComboBox->style());
|
||||||
|
ui->versionsComboBox->setStyle(comboStyle);
|
||||||
|
}
|
||||||
|
|
||||||
ui->reloadButton->setVisible(false);
|
ui->reloadButton->setVisible(false);
|
||||||
connect(ui->reloadButton, &QPushButton::clicked, this, [this](bool){
|
connect(ui->reloadButton, &QPushButton::clicked, this, [this](bool){
|
||||||
|
@ -165,7 +165,7 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent)
|
|||||||
auto proxy = new IconProxy(ui->packageView);
|
auto proxy = new IconProxy(ui->packageView);
|
||||||
proxy->setSourceModel(m_profile.get());
|
proxy->setSourceModel(m_profile.get());
|
||||||
|
|
||||||
m_filterModel = new QSortFilterProxyModel();
|
m_filterModel = new QSortFilterProxyModel(this);
|
||||||
m_filterModel->setDynamicSortFilter(true);
|
m_filterModel->setDynamicSortFilter(true);
|
||||||
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
@ -36,7 +36,7 @@ ResourceAPI::SearchArgs ModModel::createSearchArguments()
|
|||||||
|
|
||||||
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = *m_packs[entry.row()];
|
||||||
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
auto profile = static_cast<MinecraftInstance const&>(m_base_instance).getPackProfile();
|
||||||
|
|
||||||
Q_ASSERT(profile);
|
Q_ASSERT(profile);
|
||||||
@ -51,7 +51,7 @@ ResourceAPI::VersionSearchArgs ModModel::createVersionsArguments(QModelIndex& en
|
|||||||
|
|
||||||
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
|
ResourceAPI::ProjectInfoArgs ModModel::createInfoArguments(QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = *m_packs[entry.row()];
|
||||||
return { pack };
|
return { pack };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,6 @@ class ModPage : public ResourcePage {
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ModPage() override = default;
|
|
||||||
|
|
||||||
//: The plural version of 'mod'
|
//: The plural version of 'mod'
|
||||||
[[nodiscard]] inline QString resourcesString() const override { return tr("mods"); }
|
[[nodiscard]] inline QString resourcesString() const override { return tr("mods"); }
|
||||||
//: The singular version of 'mods'
|
//: The singular version of 'mods'
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
@ -45,16 +46,16 @@ auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
|
|||||||
auto pack = m_packs.at(pos);
|
auto pack = m_packs.at(pos);
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::ToolTipRole: {
|
case Qt::ToolTipRole: {
|
||||||
if (pack.description.length() > 100) {
|
if (pack->description.length() > 100) {
|
||||||
// some magic to prevent to long tooltips and replace html linebreaks
|
// some magic to prevent to long tooltips and replace html linebreaks
|
||||||
QString edit = pack.description.left(97);
|
QString edit = pack->description.left(97);
|
||||||
edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
|
edit = edit.left(edit.lastIndexOf("<br>")).left(edit.lastIndexOf(" ")).append("...");
|
||||||
return edit;
|
return edit;
|
||||||
}
|
}
|
||||||
return pack.description;
|
return pack->description;
|
||||||
}
|
}
|
||||||
case Qt::DecorationRole: {
|
case Qt::DecorationRole: {
|
||||||
if (auto icon_or_none = const_cast<ResourceModel*>(this)->getIcon(const_cast<QModelIndex&>(index), pack.logoUrl);
|
if (auto icon_or_none = const_cast<ResourceModel*>(this)->getIcon(const_cast<QModelIndex&>(index), pack->logoUrl);
|
||||||
icon_or_none.has_value())
|
icon_or_none.has_value())
|
||||||
return icon_or_none.value();
|
return icon_or_none.value();
|
||||||
|
|
||||||
@ -64,16 +65,16 @@ auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
|
|||||||
return QSize(0, 58);
|
return QSize(0, 58);
|
||||||
case Qt::UserRole: {
|
case Qt::UserRole: {
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v.setValue(pack);
|
v.setValue(*pack);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
// Custom data
|
// Custom data
|
||||||
case UserDataTypes::TITLE:
|
case UserDataTypes::TITLE:
|
||||||
return pack.name;
|
return pack->name;
|
||||||
case UserDataTypes::DESCRIPTION:
|
case UserDataTypes::DESCRIPTION:
|
||||||
return pack.description;
|
return pack->description;
|
||||||
case UserDataTypes::SELECTED:
|
case UserDataTypes::SELECTED:
|
||||||
return pack.isAnyVersionSelected();
|
return pack->isAnyVersionSelected();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -102,7 +103,7 @@ bool ResourceModel::setData(const QModelIndex& index, const QVariant& value, int
|
|||||||
if (pos >= m_packs.size() || pos < 0 || !index.isValid())
|
if (pos >= m_packs.size() || pos < 0 || !index.isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_packs[pos] = value.value<ModPlatform::IndexedPack>();
|
m_packs[pos] = std::make_shared<ModPlatform::IndexedPack>(value.value<ModPlatform::IndexedPack>());
|
||||||
emit dataChanged(index, index);
|
emit dataChanged(index, index);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -161,7 +162,7 @@ void ResourceModel::loadEntry(QModelIndex& entry)
|
|||||||
if (!hasActiveInfoJob())
|
if (!hasActiveInfoJob())
|
||||||
m_current_info_job.clear();
|
m_current_info_job.clear();
|
||||||
|
|
||||||
if (!pack.versionsLoaded) {
|
if (!pack->versionsLoaded) {
|
||||||
auto args{ createVersionsArguments(entry) };
|
auto args{ createVersionsArguments(entry) };
|
||||||
auto callbacks{ createVersionsCallbacks(entry) };
|
auto callbacks{ createVersionsCallbacks(entry) };
|
||||||
|
|
||||||
@ -177,7 +178,7 @@ void ResourceModel::loadEntry(QModelIndex& entry)
|
|||||||
runInfoJob(job);
|
runInfoJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pack.extraDataLoaded) {
|
if (!pack->extraDataLoaded) {
|
||||||
auto args{ createInfoArguments(entry) };
|
auto args{ createInfoArguments(entry) };
|
||||||
auto callbacks{ createInfoCallbacks(entry) };
|
auto callbacks{ createInfoCallbacks(entry) };
|
||||||
|
|
||||||
@ -229,7 +230,7 @@ void ResourceModel::clearData()
|
|||||||
|
|
||||||
void ResourceModel::runSearchJob(Task::Ptr ptr)
|
void ResourceModel::runSearchJob(Task::Ptr ptr)
|
||||||
{
|
{
|
||||||
m_current_search_job = ptr;
|
m_current_search_job.reset(ptr); // clean up first
|
||||||
m_current_search_job->start();
|
m_current_search_job->start();
|
||||||
}
|
}
|
||||||
void ResourceModel::runInfoJob(Task::Ptr ptr)
|
void ResourceModel::runInfoJob(Task::Ptr ptr)
|
||||||
@ -326,15 +327,15 @@ void ResourceModel::loadIndexedPackVersions(ModPlatform::IndexedPack&, QJsonArra
|
|||||||
|
|
||||||
void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
|
void ResourceModel::searchRequestSucceeded(QJsonDocument& doc)
|
||||||
{
|
{
|
||||||
QList<ModPlatform::IndexedPack> newList;
|
QList<ModPlatform::IndexedPack::Ptr> newList;
|
||||||
auto packs = documentToArray(doc);
|
auto packs = documentToArray(doc);
|
||||||
|
|
||||||
for (auto packRaw : packs) {
|
for (auto packRaw : packs) {
|
||||||
auto packObj = packRaw.toObject();
|
auto packObj = packRaw.toObject();
|
||||||
|
|
||||||
ModPlatform::IndexedPack pack;
|
ModPlatform::IndexedPack::Ptr pack = std::make_shared<ModPlatform::IndexedPack>();
|
||||||
try {
|
try {
|
||||||
loadIndexedPack(pack, packObj);
|
loadIndexedPack(*pack, packObj);
|
||||||
newList.append(pack);
|
newList.append(pack);
|
||||||
} catch (const JSONValidationError& e) {
|
} catch (const JSONValidationError& e) {
|
||||||
qWarning() << "Error while loading resource from " << debugName() << ": " << e.cause();
|
qWarning() << "Error while loading resource from " << debugName() << ": " << e.cause();
|
||||||
|
@ -123,7 +123,7 @@ class ResourceModel : public QAbstractListModel {
|
|||||||
QSet<QUrl> m_currently_running_icon_actions;
|
QSet<QUrl> m_currently_running_icon_actions;
|
||||||
QSet<QUrl> m_failed_icon_actions;
|
QSet<QUrl> m_failed_icon_actions;
|
||||||
|
|
||||||
QList<ModPlatform::IndexedPack> m_packs;
|
QList<ModPlatform::IndexedPack::Ptr> m_packs;
|
||||||
|
|
||||||
// HACK: We need this to prevent callbacks from calling the model after it has already been deleted.
|
// HACK: We need this to prevent callbacks from calling the model after it has already been deleted.
|
||||||
// This leaks a tiny bit of memory per time the user has opened a resource dialog. How to make this better?
|
// This leaks a tiny bit of memory per time the user has opened a resource dialog. How to make this better?
|
||||||
|
@ -22,13 +22,13 @@ ResourceAPI::SearchArgs ResourcePackResourceModel::createSearchArguments()
|
|||||||
ResourceAPI::VersionSearchArgs ResourcePackResourceModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs ResourcePackResourceModel::createVersionsArguments(QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { pack };
|
return { *pack };
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::ProjectInfoArgs ResourcePackResourceModel::createInfoArguments(QModelIndex& entry)
|
ResourceAPI::ProjectInfoArgs ResourcePackResourceModel::createInfoArguments(QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { pack };
|
return { *pack };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
|
void ResourcePackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
|
||||||
|
@ -31,8 +31,6 @@ class ResourcePackResourcePage : public ResourcePage {
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ResourcePackResourcePage() override = default;
|
|
||||||
|
|
||||||
//: The plural version of 'resource pack'
|
//: The plural version of 'resource pack'
|
||||||
[[nodiscard]] inline QString resourcesString() const override { return tr("resource packs"); }
|
[[nodiscard]] inline QString resourcesString() const override { return tr("resource packs"); }
|
||||||
//: The singular version of 'resource packs'
|
//: The singular version of 'resource packs'
|
||||||
|
@ -83,6 +83,8 @@ ResourcePage::ResourcePage(ResourceDownloadDialog* parent, BaseInstance& base_in
|
|||||||
ResourcePage::~ResourcePage()
|
ResourcePage::~ResourcePage()
|
||||||
{
|
{
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
|
if (m_model)
|
||||||
|
delete m_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcePage::retranslate()
|
void ResourcePage::retranslate()
|
||||||
|
@ -22,13 +22,13 @@ ResourceAPI::SearchArgs ShaderPackResourceModel::createSearchArguments()
|
|||||||
ResourceAPI::VersionSearchArgs ShaderPackResourceModel::createVersionsArguments(QModelIndex& entry)
|
ResourceAPI::VersionSearchArgs ShaderPackResourceModel::createVersionsArguments(QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { pack };
|
return { *pack };
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceAPI::ProjectInfoArgs ShaderPackResourceModel::createInfoArguments(QModelIndex& entry)
|
ResourceAPI::ProjectInfoArgs ShaderPackResourceModel::createInfoArguments(QModelIndex& entry)
|
||||||
{
|
{
|
||||||
auto& pack = m_packs[entry.row()];
|
auto& pack = m_packs[entry.row()];
|
||||||
return { pack };
|
return { *pack };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderPackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
|
void ShaderPackResourceModel::searchWithTerm(const QString& term, unsigned int sort)
|
||||||
|
@ -31,8 +31,6 @@ class ShaderPackResourcePage : public ResourcePage {
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ShaderPackResourcePage() override = default;
|
|
||||||
|
|
||||||
//: The plural version of 'shader pack'
|
//: The plural version of 'shader pack'
|
||||||
[[nodiscard]] inline QString resourcesString() const override { return tr("shader packs"); }
|
[[nodiscard]] inline QString resourcesString() const override { return tr("shader packs"); }
|
||||||
//: The singular version of 'shader packs'
|
//: The singular version of 'shader packs'
|
||||||
|
@ -87,7 +87,9 @@ PageContainer::PageContainer(BasePageProvider *pageProvider, QString defaultId,
|
|||||||
auto pages = pageProvider->getPages();
|
auto pages = pageProvider->getPages();
|
||||||
for (auto page : pages)
|
for (auto page : pages)
|
||||||
{
|
{
|
||||||
page->stackIndex = m_pageStack->addWidget(dynamic_cast<QWidget *>(page));
|
auto widget = dynamic_cast<QWidget *>(page);
|
||||||
|
widget->setParent(this);
|
||||||
|
page->stackIndex = m_pageStack->addWidget(widget);
|
||||||
page->listIndex = counter;
|
page->listIndex = counter;
|
||||||
page->setParentContainer(this);
|
page->setParentContainer(this);
|
||||||
counter++;
|
counter++;
|
||||||
|
@ -40,6 +40,8 @@ void ReplyList::remove(QNetworkReply *reply) {
|
|||||||
if (o2Reply) {
|
if (o2Reply) {
|
||||||
o2Reply->stop();
|
o2Reply->stop();
|
||||||
(void)replies_.removeOne(o2Reply);
|
(void)replies_.removeOne(o2Reply);
|
||||||
|
// we took ownership, we must free
|
||||||
|
delete o2Reply;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +90,7 @@ slots:
|
|||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
||||||
InstancePtr instance;
|
ModFolderModel m(tempDir.path(), nullptr, true);
|
||||||
|
|
||||||
ModFolderModel m(tempDir.path(), instance, true);
|
|
||||||
|
|
||||||
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
||||||
|
|
||||||
@ -116,8 +114,7 @@ slots:
|
|||||||
QString folder = source + '/';
|
QString folder = source + '/';
|
||||||
QTemporaryDir tempDir;
|
QTemporaryDir tempDir;
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
InstancePtr instance;
|
ModFolderModel m(tempDir.path(), nullptr, true);
|
||||||
ModFolderModel m(tempDir.path(), instance, true);
|
|
||||||
|
|
||||||
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
connect(&m, &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
||||||
|
|
||||||
@ -140,8 +137,7 @@ slots:
|
|||||||
void test_addFromWatch()
|
void test_addFromWatch()
|
||||||
{
|
{
|
||||||
QString source = QFINDTESTDATA("testdata/ResourceFolderModel");
|
QString source = QFINDTESTDATA("testdata/ResourceFolderModel");
|
||||||
InstancePtr instance;
|
ModFolderModel model(source, nullptr);
|
||||||
ModFolderModel model(source, instance);
|
|
||||||
|
|
||||||
QCOMPARE(model.size(), 0);
|
QCOMPARE(model.size(), 0);
|
||||||
|
|
||||||
@ -161,9 +157,7 @@ slots:
|
|||||||
QString file_mod = QFINDTESTDATA("testdata/ResourceFolderModel/supercoolmod.jar");
|
QString file_mod = QFINDTESTDATA("testdata/ResourceFolderModel/supercoolmod.jar");
|
||||||
|
|
||||||
QTemporaryDir tmp;
|
QTemporaryDir tmp;
|
||||||
InstancePtr instance;
|
ResourceFolderModel model(QDir(tmp.path()), nullptr);
|
||||||
|
|
||||||
ResourceFolderModel model(QDir(tmp.path()), instance);
|
|
||||||
|
|
||||||
QCOMPARE(model.size(), 0);
|
QCOMPARE(model.size(), 0);
|
||||||
|
|
||||||
@ -214,8 +208,7 @@ slots:
|
|||||||
QString file_mod = QFINDTESTDATA("testdata/ResourceFolderModel/supercoolmod.jar");
|
QString file_mod = QFINDTESTDATA("testdata/ResourceFolderModel/supercoolmod.jar");
|
||||||
|
|
||||||
QTemporaryDir tmp;
|
QTemporaryDir tmp;
|
||||||
InstancePtr instance;
|
ResourceFolderModel model(tmp.path(), nullptr);
|
||||||
ResourceFolderModel model(tmp.path(), instance);
|
|
||||||
|
|
||||||
QCOMPARE(model.size(), 0);
|
QCOMPARE(model.size(), 0);
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ class ResourceModelTest : public QObject {
|
|||||||
auto search_json = DummyResourceAPI::searchRequestResult();
|
auto search_json = DummyResourceAPI::searchRequestResult();
|
||||||
auto processed_response = model->documentToArray(search_json).first().toObject();
|
auto processed_response = model->documentToArray(search_json).first().toObject();
|
||||||
|
|
||||||
QVERIFY(processed_pack.addonId.toString() == Json::requireString(processed_response, "project_id"));
|
QVERIFY(processed_pack->addonId.toString() == Json::requireString(processed_response, "project_id"));
|
||||||
QVERIFY(processed_pack.description == Json::requireString(processed_response, "description"));
|
QVERIFY(processed_pack->description == Json::requireString(processed_response, "description"));
|
||||||
QVERIFY(processed_pack.authors.first().name == Json::requireString(processed_response, "author"));
|
QVERIFY(processed_pack->authors.first().name == Json::requireString(processed_response, "author"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user