2018-03-01 00:12:30 +05:30
|
|
|
#include "FtbPackDownloader.h"
|
|
|
|
#include "PackHelpers.h"
|
|
|
|
#include "FtbPackFetchTask.h"
|
|
|
|
#include "Env.h"
|
|
|
|
|
2018-03-19 07:06:12 +05:30
|
|
|
FtbPackDownloader::FtbPackDownloader()
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
done = false;
|
|
|
|
fetching = false;
|
|
|
|
}
|
|
|
|
|
2018-03-19 07:06:12 +05:30
|
|
|
FtbPackDownloader::~FtbPackDownloader()
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
}
|
|
|
|
|
2018-03-19 07:06:12 +05:30
|
|
|
FtbModpackList FtbPackDownloader::getModpacks()
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
return static_cast<FtbModpackList>(fetchedPacks.values());
|
|
|
|
}
|
|
|
|
|
2018-03-19 07:06:12 +05:30
|
|
|
void FtbPackDownloader::fetchModpacks(bool force = false)
|
|
|
|
{
|
|
|
|
if(fetching || (!force && done))
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
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++)
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
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)
|
|
|
|
{
|
2018-03-01 00:12:30 +05:30
|
|
|
qWarning() << "Failed to fetch FtbData" << reason;
|
|
|
|
fetching = false;
|
|
|
|
emit packFetchFailed();
|
|
|
|
fetchTask->deleteLater();
|
|
|
|
}
|