aboutsummaryrefslogtreecommitdiff
path: root/api/logic/modplatform/flame/PackManifest.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-06-30 11:03:59 +0200
committerPetr Mrázek <peterix@gmail.com>2019-06-30 11:03:59 +0200
commit63330bf1113e0da3f2733ec9d6ad98fc13ad4bb7 (patch)
tree67c5f8a80cbc74e1cd58aa965a694311cf07b8ee /api/logic/modplatform/flame/PackManifest.cpp
parentf74e3db804f2fb3d73cbf7ab5fbdb12ecea0f259 (diff)
downloadPrismLauncher-63330bf1113e0da3f2733ec9d6ad98fc13ad4bb7.tar.gz
PrismLauncher-63330bf1113e0da3f2733ec9d6ad98fc13ad4bb7.tar.bz2
PrismLauncher-63330bf1113e0da3f2733ec9d6ad98fc13ad4bb7.zip
NOISSUE connect twitch URL resolving to modpack resolving. works now.
Diffstat (limited to 'api/logic/modplatform/flame/PackManifest.cpp')
-rw-r--r--api/logic/modplatform/flame/PackManifest.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/api/logic/modplatform/flame/PackManifest.cpp b/api/logic/modplatform/flame/PackManifest.cpp
index 0f57c9bc..1db0a161 100644
--- a/api/logic/modplatform/flame/PackManifest.cpp
+++ b/api/logic/modplatform/flame/PackManifest.cpp
@@ -64,3 +64,63 @@ void Flame::loadManifest(Flame::Manifest & m, const QString &filepath)
}
loadManifestV1(m, obj);
}
+
+bool Flame::File::parseFromBytes(const QByteArray& bytes)
+{
+ auto doc = Json::requireDocument(bytes);
+ auto obj = Json::requireObject(doc);
+ // result code signifies true failure.
+ if(obj.contains("code"))
+ {
+ qCritical() << "Resolving of" << projectId << fileId << "failed because of a negative result:";
+ qCritical() << bytes;
+ return false;
+ }
+ fileName = Json::requireString(obj, "FileNameOnDisk");
+ QString rawUrl = Json::requireString(obj, "DownloadURL");
+ url = QUrl(rawUrl, QUrl::TolerantMode);
+ if(!url.isValid())
+ {
+ throw JSONValidationError(QString("Invalid URL: %1").arg(rawUrl));
+ }
+ // This is a piece of a Flame project JSON pulled out into the file metadata (here) for convenience
+ // It is also optional
+ QJsonObject projObj = Json::ensureObject(obj, "_Project", {});
+ if(!projObj.isEmpty())
+ {
+ QString strType = Json::ensureString(projObj, "PackageType", "mod").toLower();
+ if(strType == "singlefile")
+ {
+ type = File::Type::SingleFile;
+ }
+ else if(strType == "ctoc")
+ {
+ type = File::Type::Ctoc;
+ }
+ else if(strType == "cmod2")
+ {
+ type = File::Type::Cmod2;
+ }
+ else if(strType == "mod")
+ {
+ type = File::Type::Mod;
+ }
+ else if(strType == "folder")
+ {
+ type = File::Type::Folder;
+ }
+ else if(strType == "modpack")
+ {
+ type = File::Type::Modpack;
+ }
+ else
+ {
+ qCritical() << "Resolving of" << projectId << fileId << "failed because of unknown file type:" << strType;
+ type = File::Type::Unknown;
+ return false;
+ }
+ targetFolder = Json::ensureString(projObj, "Path", "mods");
+ }
+ resolved = true;
+ return true;
+}