summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/logic/CMakeLists.txt3
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.cpp95
-rw-r--r--api/logic/modplatform/ftb/FtbPackFetchTask.h7
-rw-r--r--api/logic/modplatform/ftb/FtbPackInstallTask.cpp10
-rw-r--r--api/logic/modplatform/ftb/FtbPackInstallTask.h4
-rw-r--r--api/logic/modplatform/ftb/FtbPrivatePackManager.cpp36
-rw-r--r--api/logic/modplatform/ftb/FtbPrivatePackManager.h40
-rw-r--r--api/logic/modplatform/ftb/PackHelpers.h7
8 files changed, 172 insertions, 30 deletions
diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt
index f0b2d979..5d20b7a9 100644
--- a/api/logic/CMakeLists.txt
+++ b/api/logic/CMakeLists.txt
@@ -425,6 +425,9 @@ set(FTB_SOURCES
modplatform/ftb/FtbPackInstallTask.h
modplatform/ftb/FtbPackInstallTask.cpp
+ modplatform/ftb/FtbPrivatePackManager.h
+ modplatform/ftb/FtbPrivatePackManager.cpp
+
modplatform/ftb/PackHelpers.h
)
diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
index 67248f2c..19f6c31a 100644
--- a/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
+++ b/api/logic/modplatform/ftb/FtbPackFetchTask.cpp
@@ -1,16 +1,12 @@
#include "FtbPackFetchTask.h"
#include <QDomDocument>
-
-FtbPackFetchTask::FtbPackFetchTask()
-{
-}
-
-FtbPackFetchTask::~FtbPackFetchTask()
-{
-}
+#include "FtbPrivatePackManager.h"
void FtbPackFetchTask::fetch()
{
+ publicPacks.clear();
+ thirdPartyPacks.clear();
+
NetJob *netJob = new NetJob("FtbModpackFetch");
QUrl publicPacksUrl = QUrl("https://ftb.cursecdn.com/FTB2/static/modpacks.xml");
@@ -28,23 +24,67 @@ void FtbPackFetchTask::fetch()
netJob->start();
}
+void FtbPackFetchTask::fetchPrivate(const QStringList & toFetch)
+{
+ QString privatePackBaseUrl = QString("https://ftb.cursecdn.com/FTB2/static/%1.xml");
+
+ for (auto &packCode: toFetch)
+ {
+ QByteArray *data = new QByteArray();
+ NetJob *job = new NetJob("Fetching private pack");
+ job->addNetAction(Net::Download::makeByteArray(privatePackBaseUrl.arg(packCode), data));
+
+ QObject::connect(job, &NetJob::succeeded, this, [this, job, data, packCode]
+ {
+ FtbModpackList packs;
+ parseAndAddPacks(*data, FtbPackType::Private, packs);
+ foreach(FtbModpack currentPack, packs)
+ {
+ currentPack.packCode = packCode;
+ emit privateFileDownloadFinished(currentPack);
+ }
+
+ job->deleteLater();
+
+ data->clear();
+ delete data;
+ });
+
+ QObject::connect(job, &NetJob::failed, this, [this, job, packCode, data](QString reason)
+ {
+ emit privateFileDownloadFailed(reason, packCode);
+ job->deleteLater();
+
+ data->clear();
+ delete data;
+ });
+
+ job->start();
+ }
+}
+
void FtbPackFetchTask::fileDownloadFinished()
{
jobPtr.reset();
QStringList failedLists;
- if(!parseAndAddPacks(publicModpacksXmlFileData, FtbPackType::Public, publicPacks)) {
+ if(!parseAndAddPacks(publicModpacksXmlFileData, FtbPackType::Public, publicPacks))
+ {
failedLists.append(tr("Public Packs"));
}
- if(!parseAndAddPacks(thirdPartyModpacksXmlFileData, FtbPackType::ThirdParty, thirdPartyPacks)) {
+ 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 {
+ if(failedLists.size() > 0)
+ {
+ emit failed(tr("Failed to download some pack lists: %1").arg(failedLists.join("\n- ")));
+ }
+ else
+ {
emit finished(publicPacks, thirdPartyPacks);
}
}
@@ -57,15 +97,17 @@ bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType,
int errorLine = -1;
int errorCol = -1;
- if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol)){
- auto fullErrMsg = QString("Failed to fetch modpack data: %s %d:%d!").arg(errorMsg, errorLine, errorCol);
+ if(!doc.setContent(data, false, &errorMsg, &errorLine, &errorCol))
+ {
+ auto fullErrMsg = QString("Failed to fetch modpack data: %1 %2:3d!").arg(errorMsg, errorLine, errorCol);
qWarning() << fullErrMsg;
data.clear();
return false;
}
QDomNodeList nodes = doc.elementsByTagName("modpack");
- for(int i = 0; i < nodes.length(); i++) {
+ for(int i = 0; i < nodes.length(); i++)
+ {
QDomElement element = nodes.at(i).toElement();
FtbModpack modpack;
@@ -80,19 +122,25 @@ bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType,
modpack.bugged = false;
//remove empty if the xml is bugged
- for(QString curr : modpack.oldVersions) {
- if(curr.isNull() || curr.isEmpty()) {
+ for(QString curr : modpack.oldVersions)
+ {
+ if(curr.isNull() || curr.isEmpty())
+ {
modpack.oldVersions.removeAll(curr);
modpack.bugged = true;
qWarning() << "Removed some empty versions from" << modpack.name;
}
}
- if(modpack.oldVersions.size() < 1) {
- if(!modpack.currentVersion.isNull() && !modpack.currentVersion.isEmpty()) {
+ if(modpack.oldVersions.size() < 1)
+ {
+ if(!modpack.currentVersion.isNull() && !modpack.currentVersion.isEmpty())
+ {
modpack.oldVersions.append(modpack.currentVersion);
qWarning() << "Added current version to oldVersions because oldVersions was empty! (" + modpack.name + ")";
- } else {
+ }
+ else
+ {
modpack.broken = true;
qWarning() << "Broken pack:" << modpack.name << " => No valid version!";
}
@@ -111,7 +159,8 @@ bool FtbPackFetchTask::parseAndAddPacks(QByteArray &data, FtbPackType packType,
return true;
}
-void FtbPackFetchTask::fileDownloadFailed(QString reason){
- qWarning() << "Fetching FtbPacks failed: " << reason;
+void FtbPackFetchTask::fileDownloadFailed(QString reason)
+{
+ qWarning() << "Fetching FtbPacks failed:" << reason;
emit failed(reason);
}
diff --git a/api/logic/modplatform/ftb/FtbPackFetchTask.h b/api/logic/modplatform/ftb/FtbPackFetchTask.h
index c919a6e1..f955fe83 100644
--- a/api/logic/modplatform/ftb/FtbPackFetchTask.h
+++ b/api/logic/modplatform/ftb/FtbPackFetchTask.h
@@ -11,10 +11,11 @@ class MULTIMC_LOGIC_EXPORT FtbPackFetchTask : public QObject {
Q_OBJECT
public:
- FtbPackFetchTask();
- virtual ~FtbPackFetchTask();
+ FtbPackFetchTask() = default;
+ virtual ~FtbPackFetchTask() = default;
void fetch();
+ void fetchPrivate(const QStringList &toFetch);
private:
NetJobPtr jobPtr;
@@ -34,4 +35,6 @@ signals:
void finished(FtbModpackList publicPacks, FtbModpackList thirdPartyPacks);
void failed(QString reason);
+ void privateFileDownloadFinished(FtbModpack modpack);
+ void privateFileDownloadFailed(QString reason, QString packCode);
};
diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp
index 2340666d..9b7689d9 100644
--- a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp
+++ b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp
@@ -29,7 +29,15 @@ void FtbPackInstallTask::downloadPack()
NetJob *job = new NetJob("Download FTB Pack");
entry->setStale(true);
- QString url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1").arg(packoffset);
+ QString url;
+ if(m_pack.type == FtbPackType::Private)
+ {
+ url = QString("http://ftb.cursecdn.com/FTB2/privatepacks/%1").arg(packoffset);
+ }
+ else
+ {
+ url = QString("http://ftb.cursecdn.com/FTB2/modpacks/%1").arg(packoffset);
+ }
job->addNetAction(Net::Download::makeCached(url, entry));
archivePath = entry->getFullPath();
diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.h b/api/logic/modplatform/ftb/FtbPackInstallTask.h
index 64262688..3319025e 100644
--- a/api/logic/modplatform/ftb/FtbPackInstallTask.h
+++ b/api/logic/modplatform/ftb/FtbPackInstallTask.h
@@ -8,8 +8,8 @@
#include "meta/VersionList.h"
#include "modplatform/ftb/PackHelpers.h"
-class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask {
-
+class MULTIMC_LOGIC_EXPORT FtbPackInstallTask : public InstanceTask
+{
Q_OBJECT
public:
diff --git a/api/logic/modplatform/ftb/FtbPrivatePackManager.cpp b/api/logic/modplatform/ftb/FtbPrivatePackManager.cpp
new file mode 100644
index 00000000..15449592
--- /dev/null
+++ b/api/logic/modplatform/ftb/FtbPrivatePackManager.cpp
@@ -0,0 +1,36 @@
+#include "FtbPrivatePackManager.h"
+
+#include <QDebug>
+
+#include "FileSystem.h"
+
+void FtbPrivatePackManager::load()
+{
+ try
+ {
+ currentPacks = QString::fromUtf8(FS::read(m_filename)).split('\n', QString::SkipEmptyParts).toSet();
+ dirty = false;
+ }
+ catch(...)
+ {
+ currentPacks = {};
+ qWarning() << "Failed to read third party FTB pack codes from" << m_filename;
+ }
+}
+
+void FtbPrivatePackManager::save() const
+{
+ if(!dirty)
+ {
+ return;
+ }
+ try
+ {
+ FS::write(m_filename, currentPacks.toList().join('\n').toUtf8());
+ dirty = false;
+ }
+ catch(...)
+ {
+ qWarning() << "Failed to write third party FTB pack codes to" << m_filename;
+ }
+}
diff --git a/api/logic/modplatform/ftb/FtbPrivatePackManager.h b/api/logic/modplatform/ftb/FtbPrivatePackManager.h
new file mode 100644
index 00000000..388224d6
--- /dev/null
+++ b/api/logic/modplatform/ftb/FtbPrivatePackManager.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <QSet>
+#include <QString>
+#include <QFile>
+#include "multimc_logic_export.h"
+
+class MULTIMC_LOGIC_EXPORT FtbPrivatePackManager
+{
+public:
+ ~FtbPrivatePackManager()
+ {
+ save();
+ }
+ void load();
+ void save() const;
+ bool empty() const
+ {
+ return currentPacks.empty();
+ }
+ const QSet<QString> &getCurrentPackCodes() const
+ {
+ return currentPacks;
+ }
+ void add(const QString &code)
+ {
+ currentPacks.insert(code);
+ dirty = true;
+ }
+ void remove(const QString &code)
+ {
+ currentPacks.remove(code);
+ dirty = true;
+ }
+
+private:
+ QSet<QString> currentPacks;
+ QString m_filename = "private_packs.txt";
+ mutable bool dirty = false;
+};
diff --git a/api/logic/modplatform/ftb/PackHelpers.h b/api/logic/modplatform/ftb/PackHelpers.h
index 0b36f10b..4306caee 100644
--- a/api/logic/modplatform/ftb/PackHelpers.h
+++ b/api/logic/modplatform/ftb/PackHelpers.h
@@ -6,13 +6,15 @@
#include <QMetaType>
//Header for structs etc...
-enum FtbPackType {
+enum class FtbPackType
+{
Public,
ThirdParty,
Private
};
-struct FtbModpack {
+struct FtbModpack
+{
QString name;
QString description;
QString author;
@@ -30,6 +32,7 @@ struct FtbModpack {
bool broken = false;
FtbPackType type;
+ QString packCode;
};
//We need it for the proxy model