Skip to content

Commit

Permalink
fix game versions / dependencies of curseforge files
Browse files Browse the repository at this point in the history
  • Loading branch information
kaniol-lck committed Jun 4, 2024
1 parent c8dfe02 commit 2850591
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/curseforge/curseforgeapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Reply<CurseforgeFileInfo> CurseforgeAPI::getFileInfo(int id, int FileID)

Reply<QList<CurseforgeFileInfo> > CurseforgeAPI::getFiles(int id)
{
//TODO: page
QUrl url = PREFIX + "/v1/mods/" + QString::number(id) + "/files";

QNetworkRequest request(url);
Expand Down
20 changes: 4 additions & 16 deletions src/curseforge/curseforgedependencyinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@
CurseforgeDependencyInfo CurseforgeDependencyInfo::fromVariant(const QVariant &variant)
{
CurseforgeDependencyInfo info;
info.addonId_ = value(variant, "addonId").toInt();
info.fileId_ = value(variant, "fileId").toInt();
info.id_ = value(variant, "id").toInt();
info.type_ = static_cast<Type>(value(variant, "type").toInt());
info.modId_ = value(variant, "modId").toInt();
info.type_ = static_cast<Type>(value(variant, "relationType").toInt());
return info;
}

int CurseforgeDependencyInfo::addonId() const
int CurseforgeDependencyInfo::modId() const
{
return addonId_;
}

int CurseforgeDependencyInfo::fileId() const
{
return fileId_;
}

int CurseforgeDependencyInfo::id() const
{
return id_;
return modId_;
}

int CurseforgeDependencyInfo::type() const
Expand Down
8 changes: 2 additions & 6 deletions src/curseforge/curseforgedependencyinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ class CurseforgeDependencyInfo
CurseforgeDependencyInfo() = default;
static CurseforgeDependencyInfo fromVariant(const QVariant &variant);

int addonId() const;
int fileId() const;
int id() const;
int modId() const;
int type() const;

QString typeString() const;

private:
int addonId_ = 0;
int fileId_ = 0;
int id_ = 0;
int modId_ = 0;
Type type_;
};

Expand Down
4 changes: 2 additions & 2 deletions src/curseforge/curseforgefileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ CurseforgeFileInfo CurseforgeFileInfo::fromVariant(const QVariant &variant)
fileInfo.fileDate_ = value(variant, "fileDate").toDateTime();

//I don't know why curseforge put game verison and modloader together
for(auto &&version : value(variant, "sortableGameVersions").toStringList()){
for(auto &&version : value(variant, "gameVersions").toStringList()){
if(auto loaderType = ModLoaderType::fromString(version); loaderType != ModLoaderType::Any)
fileInfo.loaderTypes_ << loaderType;
else {
if(auto gameVersion = GameVersion::deduceFromString(version); gameVersion != GameVersion::Any)
fileInfo.gameVersions_ << gameVersion;
else
else //TODO: client/server
fileInfo.gameVersions_ << version;
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/curseforge/curseforgemodinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ CurseforgeModInfo CurseforgeModInfo::fromVariant(const QVariant &variant)
for(auto &&variant : value(variant, "latestFiles").toList())
modInfo.latestFileList_ << CurseforgeFileInfo::fromVariant(variant);

//latest file url
for(auto &&variant : value(variant, "gameVersionLatestFiles").toList())
modInfo.gameVersionLatestFiles_ << variant;

//categories
for(auto &&variant : value(variant, "categories").toList()){
auto category = CurseforgeCategoryInfo::fromVariant(variant);
Expand Down
1 change: 0 additions & 1 deletion src/curseforge/curseforgemodinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class CurseforgeModInfo : public CurseforgeModCacheInfo, Tagable
int downloadCount_;
QList<ModLoaderType::Type> loaderTypes_;
QList<CurseforgeFileInfo> latestFileList_;
QList<QVariant> gameVersionLatestFiles_;
QList<CurseforgeFileInfo> allFileList_;
QList<CurseforgeCategoryInfo> categories_;
QDateTime dateModified_;
Expand Down
14 changes: 3 additions & 11 deletions src/ui/curseforge/curseforgefileitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ CurseforgeFileItemWidget::CurseforgeFileItemWidget(CurseforgeFileListWidget *par
connect(menu, &QMenu::aboutToShow, this, [=]{
if(!menu->isEmpty()) return;
for(auto &dependencyInfo : fileInfo_.dependencies()){
if(dependencyInfo.addonId()){
auto action = menu->addAction(tr("%1 Mod: %2").arg(dependencyInfo.typeString()).arg(dependencyInfo.addonId()));
auto reply = CurseforgeAPI::api()->getInfo(dependencyInfo.addonId());
if(dependencyInfo.modId()){
auto action = menu->addAction(tr("%1 Mod: %2").arg(dependencyInfo.typeString()).arg(dependencyInfo.modId()));
auto reply = CurseforgeAPI::api()->getInfo(dependencyInfo.modId());
reply.setRunBackground(true);
reply.setOnFinished(this, [=](const CurseforgeModInfo &modInfo){
action->setText(tr("%1 Mod: %2").arg(dependencyInfo.typeString(), modInfo.name()));
Expand All @@ -103,14 +103,6 @@ CurseforgeFileItemWidget::CurseforgeFileItemWidget(CurseforgeFileListWidget *par
dialog->show();
});
});
if(dependencyInfo.fileId()){
auto reply = CurseforgeAPI::api()->getFileInfo(dependencyInfo.addonId(), dependencyInfo.fileId());
reply.setRunBackground(true);
reply.setOnFinished(this, [=](const CurseforgeFileInfo &fileInfo){
action->setText(action->text() + "\n" +
tr("%1 File: %2").arg(dependencyInfo.typeString(), fileInfo.fileName()));
});
}
}
}
});
Expand Down

0 comments on commit 2850591

Please sign in to comment.