summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2018-03-19 02:36:12 +0100
committerPetr Mrázek <peterix@gmail.com>2018-03-27 09:25:36 +0200
commit8e44ab2338f4ca63d58de4b3329c384df9d6c053 (patch)
tree60b915ec620221656d1c3a42f40124b15e9e69f0 /api
parent4c7ea0f99a23f73fd3cae87f7dfaab89922a2311 (diff)
downloadMultiMC-8e44ab2338f4ca63d58de4b3329c384df9d6c053.tar
MultiMC-8e44ab2338f4ca63d58de4b3329c384df9d6c053.tar.gz
MultiMC-8e44ab2338f4ca63d58de4b3329c384df9d6c053.tar.lz
MultiMC-8e44ab2338f4ca63d58de4b3329c384df9d6c053.tar.xz
MultiMC-8e44ab2338f4ca63d58de4b3329c384df9d6c053.zip
NOISSUE redo new instance dialog
Diffstat (limited to 'api')
-rw-r--r--api/logic/CMakeLists.txt20
-rw-r--r--api/logic/Filter.cpp31
-rw-r--r--api/logic/Filter.h44
-rw-r--r--api/logic/FolderInstanceProvider.cpp43
-rw-r--r--api/logic/FolderInstanceProvider.h7
-rw-r--r--api/logic/InstanceCopyTask.cpp7
-rw-r--r--api/logic/InstanceCopyTask.h14
-rw-r--r--api/logic/InstanceCreationTask.cpp8
-rw-r--r--api/logic/InstanceCreationTask.h12
-rw-r--r--api/logic/InstanceImportTask.cpp8
-rw-r--r--api/logic/InstanceImportTask.h12
-rw-r--r--api/logic/InstanceTask.cpp9
-rw-r--r--api/logic/InstanceTask.h55
-rw-r--r--api/logic/minecraft/legacy/LegacyUpgradeTask.cpp7
-rw-r--r--api/logic/minecraft/legacy/LegacyUpgradeTask.h12
-rw-r--r--api/logic/modplatform/ftb/FtbPackDownloader.cpp84
-rw-r--r--api/logic/modplatform/ftb/FtbPackDownloader.h49
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.cpp2
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.h2
-rw-r--r--api/logic/modplatform/ftb/FtbPackInstallTask.cpp96
-rw-r--r--api/logic/modplatform/ftb/FtbPackInstallTask.h42
-rw-r--r--api/logic/modplatform/ftb/PackHelpers.h4
22 files changed, 292 insertions, 276 deletions
diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt
index e40f188e..c6daef6f 100644
--- a/api/logic/CMakeLists.txt
+++ b/api/logic/CMakeLists.txt
@@ -8,14 +8,10 @@ set(CORE_SOURCES
BaseInstaller.cpp
BaseVersionList.h
BaseVersionList.cpp
- InstanceCreationTask.h
- InstanceCreationTask.cpp
- InstanceCopyTask.h
- InstanceCopyTask.cpp
- InstanceImportTask.h
- InstanceImportTask.cpp
InstanceList.h
InstanceList.cpp
+ InstanceTask.h
+ InstanceTask.cpp
LoggedProcess.h
LoggedProcess.cpp
MessageLevel.cpp
@@ -32,6 +28,14 @@ set(CORE_SOURCES
MMCStrings.h
MMCStrings.cpp
+ # Basic instance manipulation tasks (derived from InstanceTask)
+ InstanceCreationTask.h
+ InstanceCreationTask.cpp
+ InstanceCopyTask.h
+ InstanceCopyTask.cpp
+ InstanceImportTask.h
+ InstanceImportTask.cpp
+
# Use tracking separate from memory management
Usable.h
@@ -42,6 +46,10 @@ set(CORE_SOURCES
Env.h
Env.cpp
+ # String filters
+ Filter.h
+ Filter.cpp
+
# JSON parsing helpers
Json.h
Json.cpp
diff --git a/api/logic/Filter.cpp b/api/logic/Filter.cpp
new file mode 100644
index 00000000..7f6667ae
--- /dev/null
+++ b/api/logic/Filter.cpp
@@ -0,0 +1,31 @@
+#include "Filter.h"
+
+Filter::~Filter(){}
+
+ContainsFilter::ContainsFilter(const QString& pattern) : pattern(pattern){}
+ContainsFilter::~ContainsFilter(){}
+bool ContainsFilter::accepts(const QString& value)
+{
+ return value.contains(pattern);
+}
+
+ExactFilter::ExactFilter(const QString& pattern) : pattern(pattern){}
+ExactFilter::~ExactFilter(){}
+bool ExactFilter::accepts(const QString& value)
+{
+ return value.contains(pattern);
+}
+
+RegexpFilter::RegexpFilter(const QString& regexp, bool invert)
+ :invert(invert)
+{
+ pattern.setPattern(regexp);
+ pattern.optimize();
+}
+RegexpFilter::~RegexpFilter(){}
+bool RegexpFilter::accepts(const QString& value)
+{
+ auto match = pattern.match(value);
+ bool matched = match.hasMatch();
+ return invert ? (!matched) : (matched);
+}
diff --git a/api/logic/Filter.h b/api/logic/Filter.h
new file mode 100644
index 00000000..8de7d8f9
--- /dev/null
+++ b/api/logic/Filter.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <QString>
+#include <QRegularExpression>
+
+#include "multimc_logic_export.h"
+
+class MULTIMC_LOGIC_EXPORT Filter
+{
+public:
+ virtual ~Filter();
+ virtual bool accepts(const QString & value) = 0;
+};
+
+class MULTIMC_LOGIC_EXPORT ContainsFilter: public Filter
+{
+public:
+ ContainsFilter(const QString &pattern);
+ virtual ~ContainsFilter();
+ bool accepts(const QString & value) override;
+private:
+ QString pattern;
+};
+
+class MULTIMC_LOGIC_EXPORT ExactFilter: public Filter
+{
+public:
+ ExactFilter(const QString &pattern);
+ virtual ~ExactFilter();
+ bool accepts(const QString & value) override;
+private:
+ QString pattern;
+};
+
+class MULTIMC_LOGIC_EXPORT RegexpFilter: public Filter
+{
+public:
+ RegexpFilter(const QString &regexp, bool invert);
+ virtual ~RegexpFilter();
+ bool accepts(const QString & value) override;
+private:
+ QRegularExpression pattern;
+ bool invert = false;
+};
diff --git a/api/logic/FolderInstanceProvider.cpp b/api/logic/FolderInstanceProvider.cpp
index 52e23254..69ba6c82 100644
--- a/api/logic/FolderInstanceProvider.cpp
+++ b/api/logic/FolderInstanceProvider.cpp
@@ -412,46 +412,13 @@ private:
QTimer m_backoffTimer;
};
-#include "InstanceImportTask.h"
-Task * FolderInstanceProvider::zipImportTask(const QUrl sourceUrl, const QString& instName, const QString& instGroup, const QString& instIcon)
+#include "InstanceTask.h"
+Task * FolderInstanceProvider::wrapInstanceTask(InstanceTask * task)
{
auto stagingPath = getStagedInstancePath();
- auto task = new InstanceImportTask(m_globalSettings, sourceUrl, stagingPath, instName, instIcon, instGroup);
- return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
-}
-
-#include "InstanceCreationTask.h"
-Task * FolderInstanceProvider::creationTask(BaseVersionPtr version, const QString& instName, const QString& instGroup, const QString& instIcon)
-{
- auto stagingPath = getStagedInstancePath();
- auto task = new InstanceCreationTask(m_globalSettings, stagingPath, version, instName, instIcon, instGroup);
- return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
-}
-
-#include <modplatform/ftb/FtbPackInstallTask.h>
-Task * FolderInstanceProvider::ftbCreationTask(FtbPackDownloader *downloader, const QString& instName, const QString& instGroup, const QString& instIcon)
-{
- auto stagingPath = getStagedInstancePath();
- auto task = new FtbPackInstallTask(downloader, m_globalSettings, stagingPath, instName, instIcon, instGroup);
- return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
-}
-
-#include "InstanceCopyTask.h"
-Task * FolderInstanceProvider::copyTask(const InstancePtr& oldInstance, const QString& instName, const QString& instGroup, const QString& instIcon, bool copySaves)
-{
- auto stagingPath = getStagedInstancePath();
- auto task = new InstanceCopyTask(m_globalSettings, stagingPath, oldInstance, instName, instIcon, instGroup, copySaves);
- return new FolderInstanceStaging(this, task, stagingPath, instName, instGroup);
-}
-
-// FIXME: find a better place for this
-#include "minecraft/legacy/LegacyUpgradeTask.h"
-Task * FolderInstanceProvider::legacyUpgradeTask(const InstancePtr& oldInstance)
-{
- auto stagingPath = getStagedInstancePath();
- QString newName = tr("%1 (Migrated)").arg(oldInstance->name());
- auto task = new LegacyUpgradeTask(m_globalSettings, stagingPath, oldInstance, newName);
- return new FolderInstanceStaging(this, task, stagingPath, newName, oldInstance->group());
+ task->setStagingPath(stagingPath);
+ task->setParentSettings(m_globalSettings);
+ return new FolderInstanceStaging(this, task, stagingPath, task->name(), task->group());
}
QString FolderInstanceProvider::getStagedInstancePath()
diff --git a/api/logic/FolderInstanceProvider.h b/api/logic/FolderInstanceProvider.h
index 2641a46b..e13dcfe9 100644
--- a/api/logic/FolderInstanceProvider.h
+++ b/api/logic/FolderInstanceProvider.h
@@ -2,9 +2,9 @@
#include "BaseInstanceProvider.h"
#include <QMap>
-#include <modplatform/ftb/FtbPackDownloader.h>
class QFileSystemWatcher;
+class InstanceTask;
class MULTIMC_LOGIC_EXPORT FolderInstanceProvider : public BaseInstanceProvider
{
@@ -20,6 +20,7 @@ public:
InstancePtr loadInstance(const InstanceId& id) override;
+ /*
// create instance in this provider
Task * creationTask(BaseVersionPtr version, const QString &instName, const QString &instGroup, const QString &instIcon);
@@ -34,6 +35,10 @@ public:
// migrate an instance to the current format
Task * legacyUpgradeTask(const InstancePtr& oldInstance);
+*/
+
+ // Wrap an instance creation task in some more task machinery and make it ready to be used
+ Task * wrapInstanceTask(InstanceTask * task);
/**
* Create a new empty staging area for instance creation and @return a path/key top commit it later.
diff --git a/api/logic/InstanceCopyTask.cpp b/api/logic/InstanceCopyTask.cpp
index 9ede65f5..62c22362 100644
--- a/api/logic/InstanceCopyTask.cpp
+++ b/api/logic/InstanceCopyTask.cpp
@@ -6,14 +6,9 @@
#include "pathmatcher/RegexpMatcher.h"
#include <QtConcurrentRun>
-InstanceCopyTask::InstanceCopyTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString& instName, const QString& instIcon, const QString& instGroup, bool copySaves)
+InstanceCopyTask::InstanceCopyTask(InstancePtr origInstance, bool copySaves)
{
- m_globalSettings = settings;
- m_stagingPath = stagingPath;
m_origInstance = origInstance;
- m_instName = instName;
- m_instIcon = instIcon;
- m_instGroup = instGroup;
if(!copySaves)
{
diff --git a/api/logic/InstanceCopyTask.h b/api/logic/InstanceCopyTask.h
index dc46bfec..a8dc9783 100644
--- a/api/logic/InstanceCopyTask.h
+++ b/api/logic/InstanceCopyTask.h
@@ -9,16 +9,15 @@
#include "settings/SettingsObject.h"
#include "BaseVersion.h"
#include "BaseInstance.h"
-
+#include "InstanceTask.h"
class BaseInstanceProvider;
-class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public Task
+class MULTIMC_LOGIC_EXPORT InstanceCopyTask : public InstanceTask
{
Q_OBJECT
public:
- explicit InstanceCopyTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString &instName,
- const QString &instIcon, const QString &instGroup, bool copySaves);
+ explicit InstanceCopyTask(InstancePtr origInstance, bool copySaves);
protected:
//! Entry point for tasks.
@@ -27,15 +26,8 @@ protected:
void copyAborted();
private: /* data */
- SettingsObjectPtr m_globalSettings;
InstancePtr m_origInstance;
- QString m_instName;
- QString m_instIcon;
- QString m_instGroup;
- QString m_stagingPath;
QFuture<bool> m_copyFuture;
QFutureWatcher<bool> m_copyFutureWatcher;
std::unique_ptr<IPathMatcher> m_matcher;
};
-
-
diff --git a/api/logic/InstanceCreationTask.cpp b/api/logic/InstanceCreationTask.cpp
index 8a68815a..6dc2496c 100644
--- a/api/logic/InstanceCreationTask.cpp
+++ b/api/logic/InstanceCreationTask.cpp
@@ -7,14 +7,8 @@
#include "minecraft/MinecraftInstance.h"
#include "minecraft/ComponentList.h"
-InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, const QString & stagingPath, BaseVersionPtr version,
- const QString& instName, const QString& instIcon, const QString& instGroup)
+InstanceCreationTask::InstanceCreationTask(BaseVersionPtr version)
{
- m_globalSettings = settings;
- m_stagingPath = stagingPath;
- m_instName = instName;
- m_instIcon = instIcon;
- m_instGroup = instGroup;
m_version = version;
}
diff --git a/api/logic/InstanceCreationTask.h b/api/logic/InstanceCreationTask.h
index 49fd4615..e06eacbb 100644
--- a/api/logic/InstanceCreationTask.h
+++ b/api/logic/InstanceCreationTask.h
@@ -6,24 +6,18 @@
#include <QUrl>
#include "settings/SettingsObject.h"
#include "BaseVersion.h"
+#include "InstanceTask.h"
-class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public Task
+class MULTIMC_LOGIC_EXPORT InstanceCreationTask : public InstanceTask
{
Q_OBJECT
public:
- explicit InstanceCreationTask(SettingsObjectPtr settings, const QString & stagingPath, BaseVersionPtr version, const QString &instName,
- const QString &instIcon, const QString &instGroup);
+ explicit InstanceCreationTask(BaseVersionPtr version);
protected:
//! Entry point for tasks.
virtual void executeTask() override;
private: /* data */
- SettingsObjectPtr m_globalSettings;
- QString m_stagingPath;
BaseVersionPtr m_version;
- QString m_instName;
- QString m_instIcon;
- QString m_instGroup;
};
-
diff --git a/api/logic/InstanceImportTask.cpp b/api/logic/InstanceImportTask.cpp
index 7fae97b8..b5375cbc 100644
--- a/api/logic/InstanceImportTask.cpp
+++ b/api/logic/InstanceImportTask.cpp
@@ -16,15 +16,9 @@
#include "modplatform/flame/PackManifest.h"
#include "Json.h"
-InstanceImportTask::InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, const QString & stagingPath,
- const QString &instName, const QString &instIcon, const QString &instGroup)
+InstanceImportTask::InstanceImportTask(const QUrl sourceUrl)
{
- m_globalSettings = settings;
m_sourceUrl = sourceUrl;
- m_stagingPath = stagingPath;
- m_instName = instName;
- m_instIcon = instIcon;
- m_instGroup = instGroup;
}
void InstanceImportTask::executeTask()
diff --git a/api/logic/InstanceImportTask.h b/api/logic/InstanceImportTask.h
index 99397009..06778dfe 100644
--- a/api/logic/InstanceImportTask.h
+++ b/api/logic/InstanceImportTask.h
@@ -1,6 +1,6 @@
#pragma once
-#include "tasks/Task.h"
+#include "InstanceTask.h"
#include "multimc_logic_export.h"
#include "net/NetJob.h"
#include <QUrl>
@@ -16,12 +16,11 @@ namespace Flame
class FileResolvingTask;
}
-class MULTIMC_LOGIC_EXPORT InstanceImportTask : public Task
+class MULTIMC_LOGIC_EXPORT InstanceImportTask : public InstanceTask
{
Q_OBJECT
public:
- explicit InstanceImportTask(SettingsObjectPtr settings, const QUrl sourceUrl, const QString & stagingPath, const QString &instName,
- const QString &instIcon, const QString &instGroup);
+ explicit InstanceImportTask(const QUrl sourceUrl);
protected:
//! Entry point for tasks.
@@ -40,16 +39,11 @@ private slots:
void extractAborted();
private: /* data */
- SettingsObjectPtr m_globalSettings;
NetJobPtr m_filesNetJob;
shared_qobject_ptr<Flame::FileResolvingTask> m_modIdResolver;
QUrl m_sourceUrl;
QString m_archivePath;
bool m_downloadRequired = false;
- QString m_instName;
- QString m_instIcon;
- QString m_instGroup;
- QString m_stagingPath;
std::unique_ptr<QuaZip> m_packZip;
QFuture<QStringList> m_extractFuture;
QFutureWatcher<QStringList> m_extractFutureWatcher;
diff --git a/api/logic/InstanceTask.cpp b/api/logic/InstanceTask.cpp
new file mode 100644
index 00000000..dd132877
--- /dev/null
+++ b/api/logic/InstanceTask.cpp
@@ -0,0 +1,9 @@
+#include "InstanceTask.h"
+
+InstanceTask::InstanceTask()
+{
+}
+
+InstanceTask::~InstanceTask()
+{
+}
diff --git a/api/logic/InstanceTask.h b/api/logic/InstanceTask.h
new file mode 100644
index 00000000..8fc98eb7
--- /dev/null
+++ b/api/logic/InstanceTask.h
@@ -0,0 +1,55 @@
+#pragma once
+
+#include "tasks/Task.h"
+#include "multimc_logic_export.h"
+#include "settings/SettingsObject.h"
+
+class BaseInstanceProvider;
+
+class MULTIMC_LOGIC_EXPORT InstanceTask : public Task
+{
+ Q_OBJECT
+public:
+ explicit InstanceTask();
+ virtual ~InstanceTask();
+
+ void setParentSettings(SettingsObjectPtr settings)
+ {
+ m_globalSettings = settings;
+ }
+
+ void setStagingPath(const QString &stagingPath)
+ {
+ m_stagingPath = stagingPath;
+ }
+
+ void setName(const QString &name)
+ {
+ m_instName = name;
+ }
+ QString name() const
+ {
+ return m_instName;
+ }
+
+ void setIcon(const QString &icon)
+ {
+ m_instIcon = icon;
+ }
+
+ void setGroup(const QString &group)
+ {
+ m_instGroup = group;
+ }
+ QString group() const
+ {
+ return m_instGroup;
+ }
+
+protected: /* data */
+ SettingsObjectPtr m_globalSettings;
+ QString m_instName;
+ QString m_instIcon;
+ QString m_instGroup;
+ QString m_stagingPath;
+};
diff --git a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp
index 9fc6d92b..5cc3b5d9 100644
--- a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp
+++ b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp
@@ -10,12 +10,9 @@
#include "minecraft/ComponentList.h"
#include "classparser.h"
-LegacyUpgradeTask::LegacyUpgradeTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString & newName)
+LegacyUpgradeTask::LegacyUpgradeTask(InstancePtr origInstance)
{
- m_globalSettings = settings;
- m_stagingPath = stagingPath;
m_origInstance = origInstance;
- m_newName = newName;
}
void LegacyUpgradeTask::executeTask()
@@ -70,7 +67,7 @@ void LegacyUpgradeTask::copyFinished()
// NOTE: this scope ensures the instance is fully saved before we emitSucceeded
{
MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
- inst.setName(m_newName);
+ inst.setName(m_instName);
inst.init();
QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId());
diff --git a/api/logic/minecraft/legacy/LegacyUpgradeTask.h b/api/logic/minecraft/legacy/LegacyUpgradeTask.h
index 56896385..a93dd0d9 100644
--- a/api/logic/minecraft/legacy/LegacyUpgradeTask.h
+++ b/api/logic/minecraft/legacy/LegacyUpgradeTask.h
@@ -1,6 +1,6 @@
#pragma once
-#include "tasks/Task.h"
+#include "InstanceTask.h"
#include "multimc_logic_export.h"
#include "net/NetJob.h"
#include <QUrl>
@@ -13,11 +13,11 @@
class BaseInstanceProvider;
-class MULTIMC_LOGIC_EXPORT LegacyUpgradeTask : public Task
+class MULTIMC_LOGIC_EXPORT LegacyUpgradeTask : public InstanceTask
{
Q_OBJECT
public:
- explicit LegacyUpgradeTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString & newName);
+ explicit LegacyUpgradeTask(InstancePtr origInstance);
protected:
//! Entry point for tasks.
@@ -26,13 +26,7 @@ protected:
void copyAborted();
private: /* data */
- SettingsObjectPtr m_globalSettings;
InstancePtr m_origInstance;
- QString m_stagingPath;
- QString m_newName;
QFuture<bool> m_copyFuture;
QFutureWatcher<bool> m_copyFutureWatcher;
};
-
-
-
diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.cpp b/api/logic/modplatform/ftb/FtbPackDownloader.cpp
index caadd4ae..3e274c9e 100644
--- a/api/logic/modplatform/ftb/FtbPackDownloader.cpp
+++ b/api/logic/modplatform/ftb/FtbPackDownloader.cpp
@@ -3,36 +3,25 @@
#include "FtbPackFetchTask.h"
#include "Env.h"
-FtbPackDownloader::FtbPackDownloader() {
+FtbPackDownloader::FtbPackDownloader()
+{
done = false;
fetching = false;
}
-FtbPackDownloader::~FtbPackDownloader(){
-}
-
-bool FtbPackDownloader::isValidPackSelected(){
- FtbModpack dummy;
- dummy.name = "__INVALID__";
-
- FtbModpack other = fetchedPacks.value(selected.name, dummy);
- if(other.name == "__INVALID__") {
- return false;
- }
-
- return other.oldVersions.contains(selectedVersion) && !other.broken;
-}
-
-QString FtbPackDownloader::getSuggestedInstanceName() {
- return selected.name;
+FtbPackDownloader::~FtbPackDownloader()
+{
}
-FtbModpackList FtbPackDownloader::getModpacks() {
+FtbModpackList FtbPackDownloader::getModpacks()
+{
return static_cast<FtbModpackList>(fetchedPacks.values());
}
-void FtbPackDownloader::fetchModpacks(bool force = false){
- if(fetching || (!force && done)) {
+void FtbPackDownloader::fetchModpacks(bool force = false)
+{
+ if(fetching || (!force && done))
+ {
qDebug() << "Skipping modpack refetch because done or already fetching [done =>" << done << "| fetching =>" << fetching << "]";
return;
}
@@ -46,8 +35,10 @@ void FtbPackDownloader::fetchModpacks(bool force = false){
}
-void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) {
- for(int i = 0; i < modpacks.size(); i++) {
+void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks)
+{
+ for(int i = 0; i < modpacks.size(); i++)
+ {
fetchedPacks.insert(modpacks.at(i).name, modpacks.at(i));
}
@@ -57,53 +48,10 @@ void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks) {
fetchTask->deleteLater();
}
-void FtbPackDownloader::fetchFailed(QString reason) {
+void FtbPackDownloader::fetchFailed(QString reason)
+{
qWarning() << "Failed to fetch FtbData" << reason;
fetching = false;
emit packFetchFailed();
fetchTask->deleteLater();
}
-
-void FtbPackDownloader::selectPack(FtbModpack modpack, QString version) {
- selected = modpack;
- selectedVersion = version;
-}
-
-FtbModpack FtbPackDownloader::getSelectedPack() {
- return selected;
-}
-
-void FtbPackDownloader::downloadSelected(MetaEntryPtr cache) {
- NetJob *job = new NetJob("Downlad FTB Pack");
-
- cache->setStale(true);
- QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1/%2/%3").arg(selected.dir, selectedVersion.replace(".", "_"), selected.file);
- job->addNetAction(Net::Download::makeCached(url, cache));
- downloadPath = cache->getFullPath();
-
- netJobContainer.reset(job);
-
- connect(job, &NetJob::succeeded, this, &FtbPackDownloader::_downloadSucceeded);
- connect(job, &NetJob::failed, this, &FtbPackDownloader::_downloadFailed);
- connect(job, &NetJob::progress, this, &FtbPackDownloader::_downloadProgress);
- job->start();
-}
-
-void FtbPackDownloader::_downloadSucceeded() {
- netJobContainer.reset();
- emit downloadSucceded(downloadPath);
-}
-
-void FtbPackDownloader::_downloadProgress(qint64 current, qint64 total) {
- emit downloadProgress(current, total);
-}
-
-void FtbPackDownloader::_downloadFailed(QString reason) {
- netJobContainer.reset();
- emit downloadFailed(reason);
-}
-
-NetJobPtr FtbPackDownloader::getNetJob()
-{
- return netJobContainer;
-}
diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.h b/api/logic/modplatform/ftb/FtbPackDownloader.h
index c5cc9bd2..cf7eb567 100644
--- a/api/logic/modplatform/ftb/FtbPackDownloader.h
+++ b/api/logic/modplatform/ftb/FtbPackDownloader.h
@@ -11,54 +11,29 @@
#pragma once
-class FtbPackDownloader;
-class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject {
-
+class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject
+{
Q_OBJECT
-private:
- QMap<QString, FtbModpack> fetchedPacks;
- bool fetching = false;
- bool done = false;
-
- FtbModpack selected;
- QString selectedVersion;
- QString downloadPath;
-
- FtbPackFetchTask *fetchTask = 0;
- NetJobPtr netJobContainer;
-
- void _downloadSucceeded();
- void _downloadFailed(QString reason);
- void _downloadProgress(qint64 current, qint64 total);
-
-private slots:
- void fetchSuccess(FtbModpackList modlist);
- void fetchFailed(QString reason);
-
public:
FtbPackDownloader();
- ~FtbPackDownloader();
-
- bool isValidPackSelected();
- void selectPack(FtbModpack modpack, QString version);
-
- FtbModpack getSelectedPack();
+ virtual ~FtbPackDownloader();
void fetchModpacks(bool force);
- void downloadSelected(MetaEntryPtr cache);
-
- QString getSuggestedInstanceName();
-
FtbModpackList getModpacks();
- NetJobPtr getNetJob();
signals:
void ready();
void packFetchFailed();
- void downloadSucceded(QString archivePath);
- void downloadFailed(QString reason);
- void downloadProgress(qint64 current, qint64 total);
+private slots:
+ void fetchSuccess(FtbModpackList modlist);
+ void fetchFailed(QString reason);
+private:
+ QMap<QString, FtbModpack> fetchedPacks;
+ bool fetching = false;
+ bool done = false;
+
+ FtbPackFetchTask *fetchTask = 0;
};
diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
index 9e151186..30253bb9 100644
--- a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
+++ b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
@@ -58,6 +58,8 @@ void FtbPackFetchTask::fileDownloadFinished(){
modpack.mods = element.attribute("mods");
modpack.image = element.attribute("image");
modpack.oldVersions = element.attribute("oldVersions").split(";");
+ modpack.broken = false;
+ modpack.bugged = false;
//remove empty if the xml is bugged
for(QString curr : modpack.oldVersions) {
diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.h b/api/logic/modplatform/ftb/FtbPackFetchTask.h
index 3cfac4ed..a2e4b5ab 100644
--- a/api/logic/modplatform/ftb/FtbPackFetchTask.h
+++ b/api/logic/modplatform/ftb/FtbPackFetchTask.h
@@ -12,7 +12,7 @@ class MULTIMC_LOGIC_EXPORT FtbPackFetchTask : public QObject {
public:
FtbPackFetchTask();
- ~FtbPackFetchTask();
+ virtual ~FtbPackFetchTask();
void fetch();
diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp
index 530f72ca..e3bb2340 100644
--- a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp
+++ b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp
@@ -9,52 +9,65 @@
#include "minecraft/ComponentList.h"
#include "minecraft/GradleSpecifier.h"
-FtbPackInstallTask::FtbPackInstallTask(FtbPackDownloader *downloader, SettingsObjectPtr settings,
- const QString &stagingPath, const QString &instName, const QString &instIcon, const QString &instGroup) :
- m_globalSettings(settings), m_stagingPath(stagingPath), m_instName(instName), m_instIcon(instIcon), m_instGroup(instGroup)
+FtbPackInstallTask::FtbPackInstallTask(FtbModpack pack, QString version)
{
- m_downloader = downloader;
+ m_pack = pack;
+ m_version = version;
}
-void FtbPackInstallTask::executeTask() {
+void FtbPackInstallTask::executeTask()
+{
downloadPack();
}
-void FtbPackInstallTask::downloadPack(){
- FtbModpack toInstall = m_downloader->getSelectedPack();
- setStatus(tr("Downloading zip for %1").arg(toInstall.name));
+void FtbPackInstallTask::downloadPack()
+{
+ setStatus(tr("Downloading zip for %1").arg(m_pack.name));
+
+ auto entry = ENV.metacache()->resolveEntry("general", "FTBPacks/" + m_pack.name);
+ NetJob *job = new NetJob("Downlad FTB Pack");
+
+ entry->setStale(true);
+ QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1/%2/%3").arg(m_pack.dir, m_version.replace(".", "_"), m_pack.file);
+ job->addNetAction(Net::Download::makeCached(url, entry));
+ archivePath = entry->getFullPath();
- auto entry = ENV.metacache()->resolveEntry("general", "FTBPacks/" + toInstall.name);
- m_downloader->downloadSelected(entry);
+ netJobContainer.reset(job);
+ connect(job, &NetJob::succeeded, this, &FtbPackInstallTask::onDownloadSucceeded);
+ connect(job, &NetJob::failed, this, &FtbPackInstallTask::onDownloadFailed);
+ connect(job, &NetJob::progress, this, &FtbPackInstallTask::onDownloadProgress);
+ job->start();
- connect(m_downloader, &FtbPackDownloader::downloadSucceded, this, &FtbPackInstallTask::onDownloadSucceeded);
- connect(m_downloader, &FtbPackDownloader::downloadProgress, this, &FtbPackInstallTask::onDownloadProgress);
- connect(m_downloader, &FtbPackDownloader::downloadFailed, this,&FtbPackInstallTask::onDownloadFailed);
progress(1, 4);
}
-void FtbPackInstallTask::onDownloadSucceeded(QString archivePath){
+void FtbPackInstallTask::onDownloadSucceeded()
+{
abortable = false;
- unzip(archivePath);
+ unzip();
}
-void FtbPackInstallTask::onDownloadFailed(QString reason) {
+void FtbPackInstallTask::onDownloadFailed(QString reason)
+{
emitFailed(reason);
}
-void FtbPackInstallTask::onDownloadProgress(qint64 current, qint64 total){
+void FtbPackInstallTask::onDownloadProgress(qint64 current, qint64 total)
+{
abortable = true;
progress(current, total * 4);
- setStatus(tr("Downloading zip for %1 (%2\%)").arg(m_downloader->getSelectedPack().name).arg(current / 10));
+ setStatus(tr("Downloading zip for %1 (%2\%)").arg(m_pack.name).arg(current / 10));
}
-void FtbPackInstallTask::unzip(QString archivePath) {
+void FtbPackInstallTask::unzip()
+{
progress(2, 4);
setStatus(tr("Extracting modpack"));
QDir extractDir(m_stagingPath);
m_packZip.reset(new QuaZip(archivePath));
- if(!m_packZip->open(QuaZip::mdUnzip)) {
+ if(!m_packZip->open(QuaZip::mdUnzip))
+ {
emitFailed(tr("Failed to open modpack file %1!").arg(archivePath));
return;
}
@@ -65,22 +78,26 @@ void FtbPackInstallTask::unzip(QString archivePath) {
m_extractFutureWatcher.setFuture(m_extractFuture);
}
-void FtbPackInstallTask::onUnzipFinished() {
+void FtbPackInstallTask::onUnzipFinished()
+{
install();
}
-void FtbPackInstallTask::onUnzipCanceled() {
+void FtbPackInstallTask::onUnzipCanceled()
+{
emitAborted();
}
-void FtbPackInstallTask::install() {
+void FtbPackInstallTask::install()
+{
progress(3, 4);
- FtbModpack toInstall = m_downloader->getSelectedPack();
setStatus(tr("Installing modpack"));
QDir unzipMcDir(m_stagingPath + "/unzip/minecraft");
- if(unzipMcDir.exists()) {
+ if(unzipMcDir.exists())
+ {
//ok, found minecraft dir, move contents to instance dir
- if(!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft")) {
+ if(!QDir().rename(m_stagingPath + "/unzip/minecraft", m_stagingPath + "/.minecraft"))
+ {
emitFailed(tr("Failed to move unzipped minecraft!"));
return;
}
@@ -94,14 +111,15 @@ void FtbPackInstallTask::install() {
MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath);
auto components = instance.getComponentList();
components->buildingFromScratch();
- components->setComponentVersion("net.minecraft", toInstall.mcVersion, true);
+ components->setComponentVersion("net.minecraft", m_pack.mcVersion, true);
bool fallback = true;
//handle different versions
QFile packJson(m_stagingPath + "/.minecraft/pack.json");
QDir jarmodDir = QDir(m_stagingPath + "/unzip/instMods");
- if(packJson.exists()) {
+ if(packJson.exists())
+ {
packJson.open(QIODevice::ReadOnly | QIODevice::Text);
QJsonDocument doc = QJsonDocument::fromJson(packJson.readAll());
packJson.close();
@@ -109,15 +127,17 @@ void FtbPackInstallTask::install() {
//we only care about the libs
QJsonArray libs = doc.object().value("libraries").toArray();
- foreach (const QJsonValue &value, libs) {
+ foreach (const QJsonValue &value, libs)
+ {
QString nameValue = value.toObject().value("name").toString();
- if(!nameValue.startsWith("net.minecraftforge")) {
+ if(!nameValue.startsWith("net.minecraftforge"))
+ {
continue;
}
GradleSpecifier forgeVersion(nameValue);
- components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(toInstall.mcVersion, "").replace("-", ""));
+ components->setComponentVersion("net.minecraftforge", forgeVersion.version().replace(m_pack.mcVersion, "").replace("-", ""));
packJson.remove();
fallback = false;
break;
@@ -125,7 +145,8 @@ void FtbPackInstallTask::install() {
}
- if(jarmodDir.exists()) {
+ if(jarmodDir.exists())
+ {
qDebug() << "Found jarmods, installing...";
QStringList jarmods;
@@ -142,7 +163,8 @@ void FtbPackInstallTask::install() {
//just nuke unzip directory, it s not needed anymore
FS::deletePath(m_stagingPath + "/unzip");
- if(fallback) {
+ if(fallback)
+ {
//TODO: Some fallback mechanism... or just keep failing!
emitFailed(tr("No installation method found!"));
return;
@@ -154,7 +176,8 @@ void FtbPackInstallTask::install() {
instance.init();
instance.setName(m_instName);
- if(m_instIcon == "default") {
+ if(m_instIcon == "default")
+ {
m_instIcon = "ftb_logo";
}
instance.setIconKey(m_instIcon);
@@ -166,8 +189,9 @@ void FtbPackInstallTask::install() {
bool FtbPackInstallTask::abort()
{
- if(abortable) {
- return m_downloader->getNetJob()->abort();
+ if(abortable)
+ {
+ return netJobContainer->abort();
}
return false;
}
diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.h b/api/logic/modplatform/ftb/FtbPackInstallTask.h
index 7d6e5276..64f4809d 100644
--- a/api/logic/modplatform/ftb/FtbPackInstallTask.h
+++ b/api/logic/modplatform/ftb/FtbPackInstallTask.h
@@ -1,5 +1,5 @@
#pragma once
-#include "tasks/Task.h"
+#include "InstanceTask.h"
#include "modplatform/ftb/FtbPackDownloader.h"
#include "BaseInstanceProvider.h"
#include "net/NetJob.h"
@@ -9,47 +9,41 @@
#include "meta/Version.h"
#include "meta/VersionList.h"
-class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public Task {
+class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask {
Q_OBJECT
public:
- explicit FtbPackInstallTask(FtbPackDownloader *downloader, SettingsObjectPtr settings, const QString &stagingPath, const QString &instName,
- const QString &instIcon, const QString &instGroup);
+ explicit FtbPackInstallTask(FtbModpack pack, QString version);
+ virtual ~FtbPackInstallTask(){}
+
bool abort() override;
protected:
//! Entry point for tasks.
virtual void executeTask() override;
-private: /* data */
- SettingsObjectPtr m_globalSettings;
- QString m_stagingPath;
- QString m_instName;
- QString m_instIcon;
- QString m_instGroup;
- NetJobPtr m_netJobPtr;
-
- FtbPackDownloader *m_downloader;
-
- std::unique_ptr<QuaZip> m_packZip;
- QFuture<QStringList> m_extractFuture;
- QFutureWatcher<QStringList> m_extractFutureWatcher;
-
+private:
void downloadPack();
- void unzip(QString archivePath);
+ void unzip();
void install();
- bool moveRecursively(QString source, QString dest);
-
- bool abortable = false;
-
private slots:
- void onDownloadSucceeded(QString archivePath);
+ void onDownloadSucceeded();
void onDownloadFailed(QString reason);
void onDownloadProgress(qint64 current, qint64 total);
void onUnzipFinished();
void onUnzipCanceled();
+private: /* data */
+ bool abortable = false;
+ std::unique_ptr<QuaZip> m_packZip;
+ QFuture<QStringList> m_extractFuture;
+ QFutureWatcher<QStringList> m_extractFutureWatcher;
+ NetJobPtr netJobContainer;
+ QString archivePath;
+
+ FtbModpack m_pack;
+ QString m_version;
};
diff --git a/api/logic/modplatform/ftb/PackHelpers.h b/api/logic/modplatform/ftb/PackHelpers.h
index f761ed6b..b184ed33 100644
--- a/api/logic/modplatform/ftb/PackHelpers.h
+++ b/api/logic/modplatform/ftb/PackHelpers.h
@@ -17,8 +17,8 @@ struct FtbModpack {
QString dir;
QString file; //<- Url in the xml, but doesn't make much sense
- bool bugged = false;
- bool broken = false;
+ bool bugged = true;
+ bool broken = true;
};
//We need it for the proxy model
Q_DECLARE_METATYPE(FtbModpack)