Merge pull request #296 from flowln/right_file

Use primary file for mod downloading on Modrinth
This commit is contained in:
Ezekiel Smith 2022-03-19 11:41:36 +11:00 committed by Sefa Eyeoglu
parent 6d9eaee7f9
commit 025a3cf730
No known key found for this signature in database
GPG Key ID: C10411294912A422

View File

@ -51,31 +51,32 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray
auto files = Json::requireArray(obj, "files"); auto files = Json::requireArray(obj, "files");
int i = 0; int i = 0;
while (files.count() > 1 && i < files.count()){
//try to resolve the correct file // Find correct file (needed in cases where one version may have multiple files)
// Will default to the last one if there's no primary (though I think Modrinth requires that
// at least one file is primary, idk)
while (i < files.count()){
auto parent = files[i].toObject(); auto parent = files[i].toObject();
auto fileName = Json::requireString(parent, "filename"); auto fileName = Json::requireString(parent, "filename");
//avoid grabbing "dev" files
if(fileName.contains("javadocs",Qt::CaseInsensitive) || fileName.contains("sources",Qt::CaseInsensitive)){ // Grab the correct mod loader
if(hasFabric){
if(fileName.contains("forge",Qt::CaseInsensitive)){
i++;
continue;
}
} else if(fileName.contains("fabric", Qt::CaseInsensitive)){
i++; i++;
continue; continue;
} }
//grab the correct mod loader
if(fileName.contains("forge",Qt::CaseInsensitive) || fileName.contains("fabric",Qt::CaseInsensitive) ){ // Grab the primary file, if available
if(hasFabric){ if(Json::requireBoolean(parent, "primary"))
if(fileName.contains("forge",Qt::CaseInsensitive)){ break;
i++;
continue; i++;
}
}else{
if(fileName.contains("fabric",Qt::CaseInsensitive)){
i++;
continue;
}
}
}
break;
} }
auto parent = files[i].toObject(); auto parent = files[i].toObject();
if(parent.contains("url")) { if(parent.contains("url")) {
file.downloadUrl = Json::requireString(parent, "url"); file.downloadUrl = Json::requireString(parent, "url");