pollymc/api/logic/modplatform/ftb/FtbPackDownloader.cpp

58 lines
1.2 KiB
C++
Raw Normal View History

#include "FtbPackDownloader.h"
#include "PackHelpers.h"
#include "FtbPackFetchTask.h"
#include "Env.h"
2018-03-19 07:06:12 +05:30
FtbPackDownloader::FtbPackDownloader()
{
done = false;
fetching = false;
}
2018-03-19 07:06:12 +05:30
FtbPackDownloader::~FtbPackDownloader()
{
}
2018-03-19 07:06:12 +05:30
FtbModpackList FtbPackDownloader::getModpacks()
{
return static_cast<FtbModpackList>(fetchedPacks.values());
}
2018-03-19 07:06:12 +05:30
void FtbPackDownloader::fetchModpacks(bool force = false)
{
if(fetching || (!force && done))
{
qDebug() << "Skipping modpack refetch because done or already fetching [done =>" << done << "| fetching =>" << fetching << "]";
return;
}
fetching = true;
fetchTask = new FtbPackFetchTask();
connect(fetchTask, &FtbPackFetchTask::finished, this, &FtbPackDownloader::fetchSuccess);
connect(fetchTask, &FtbPackFetchTask::failed, this, &FtbPackDownloader::fetchFailed);
fetchTask->fetch();
}
2018-03-19 07:06:12 +05:30
void FtbPackDownloader::fetchSuccess(FtbModpackList modpacks)
{
for(int i = 0; i < modpacks.size(); i++)
{
fetchedPacks.insert(modpacks.at(i).name, modpacks.at(i));
}
fetching = false;
done = true;
emit ready();
fetchTask->deleteLater();
}
2018-03-19 07:06:12 +05:30
void FtbPackDownloader::fetchFailed(QString reason)
{
qWarning() << "Failed to fetch FtbData" << reason;
fetching = false;
emit packFetchFailed();
fetchTask->deleteLater();
}