From 6122e0cbc3d10b64dbbe82f5a8f1f849bce7eeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 1 Jul 2013 00:45:32 +0200 Subject: Make downloader create folders as needed, test queuing, multiple files, saving to real files. --- asset_test.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/asset_test.cpp b/asset_test.cpp index 411e270d..7289f644 100644 --- a/asset_test.cpp +++ b/asset_test.cpp @@ -56,15 +56,21 @@ class DLJob : public QObject Q_OBJECT public: - DLJob ( QUrl what , QObject* parent = 0 ) : QObject(parent) + DLJob() : QObject(0) {} + DLJob (QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString() ) : QObject(0) { m_status = Dl_NotStarted; - m_downloads.append(DownloadablePtr(new Downloadable(what))); + append(url, rel_target_path, expected_md5); } DlStatus getStatus() { return m_status; } + void append (QUrl url, QString target = QString(), QString md5 = QString()) + { + Downloadable * dlable = new Downloadable(url, target, md5); + m_downloads.append(DownloadablePtr(dlable)); + } QByteArray getFirstFileData() { if(!m_downloads.size()) @@ -174,6 +180,20 @@ public: } } } + QFileInfo a(filename); + QDir dir; + if(!dir.mkpath(a.path())) + { + /* + * TODO: error when making the folder structure + */ + currentJob->emitFail(); + currentJob.clear(); + currentIndex = 0; + QTimer::singleShot(0, this, SLOT(startNextJob())); + + return; + } if (!currentOutput.open(QIODevice::WriteOnly)) { /* @@ -323,23 +343,44 @@ public slots: qDebug() << keyStr << " " << lastModStr << " " << etagStr << sizeStr; } - qApp->quit(); + } void fetchStarted() { - qDebug() << " Started downloading!"; + qDebug() << "Started downloading!"; + } + void googleFinished() + { + qDebug() << "yayayay google!"; + qApp->quit(); + } + void sadPanda() + { + qDebug() << "sad panda is sad :<"; + qApp->quit(); } public: void start() { + DLJob *gjob = new DLJob(); + gjob->append(QUrl("https://www.google.cz/"), "foo/bar/baz/index.html"); + gjob->append(QUrl("https://www.google.cz/"), "foo/bar/baz/lol.html"); + gjob->append(QUrl("https://www.google.cz/"), "foo/bar/baz/lolol.html"); + connect(gjob, SIGNAL(started()), SLOT(fetchStarted())); + connect(gjob, SIGNAL(failed()), SLOT(sadPanda())); + connect(gjob, SIGNAL(finished()), SLOT(googleFinished())); + google_job_ptr.reset(gjob); + DLJob *job = new DLJob(QUrl("http://s3.amazonaws.com/Minecraft.Resources/")); connect(job, SIGNAL(finished()), SLOT(fetchFinished())); connect(job, SIGNAL(started()), SLOT(fetchStarted())); jptr.reset(job); dl.enqueue(jptr); + dl.enqueue(google_job_ptr); } Downloader dl; DLJobPtr jptr; + DLJobPtr google_job_ptr; }; int main(int argc, char *argv[]) -- cgit v1.2.3