ATLauncher: Parse keeps and deletes from pack manifests

This commit is contained in:
Jamie Mansfield 2022-05-21 19:11:37 +01:00
parent e0ae631d59
commit 9e69b8fe1b
No known key found for this signature in database
GPG Key ID: 36F61598F39F67B0
2 changed files with 87 additions and 0 deletions

View File

@ -224,6 +224,64 @@ static void loadVersionExtraArguments(ATLauncher::PackVersionExtraArguments& a,
a.depends = Json::ensureString(obj, "depends", "");
}
static void loadVersionKeep(ATLauncher::VersionKeep& k, QJsonObject& obj)
{
k.base = Json::requireString(obj, "base");
k.target = Json::requireString(obj, "target");
}
static void loadVersionKeeps(ATLauncher::VersionKeeps& k, QJsonObject& obj)
{
if (obj.contains("files")) {
auto files = Json::requireArray(obj, "files");
for (const auto keepRaw : files) {
auto keepObj = Json::requireObject(keepRaw);
ATLauncher::VersionKeep keep;
loadVersionKeep(keep, keepObj);
k.files.append(keep);
}
}
if (obj.contains("folders")) {
auto folders = Json::requireArray(obj, "folders");
for (const auto keepRaw : folders) {
auto keepObj = Json::requireObject(keepRaw);
ATLauncher::VersionKeep keep;
loadVersionKeep(keep, keepObj);
k.folders.append(keep);
}
}
}
static void loadVersionDelete(ATLauncher::VersionDelete& d, QJsonObject& obj)
{
d.base = Json::requireString(obj, "base");
d.target = Json::requireString(obj, "target");
}
static void loadVersionDeletes(ATLauncher::VersionDeletes& d, QJsonObject& obj)
{
if (obj.contains("files")) {
auto files = Json::requireArray(obj, "files");
for (const auto deleteRaw : files) {
auto deleteObj = Json::requireObject(deleteRaw);
ATLauncher::VersionDelete versionDelete;
loadVersionDelete(versionDelete, deleteObj);
d.files.append(versionDelete);
}
}
if (obj.contains("folders")) {
auto folders = Json::requireArray(obj, "folders");
for (const auto deleteRaw : folders) {
auto deleteObj = Json::requireObject(deleteRaw);
ATLauncher::VersionDelete versionDelete;
loadVersionDelete(versionDelete, deleteObj);
d.folders.append(versionDelete);
}
}
}
void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
{
v.version = Json::requireString(obj, "version");
@ -284,4 +342,10 @@ void ATLauncher::loadVersion(PackVersion & v, QJsonObject & obj)
auto messages = Json::ensureObject(obj, "messages");
loadVersionMessages(v.messages, messages);
auto keeps = Json::ensureObject(obj, "keeps");
loadVersionKeeps(v.keeps, keeps);
auto deletes = Json::ensureObject(obj, "deletes");
loadVersionDeletes(v.deletes, deletes);
}

View File

@ -150,6 +150,26 @@ struct VersionMessages
QString update;
};
struct VersionKeep {
QString base;
QString target;
};
struct VersionKeeps {
QVector<VersionKeep> files;
QVector<VersionKeep> folders;
};
struct VersionDelete {
QString base;
QString target;
};
struct VersionDeletes {
QVector<VersionDelete> files;
QVector<VersionDelete> folders;
};
struct PackVersionMainClass
{
QString mainClass;
@ -178,6 +198,9 @@ struct PackVersion
QMap<QString, QString> colours;
QMap<QString, QString> warnings;
VersionMessages messages;
VersionKeeps keeps;
VersionDeletes deletes;
};
void loadVersion(PackVersion & v, QJsonObject & obj);