2013-06-30 20:39:57 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QtXml/QtXml>
|
2013-07-05 23:50:07 +00:00
|
|
|
#include "dlqueue.h"
|
2013-06-30 20:39:57 +00:00
|
|
|
|
|
|
|
inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname)
|
|
|
|
{
|
|
|
|
QDomNodeList elementList = parent.elementsByTagName(tagname);
|
|
|
|
if (elementList.count())
|
|
|
|
return elementList.at(0).toElement();
|
|
|
|
else
|
|
|
|
return QDomElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
class DlMachine : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public slots:
|
2013-07-04 22:57:20 +00:00
|
|
|
void filesFinished()
|
|
|
|
{
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
|
2013-06-30 20:39:57 +00:00
|
|
|
void fetchFinished()
|
|
|
|
{
|
2013-07-05 22:55:54 +00:00
|
|
|
JobPtr firstJob = index_job->getFirstJob();
|
|
|
|
auto DlJob = firstJob.dynamicCast<DownloadJob>();
|
|
|
|
QByteArray ba = DlJob->m_data;
|
2013-06-30 20:39:57 +00:00
|
|
|
|
|
|
|
QString xmlErrorMsg;
|
|
|
|
QDomDocument doc;
|
|
|
|
if (!doc.setContent(ba, false, &xmlErrorMsg))
|
|
|
|
{
|
|
|
|
qDebug() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" <<
|
|
|
|
xmlErrorMsg << ba;
|
|
|
|
}
|
|
|
|
QRegExp etag_match(".*([a-f0-9]{32}).*");
|
|
|
|
QDomNodeList contents = doc.elementsByTagName("Contents");
|
|
|
|
|
2013-07-05 22:55:54 +00:00
|
|
|
JobList *job = new JobList();
|
2013-07-04 22:57:20 +00:00
|
|
|
connect(job, SIGNAL(finished()), SLOT(filesFinished()));
|
|
|
|
|
2013-06-30 20:39:57 +00:00
|
|
|
for (int i = 0; i < contents.length(); i++)
|
|
|
|
{
|
|
|
|
QDomElement element = contents.at(i).toElement();
|
|
|
|
|
|
|
|
if (element.isNull())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QDomElement keyElement = getDomElementByTagName(element, "Key");
|
|
|
|
QDomElement lastmodElement = getDomElementByTagName(element, "LastModified");
|
|
|
|
QDomElement etagElement = getDomElementByTagName(element, "ETag");
|
|
|
|
QDomElement sizeElement = getDomElementByTagName(element, "Size");
|
|
|
|
|
|
|
|
if (keyElement.isNull() || lastmodElement.isNull() || etagElement.isNull() || sizeElement.isNull())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QString keyStr = keyElement.text();
|
|
|
|
QString lastModStr = lastmodElement.text();
|
|
|
|
QString etagStr = etagElement.text();
|
|
|
|
QString sizeStr = sizeElement.text();
|
|
|
|
|
|
|
|
//Filter folder keys
|
|
|
|
if (sizeStr == "0")
|
|
|
|
continue;
|
|
|
|
|
2013-07-04 22:57:20 +00:00
|
|
|
QString trimmedEtag = etagStr.remove('"');
|
|
|
|
QString prefix("http://s3.amazonaws.com/Minecraft.Resources/");
|
|
|
|
QString fprefix("assets/");
|
2013-07-05 22:55:54 +00:00
|
|
|
job->add(DownloadJob::create(QUrl(prefix + keyStr),fprefix + keyStr, trimmedEtag));
|
2013-06-30 20:39:57 +00:00
|
|
|
}
|
2013-07-04 22:57:20 +00:00
|
|
|
files_job.reset(job);
|
|
|
|
dl.enqueue(files_job);
|
2013-06-30 20:39:57 +00:00
|
|
|
}
|
|
|
|
void fetchStarted()
|
|
|
|
{
|
2013-06-30 22:45:32 +00:00
|
|
|
qDebug() << "Started downloading!";
|
|
|
|
}
|
2013-06-30 20:39:57 +00:00
|
|
|
public:
|
|
|
|
void start()
|
|
|
|
{
|
2013-07-05 22:55:54 +00:00
|
|
|
JobList *job = new JobList();
|
|
|
|
job->add(DownloadJob::create(QUrl("http://s3.amazonaws.com/Minecraft.Resources/")));
|
2013-06-30 20:39:57 +00:00
|
|
|
connect(job, SIGNAL(finished()), SLOT(fetchFinished()));
|
|
|
|
connect(job, SIGNAL(started()), SLOT(fetchStarted()));
|
2013-07-04 22:57:20 +00:00
|
|
|
index_job.reset(job);
|
|
|
|
dl.enqueue(index_job);
|
2013-06-30 20:39:57 +00:00
|
|
|
}
|
2013-07-05 22:55:54 +00:00
|
|
|
JobListQueue dl;
|
|
|
|
JobListPtr index_job;
|
|
|
|
JobListPtr files_job;
|
2013-06-30 20:39:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
|
|
|
DlMachine dl;
|
|
|
|
dl.start();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|
2013-07-04 22:57:20 +00:00
|
|
|
|
|
|
|
#include "asset_test.moc"
|