summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/CMakeLists.txt4
-rw-r--r--api/logic/RWStorage.h2
-rw-r--r--api/logic/modplatform/ftb/FtbPackDownloader.cpp57
-rw-r--r--api/logic/modplatform/ftb/FtbPackDownloader.h39
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.cpp63
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.h10
-rw-r--r--api/logic/modplatform/ftb/FtbPackInstallTask.h2
-rw-r--r--api/logic/modplatform/ftb/PackHelpers.h15
8 files changed, 63 insertions, 129 deletions
diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt
index c6daef6f..d6b61d23 100644
--- a/api/logic/CMakeLists.txt
+++ b/api/logic/CMakeLists.txt
@@ -421,10 +421,6 @@ set(META_SOURCES
)
set(FTB_SOURCES
- # Modplatform sources
- modplatform/ftb/FtbPackDownloader.h
- modplatform/ftb/FtbPackDownloader.cpp
-
modplatform/ftb/FtbPackFetchTask.h
modplatform/ftb/FtbPackFetchTask.cpp
modplatform/ftb/FtbPackInstallTask.h
diff --git a/api/logic/RWStorage.h b/api/logic/RWStorage.h
index bbe8ac5a..4afbd96c 100644
--- a/api/logic/RWStorage.h
+++ b/api/logic/RWStorage.h
@@ -1,4 +1,6 @@
#pragma once
+#include <QWriteLocker>
+#include <QReadLocker>
template <typename K, typename V>
class RWStorage
{
diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.cpp b/api/logic/modplatform/ftb/FtbPackDownloader.cpp
deleted file mode 100644
index 3e274c9e..00000000
--- a/api/logic/modplatform/ftb/FtbPackDownloader.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "FtbPackDownloader.h"
-#include "PackHelpers.h"
-#include "FtbPackFetchTask.h"
-#include "Env.h"
-
-FtbPackDownloader::FtbPackDownloader()
-{
- done = false;
- fetching = false;
-}
-
-FtbPackDownloader::~FtbPackDownloader()
-{
-}
-
-FtbModpackList FtbPackDownloader::getModpacks()
-{
- return static_cast<FtbModpackList>(fetchedPacks.values());
-}
-
-void FtbPackDownloader::fetchModpacks(bool force = false)
-{
- if(fetching || (!force && done))
- {
- qDebug() << "Skipping modpack refetch because done or already fetching [done =>" << done << "| fetching =>" << fetching << "]";
- return;
- }
-
- fetching = true;
-
- fetchTask = new FtbPackFetchTask();
- connect(fetchTask, &FtbPackFetchTask::finished, this, &FtbPackDownloader::fetchSuccess);
- connect(fetchTask, &FtbPackFetchTask::failed, this, &FtbPackDownloader::fetchFailed);
- fetchTask->fetch();
-}
-
-
-void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks)
-{
- for(int i = 0; i < modpacks.size(); i++)
- {
- fetchedPacks.insert(modpacks.at(i).name, modpacks.at(i));
- }
-
- fetching = false;
- done = true;
- emit ready();
- fetchTask->deleteLater();
-}
-
-void FtbPackDownloader::fetchFailed(QString reason)
-{
- qWarning() << "Failed to fetch FtbData" << reason;
- fetching = false;
- emit packFetchFailed();
- fetchTask->deleteLater();
-}
diff --git a/api/logic/modplatform/ftb/FtbPackDownloader.h b/api/logic/modplatform/ftb/FtbPackDownloader.h
deleted file mode 100644
index cf7eb567..00000000
--- a/api/logic/modplatform/ftb/FtbPackDownloader.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#include <QString>
-#include <QUrl>
-#include <QList>
-#include <QObject>
-#include "FtbPackFetchTask.h"
-#include "tasks/Task.h"
-#include "net/NetJob.h"
-
-#include "PackHelpers.h"
-#include "Env.h"
-
-#pragma once
-
-class MULTIMC_LOGIC_EXPORT FtbPackDownloader : public QObject
-{
- Q_OBJECT
-
-public:
- FtbPackDownloader();
- virtual ~FtbPackDownloader();
-
- void fetchModpacks(bool force);
- FtbModpackList getModpacks();
-
-signals:
- void ready();
- void packFetchFailed();
-
-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 30253bb9..5588a7fd 100644
--- a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
+++ b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
@@ -1,21 +1,25 @@
#include "FtbPackFetchTask.h"
#include <QDomDocument>
-FtbPackFetchTask::FtbPackFetchTask() {
-
+FtbPackFetchTask::FtbPackFetchTask()
+{
}
-FtbPackFetchTask::~FtbPackFetchTask() {
-
+FtbPackFetchTask::~FtbPackFetchTask()
+{
}
-void FtbPackFetchTask::fetch() {
+void FtbPackFetchTask::fetch()
+{
NetJob *netJob = new NetJob("FtbModpackFetch");
- QUrl url = QUrl("https://ftb.cursecdn.com/FTB2/static/modpacks.xml");
- qDebug() << "Downloading version info from " << url.toString();
+ QUrl publicPacksUrl = QUrl("https://ftb.cursecdn.com/FTB2/static/modpacks.xml");
+ qDebug() << "Downloading public version info from" << publicPacksUrl.toString();
+ netJob->addNetAction(Net::Download::makeByteArray(publicPacksUrl, &publicModpacksXmlFileData));
- netJob->addNetAction(downloadPtr = Net::Download::makeByteArray(url, &modpacksXmlFileData));
+ QUrl thirdPartyUrl = QUrl("https://ftb.cursecdn.com/FTB2/static/thirdparty.xml");
+ qDebug() << "Downloading thirdparty version info from" << thirdPartyUrl.toString();
+ netJob->addNetAction(Net::Download::makeByteArray(thirdPartyUrl, &thirdPartyModpacksXmlFileData));
QObject::connect(netJob, &NetJob::succeeded, this, &FtbPackFetchTask::fileDownloadFinished);
QObject::connect(netJob, &NetJob::failed, this, &FtbPackFetchTask::fileDownloadFailed);
@@ -24,28 +28,42 @@ void FtbPackFetchTask::fetch() {
netJob->start();
}
-void FtbPackFetchTask::fileDownloadFinished(){
-
+void FtbPackFetchTask::fileDownloadFinished()
+{
jobPtr.reset();
+ QStringList failedLists;
+
+ if(!parseAndAddPacks(publicModpacksXmlFileData, FtbPackType::Public, publicPacks)) {
+ failedLists.append(tr("Public Packs"));
+ }
+
+ if(!parseAndAddPacks(thirdPartyModpacksXmlFileData, FtbPackType::ThirdParty, thirdPartyPacks)) {
+ failedLists.append(tr("Third Party Packs"));
+ }
+
+ if(failedLists.size() > 0) {
+ emit failed(QString("Failed to download some pack lists:%1").arg(failedLists.join("\n- ")));
+ } else {
+ emit finished(publicPacks, thirdPartyPacks);
+ }
+}
+
+bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType, FtbModpackList &list)
+{
QDomDocument doc;
QString errorMsg = "Unknown error.";
int errorLine = -1;
int errorCol = -1;
- if(!doc.setContent(modpacksXmlFileData, false, &errorMsg, &errorLine, &errorCol)){
+ if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol)){
auto fullErrMsg = QString("Failed to fetch modpack data: %s %d:%d!").arg(errorMsg, errorLine, errorCol);
qWarning() << fullErrMsg;
- emit failed(fullErrMsg);
- modpacksXmlFileData.clear();
- return;
+ data.clear();
+ return false;
}
- modpacksXmlFileData.clear();
-
- FtbModpackList modpackList;
-
QDomNodeList nodes = doc.elementsByTagName("modpack");
for(int i = 0; i < nodes.length(); i++) {
QDomElement element = nodes.at(i).toElement();
@@ -56,7 +74,7 @@ void FtbPackFetchTask::fileDownloadFinished(){
modpack.mcVersion = element.attribute("mcVersion");
modpack.description = element.attribute("description");
modpack.mods = element.attribute("mods");
- modpack.image = element.attribute("image");
+ modpack.logo = element.attribute("logo");
modpack.oldVersions = element.attribute("oldVersions").split(";");
modpack.broken = false;
modpack.bugged = false;
@@ -85,11 +103,12 @@ void FtbPackFetchTask::fileDownloadFinished(){
modpack.dir = element.attribute("dir");
modpack.file = element.attribute("url");
- modpackList.append(modpack);
- }
+ modpack.type = packType;
+ list.append(modpack);
+ }
- emit finished(modpackList);
+ return true;
}
void FtbPackFetchTask::fileDownloadFailed(QString reason){
diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.h b/api/logic/modplatform/ftb/FtbPackFetchTask.h
index a2e4b5ab..b5635b12 100644
--- a/api/logic/modplatform/ftb/FtbPackFetchTask.h
+++ b/api/logic/modplatform/ftb/FtbPackFetchTask.h
@@ -18,16 +18,20 @@ public:
private:
NetJobPtr jobPtr;
- Net::Download::Ptr downloadPtr;
- QByteArray modpacksXmlFileData;
+ QByteArray publicModpacksXmlFileData;
+ QByteArray thirdPartyModpacksXmlFileData;
+
+ bool parseAndAddPacks(QByteArray &data, FtbPackType packType, FtbModpackList &list);
+ FtbModpackList publicPacks;
+ FtbModpackList thirdPartyPacks;
protected slots:
void fileDownloadFinished();
void fileDownloadFailed(QString reason);
signals:
- void finished(FtbModpackList list);
+ void finished(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
void failed(QString reason);
};
diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.h b/api/logic/modplatform/ftb/FtbPackInstallTask.h
index 64f4809d..0bfba3d6 100644
--- a/api/logic/modplatform/ftb/FtbPackInstallTask.h
+++ b/api/logic/modplatform/ftb/FtbPackInstallTask.h
@@ -1,6 +1,5 @@
#pragma once
#include "InstanceTask.h"
-#include "modplatform/ftb/FtbPackDownloader.h"
#include "BaseInstanceProvider.h"
#include "net/NetJob.h"
#include "quazip.h"
@@ -8,6 +7,7 @@
#include "meta/Index.h"
#include "meta/Version.h"
#include "meta/VersionList.h"
+#include "modplatform/ftb/PackHelpers.h"
class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask {
diff --git a/api/logic/modplatform/ftb/PackHelpers.h b/api/logic/modplatform/ftb/PackHelpers.h
index b184ed33..350a5fa6 100644
--- a/api/logic/modplatform/ftb/PackHelpers.h
+++ b/api/logic/modplatform/ftb/PackHelpers.h
@@ -3,6 +3,12 @@
#include "qmetatype.h"
//Header for structs etc...
+enum FtbPackType {
+ Public,
+ ThirdParty,
+ Private
+};
+
struct FtbModpack {
QString name;
QString description;
@@ -11,15 +17,18 @@ struct FtbModpack {
QString currentVersion;
QString mcVersion;
QString mods;
- QString image;
+ QString logo;
//Technical data
QString dir;
QString file; //<- Url in the xml, but doesn't make much sense
- bool bugged = true;
- bool broken = true;
+ bool bugged = false;
+ bool broken = false;
+
+ FtbPackType type;
};
+
//We need it for the proxy model
Q_DECLARE_METATYPE(FtbModpack)