fix: choose valid download url even if it's not the primary one
It seems to be possible to have modpack versions that have to primary file. In those cases, we pick a valid one "at random".
This commit is contained in:
parent
49de5d9b07
commit
4745ed2818
@ -81,14 +81,22 @@ auto loadIndexedVersion(QJsonObject &obj) -> ModpackVersion
|
|||||||
|
|
||||||
auto files = Json::requireArray(obj, "files");
|
auto files = Json::requireArray(obj, "files");
|
||||||
|
|
||||||
|
qWarning() << files;
|
||||||
|
|
||||||
for (auto file_iter : files) {
|
for (auto file_iter : files) {
|
||||||
File indexed_file;
|
File indexed_file;
|
||||||
auto parent = Json::requireObject(file_iter);
|
auto parent = Json::requireObject(file_iter);
|
||||||
if (!Json::ensureBoolean(parent, "primary", false)) {
|
auto is_primary = Json::ensureBoolean(parent, "primary", false);
|
||||||
|
if (!is_primary) {
|
||||||
|
auto filename = Json::ensureString(parent, "filename");
|
||||||
|
// Checking suffix here is fine because it's the response from Modrinth,
|
||||||
|
// so one would assume it will always be in English.
|
||||||
|
if(!filename.endsWith("mrpack") && !filename.endsWith("zip"))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.download_url = Json::requireString(parent, "url");
|
file.download_url = Json::requireString(parent, "url");
|
||||||
|
if(is_primary)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,5 +79,5 @@ auto loadIndexedVersion(QJsonObject&) -> ModpackVersion;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Modrinth::Modpack);
|
Q_DECLARE_METATYPE(Modrinth::Modpack)
|
||||||
Q_DECLARE_METATYPE(Modrinth::ModpackVersion);
|
Q_DECLARE_METATYPE(Modrinth::ModpackVersion)
|
||||||
|
Loading…
Reference in New Issue
Block a user