size_t FileDownloader::write_data(void *ptr, size_t size, size_t nmemb, void *fileDownloader) { FileDownloader * fd = (FileDownloader*)fileDownloader; File * destFile = fd->fileForWrite; int written = destFile->Write(ptr, size * nmemb); if ( fd->delegate != NULL ) { fd->delegate->DownloadGetPacket(written); } // Pause & resume download if ( fd->state == FD_PAUSE && !fd->isPauseChangeApplied ) { curl_easy_pause( fd->GetCurlHandler(), CURLPAUSE_ALL ); fd->isPauseChangeApplied = true; Logger::Instance()->Debug(" ----- Downloader pause"); } // Stop download if ( fd->state == FD_STOP ) { return CURL_READFUNC_ABORT; } return written; }
void DownloadsManager::downloadFile(QString token, QString id, QString fileName) { if (!downloadDir.exists(fileName)) { FileDownloader* t = new FileDownloader(fileName, this); connect(t, SIGNAL(fileDownloaded()), this, SLOT(fileDownloaded())); t->startDownload(token, id); } else fileDownloaded(); }
QList<QList<QString> > YandexmusicApi::getAlbumInfo(const QString &name) { QList<QList<QString> > albumInfo{{}}; FileDownloader *fd = new FileDownloader(QUrl(QString("https://music.yandex.ru/handlers/search.jsx?text=%1&type=albums").arg(name))); QJsonDocument jsonDoc = QJsonDocument::fromJson(fd->downloadedData()); fd->~FileDownloader(); albumInfo[0].append(QString::number(jsonDoc.object().value("counts").toObject().value("artists").toDouble())); albumInfo[0].append(QString::number(jsonDoc.object().value("counts").toObject().value("albums").toDouble())); albumInfo[0].append(QString::number(jsonDoc.object().value("counts").toObject().value("tracks").toDouble())); QList<QString> tmp {}; for(int i = 0; i < jsonDoc.object().value("albums").toObject().value("items").toArray().count(); i++) { tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("id").toDouble()); tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("storageDir").toString(); tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("title").toString(); tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("year").toDouble()); tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("coverUri").toString(); tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("artists").toObject().value("id").toDouble()); tmp << jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("artists").toObject().value("name").toString(); tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("trackCount").toDouble()); tmp << QString::number(jsonDoc.object().value("albums").toObject().value("items").toArray().at(i).toObject().value("genre").toDouble()); albumInfo << tmp; tmp.clear(); } return albumInfo; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); FileDownloader w; w.show(); w.download(QUrl("http://smplayer.berlios.de/downloads.php?tr_lang=es")); return w.exec(); }
DWORD Application_ClientConfigManager::visitUrl(Url* url, DWORD* minorError) { DWORD status = CAPTURE_VISITATION_OK; stdext::hash_map<wstring, APPLICATION*>::iterator it; it = applicationsMap.find(url->getApplicationName()); if(it != applicationsMap.end()) { // Download file to temp directory if required FileDownloader* downloader = new FileDownloader(); wstring file = url->getUrl().substr(url->getUrl().find_last_of(L"\\")); DWORD downloadStatus = 0; if((downloadStatus = downloader->Download(url->getUrl(), &file)) > 0) { *minorError = downloadStatus; return CAPTURE_VISITATION_NETWORK_ERROR; } PAPPLICATION pApplication = it->second; STARTUPINFO siStartupInfo; PROCESS_INFORMATION piProcessInfo; memset(&siStartupInfo, 0, sizeof(siStartupInfo)); memset(&piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); wstring processCommand = L"\""; processCommand += pApplication->path; processCommand += L"\" "; processCommand += url->getUrl(); BOOL created = CreateProcess(NULL,(LPWSTR)processCommand.c_str(), 0, 0, FALSE, CREATE_DEFAULT_ERROR_MODE, 0, 0, &siStartupInfo, &piProcessInfo); if(created == FALSE) { status = CAPTURE_VISITATION_PROCESS_ERROR; *minorError = GetLastError(); } else { Sleep(url->getVisitTime()*1000); bool processClosed = closeProcess(piProcessInfo.dwProcessId, minorError); if(!processClosed) { status = CAPTURE_VISITATION_PROCESS_ERROR; } Sleep(1000); } } else { status = CAPTURE_VISITATION_PROCESS_ERROR; *minorError = CAPTURE_PE_PROCESS_PATH_NOT_FOUND; } return status; }
void UpdateChecker::checkForUpdates() { FileDownloader *downloader = new FileDownloader(); connect(downloader, SIGNAL(downloadCompleted(QByteArray)), this, SLOT(xmlDownloaded(QByteArray))); connect(downloader, SIGNAL(downloadFailed()), this, SIGNAL(updateIsNotAvailable())); downloader->startDownload(application.updateXmlUrl); }
static void NM_OnData(struct _netdownloader *nd, char *data, u32 data_size) { FileDownloader *dnload; dnload = (FileDownloader *)nd->user_cbck; if (dnload->OnData) { /*send prog*/ dnload->OnData(dnload->usr_cbk, data, data_size); } }
/*! Returns a new instance of a KDUpdater::FileDownloader subclass. The instantiation of a subclass depends on the communication protocol string stored in \a scheme with the parent \a parent. \note Ownership of the created object remains with the programmer. */ FileDownloader *FileDownloaderFactory::create(const QString &scheme, QObject *parent) const { FileDownloader *downloader = GenericFactory<FileDownloader, QString, QObject*>::create(scheme, parent); if (downloader != 0) { downloader->setFollowRedirects(d->m_followRedirects); downloader->setIgnoreSslErrors(d->m_ignoreSslErrors); if (d->m_factory) downloader->setProxyFactory(d->m_factory->clone()); } return downloader; }
static Eina_Bool _complete_cb(void *data, int type, void *event) { Ecore_Con_Event_Url_Complete *ev = reinterpret_cast<Ecore_Con_Event_Url_Complete *>(event); FileDownloader *fd = reinterpret_cast<FileDownloader *>(data); if (data == ecore_con_url_data_get(ev->url_con)) { fd->completeCb(ev->status); } return ECORE_CALLBACK_RENEW; }
static Eina_Bool _progress_cb(void *data, int type, void *event) { Ecore_Con_Event_Url_Progress *ev = reinterpret_cast<Ecore_Con_Event_Url_Progress *>(event); FileDownloader *fd = reinterpret_cast<FileDownloader *>(data); if (data == ecore_con_url_data_get(ev->url_con)) { fd->progressCb(ev->down.now, ev->down.total); } return ECORE_CALLBACK_RENEW; }
bool ActionMail::Execute() { IPCam *camera = NULL; if (mail_attachment != "") camera = dynamic_cast<IPCam *>(ListeRoom::Instance().get_io(mail_attachment)); if (camera) { cInfoDom("rule.action.mail") << "Need to download camera (" << camera->get_param("name") << ") attachment"; std::string tmpFile; int cpt = 0; //Get a temporary filename do { tmpFile = "/tmp/calaos_mail_attachment_"; tmpFile += Utils::to_string(cpt); cpt++; } while (ecore_file_exists(tmpFile.c_str())); // Autodestroy file downloader cDebug() << "DL URL: " << camera->getPictureUrl(); FileDownloader* downloader = new FileDownloader(camera->getPictureUrl(), tmpFile, true); downloader->addCallback([=](std::string signal, void *sender_data) { if (signal == "done") { mail_attachment_tfile = *(reinterpret_cast<std::string *>(sender_data)); sendMail(); } else if (signal == "failed" || signal == "aborted") { mail_attachment_tfile.clear(); sendMail(); } }); downloader->Start(); } else { sendMail(); cInfoDom("rule.action.mail") << "Ok, mail is in queue"; } return true; }
QString YandexmusicApi::getTrackUrl(const QString &storageDir) { FileDownloader *fd = new FileDownloader(QUrl(QString("https://storage.mds.yandex.net/download-info/%1/2?format=json").arg(storageDir))); QJsonDocument jsonDoc = QJsonDocument::fromJson(fd->downloadedData()); fd->~FileDownloader(); QByteArray h = QCryptographicHash::hash("XGRlBW9FXlekgbPrRHuSiA" + jsonDoc.object().value("path").toString().mid(1).toUtf8() + jsonDoc.object().value("s").toString().toUtf8(), QCryptographicHash::Md5); return QString("https://") + jsonDoc.object().value("host").toString() + "/get-mp3/" + QString(h.toHex()) + QString("/") + jsonDoc.object().value("ts").toString() + jsonDoc.object().value("path").toString(); }
void BrowserDialog::download(const QUrl& url) { m_ui->webView->stop(); m_ui->webView->hide(); m_ui->progressBar->hide(); m_ui->listWidget->show(); FileDownloader* downloader = new FileDownloader(this); connect(downloader, SIGNAL(message(QMessageBox::Icon,QString)), SLOT(showMessage(QMessageBox::Icon,QString))); connect(downloader, SIGNAL(finished(bool)), SLOT(downloadFinished(bool))); connect(downloader, SIGNAL(finished(bool)), downloader, SLOT(deleteLater())); downloader->download(url); }
DownloadWindow::DownloadWindow(QUrl updatePackage, QWidget *parent) : QMainWindow(parent), ui(new Ui::DownloadWindow) { ui->setupUi(this); FileDownloader *downloader = new FileDownloader(); connect(downloader, SIGNAL(downloadCompleted(QByteArray)), this, SLOT(downloadingFinished())); connect(downloader, SIGNAL(downloadFailed()), this, SLOT(downloadingFailed())); downloader->startDownload(updatePackage, QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/software-update-package.exe"); }
void BrowserDialog::downloadFinished(bool succ) { FileDownloader* downloader = qobject_cast< FileDownloader* >(sender()); if (!succ) { return; } QString fileName = downloader->fileName(); ScelConverter* converter = new ScelConverter(this); connect(converter, SIGNAL(message(QMessageBox::Icon,QString)), SLOT(showMessage(QMessageBox::Icon,QString))); connect(converter, SIGNAL(finished(bool)), SLOT(convertFinished(bool))); connect(converter, SIGNAL(finished(bool)), converter, SLOT(deleteLater())); converter->convert(fileName, m_name.append(".txt")); }
FileDownloader *FileDownloaderFactory::create(const QString &scheme, const SignatureVerifier *verifier, const QUrl &signatureUrl, QObject *parent) const { FileDownloader *downloader = KDGenericFactory<FileDownloader>::create(scheme); if (downloader != 0) { downloader->setParent(parent); downloader->setFollowRedirects(d->m_followRedirects); if (d->m_factory) downloader->setProxyFactory(d->m_factory->clone()); } if (!verifier) return downloader; SignatureVerificationDownloader *svdl = new SignatureVerificationDownloader(downloader, parent); svdl->setSignatureVerifier(verifier); svdl->setSignatureUrl(signatureUrl); return svdl; }
void QGitHubReleaseAPIPrivate::downloaded(const FileDownloader &fd) { QObject::connect(m_apiDownloader, SIGNAL(error(QString)), this, SLOT(fdError(QString))); QObject::connect(m_apiDownloader, SIGNAL(downloaded(FileDownloader)), this, SLOT(downloaded(FileDownloader))); QObject::connect(m_apiDownloader, SIGNAL(progress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); m_jsonData = fd.downloadedData(); foreach(const FileDownloader::RAWHEADERPAIR &pair, fd.rawHeaderPairs()) { if(pair.first == "ETag") m_eTag = pair.second.mid(2); if(pair.first == "X-RateLimit-Reset") { m_rateLimitReset = QDateTime::fromTime_t(QString(pair.second).toUInt()); } if(pair.first == "X-RateLimit-Limit") m_rateLimit = QString(pair.second).toUInt(); if(pair.first == "X-RateLimit-Remaining") { m_rateLimitRemaining = QString(pair.second).toUInt(); } } QVariant va(parseJSon(m_jsonData, m_errorString)); if(m_errorString.isNull()) { if(m_singleEntryRequested) { m_vdata.append(va); } else if((m_vdata = va.toList()).isEmpty()) { m_errorString = va.toMap()["message"].toString(); emit error(m_errorString); return; } emit available(); } else { emit error(m_errorString); } }
void FileDownloaderHandler::startNewDownload() { if(m_outstandingDownloads < 1 && !m_fileDownloaderQueue.isEmpty()) { QThread* thread = new QThread(); FileDownloader* fd = new FileDownloader(); fd->moveToThread(thread); thread->start(); connect(this, SIGNAL(startDownload(QString,QString,QString)), fd, SLOT(downloadFile(QString,QString,QString))); connect(fd, SIGNAL(fileSaved(QString, QString)), this, SLOT(downloadComplete(QString, QString))); connect(fd, SIGNAL(fileSaved(QString, QString)), thread, SLOT(quit())); connect(thread, &QThread::finished, thread, &QThread::deleteLater); FileInfoStruct fis = m_fileDownloaderQueue.dequeue(); // QString currentBaseUrl = fis.currentBaseUrl; // QString fileName = fis.fileName; // QString savePath = fis.savePath; qDebug() << fis.fileName; emit startDownload(fis.currentBaseUrl, fis.fileName, fis.savePath); m_outstandingDownloads++; } }
int testWebServer() { std::cerr << "Testing Webserver..." << std::endl; ProgramOptions::getInstance()->webserver_public_html_folder = "./gui/"; HttpServerThread<BikerHttpRequestProcessor> server(8081); server.startServer(); //todo: aufs hochfahren warten toller lösen als so FileDownloader downloader; QByteArray gui_html = downloader.downloadURL(QUrl("http://localhost:8081/files/gui.html")); CHECK(gui_html.size()>0); QByteArray marker_red_png = downloader.downloadURL(QUrl("http://localhost:8081/files/img/marker-red.png")); CHECK(marker_red_png.size()>0); QByteArray bad_request_404 = downloader.downloadURL(QUrl("http://localhost:8081/files/lalala")); //QByteArray wird leer sein, wenn die Datei nicht heruntergeladen wurde CHECK_EQ(bad_request_404.size(), 0); QRegExp cloudmadeApiKeyRegExp("/([\\da-fA-F]{1,64})/(?:api|API)/0.(\\d)"); QRegExp cloudmadeApiPointListRegExp("/(?:(\\d{1,3}.\\d{1,10}),(\\d{1,3}.\\d{1,10})),(?:\\[(?:(\\d{1,3}.\\d{1,10}),(\\d{1,3}.\\d{1,10}))(?:,(?:(\\d{1,3}.\\d{1,10}),(\\d{1,3}.\\d{1,10}))){0,20}\\],)?(?:(\\d{1,3}.\\d{1,10}),(\\d{1,3}.\\d{1,10}))"); QRegExp cloudmadeApiRouteTypeRegExp("/([a-zA-Z0-9]{1,64})(/([a-zA-Z0-9]{1,64}))?.(gpx|GPX|js|JS)"); //http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/51.22545,4.40730,%5B51.22,4.41,51.2,4.41%5D,51.23,4.42/car.js?lang=de&units=miles //http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/47.25976,9.58423,47.26117,9.59882/bicycle.gpx //http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/47.25976,9.58423,47.26117,9.59882/car/shortest.js QString line = "http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/51.22545,4.40730,[51.22,4.41,51.2,4.41,51.22,4.41,51.2,4.41],51.23,4.42/car.js"; int i=0; i=cloudmadeApiKeyRegExp.indexIn(line, i); CHECK(i!=-1); i=cloudmadeApiPointListRegExp.indexIn(line, i); CHECK(i!=-1); i=cloudmadeApiRouteTypeRegExp.indexIn(line, i); CHECK(i!=-1); server.wait(100); return EXIT_SUCCESS; }
void WebBridgeRS::onUrlDownloaded(){ FileDownloader * fileDownloader = qobject_cast<FileDownloader *>(QObject::sender()); //QDir::absoluteFilePath() QString fpath = getDownloadDirectory(); fpath.append("/"); QString urlstring(fileDownloader->url().toString()); fpath.append(QFileInfo(urlstring).fileName()); std::cout << fpath.toStdString() << std::endl; QFile file(fpath); file.open(QIODevice::WriteOnly); file.write(fileDownloader->downloadedData()); // optional, as QFile destructor will already do it: file.close(); std::cout << fileDownloader->downloadedData().data() << std::endl; emit urlDownloaded(fpath, urlstring); }
void ActivityWebView::buttonCallback(void *data, Evas_Object *edje_object, string emission, string source) { if (source == "button.back") elm_web_back(web); else if (source == "button.forward") elm_web_forward(web); else if (source == "button.reload") elm_web_reload_full(web); else if (source == "button.stop") elm_web_stop(web); else if (source == "button.forward") elm_web_forward(web); else if (source == "button.home") goToCallback(DEFAULT_BROWSER_URL); else if (source == "button.go") { ApplicationMain::Instance().ShowKeyboard("Entrez une URL ci-dessous", sigc::mem_fun(*this, &ActivityWebView::goToCallback), false, elm_web_uri_get(web)); } else if (source == "button.bookmark") { string url = elm_web_uri_get(web); string _url = DEFAULT_BROWSER_URL; _url += "Bookmark.php?new=" + url_encode(url); _url += "&title=" + url_encode(elm_web_title_get(web)); _url += "&thumb_file=/tmp/thumb.png"; setDragValue("progress.level", 0.0, 0.0); setPartText("progress.text", "Saving..."); EmitSignal("saving,bookmark", "calaos"); FileDownloader *fdownloader = new FileDownloader(_url, "/dev/null", true); fdownloader->Start(); } }
bool FileDownloader::downloadUrl(QString urlStr, QByteArray &data) { FileDownloader fd; fd.startDownloadAsync(urlStr); Q_ASSERT(fd.lastError() == result_code::Type::Invalid); while (fd.lastError() == result_code::Type::Invalid || fd.lastError() == result_code::Type::InProgress) qApp->processEvents(); data = fd.downloadedData(); return result_code::succeeded(fd.lastError()); }
void StartDownloading() { _state = CACHE_ENTRY_STATE_DOWNLOADING; _downloader->DownloadImage(this); }
void Application_ClientConfigManager::visitGroup(VisitEvent* visitEvent) { DWORD status = CAPTURE_VISITATION_OK; stdext::hash_map<wstring, APPLICATION*>::iterator it; it = applicationsMap.find(visitEvent->getProgram()); if(it != applicationsMap.end()) { const size_t size = visitEvent->getUrls().size(); std::vector<ProcessHandler*> processHandlers(size); bool error = false; for(unsigned int i = 0; i < visitEvent->getUrls().size(); i++) { // Download file to temp directory if required Url* url = visitEvent->getUrls()[i]; wstring url_path = url->getUrl(); if(it->second->downloadURL) { FileDownloader* downloader = new FileDownloader(); wstring file = url->getUrl().substr(url->getUrl().find_last_of(L"/")); DWORD downloadStatus = 0; if((downloadStatus = downloader->Download(url->getUrl(), &file)) > 0) { visitEvent->setErrorCode(CAPTURE_VISITATION_NETWORK_ERROR); url->setMajorErrorCode(CAPTURE_VISITATION_NETWORK_ERROR); url->setMinorErrorCode(downloadStatus); continue; } else { url_path = file; } } PAPPLICATION pApplication = it->second; wstring cmd = pApplication->path; wstring param = url_path; ProcessHandler *ph = new ProcessHandler(cmd,param); processHandlers[i] = ph; ph->executeProcess(); url->setProcessId(ph->getProcessId()); if(i==0) { Sleep(2000); } double maxWaitTimeInSec = 60; double waitTimeInSec = 0; bool isOpen = ph->isOpen(); while(!isOpen && waitTimeInSec < maxWaitTimeInSec) { Sleep(100); waitTimeInSec = waitTimeInSec + 0.1; isOpen = ph->isOpen(); } if(waitTimeInSec >= maxWaitTimeInSec) { visitEvent->setErrorCode(CAPTURE_VISITATION_PROCESS_ERROR); url->setMajorErrorCode(CAPTURE_VISITATION_PROCESS_ERROR); url->setMinorErrorCode(GetLastError()); error = true; printf("Error opening app"); } else { ;//printf("Successfully opened app"); } } if(!error) { int sleepTimeInSec = visitEvent->getUrls()[0]->getVisitTime(); Sleep(sleepTimeInSec*1000); } for(unsigned int i = 0; i < visitEvent->getUrls().size(); i++) { DWORD minorError = 0; Url* url = visitEvent->getUrls()[i]; ProcessHandler *ph = processHandlers[i]; ph->closeProcess(); double maxWaitTimeInSec = 30; double waitTimeInSec = 0; bool isOpen = ph->isOpen(); while(isOpen && waitTimeInSec < maxWaitTimeInSec) { Sleep(100); waitTimeInSec = waitTimeInSec + 0.1; isOpen = ph->isOpen(); } if(waitTimeInSec >= maxWaitTimeInSec) { visitEvent->setErrorCode(CAPTURE_VISITATION_PROCESS_ERROR); url->setMajorErrorCode(CAPTURE_VISITATION_PROCESS_ERROR); url->setMinorErrorCode(minorError); } else { ;//printf("Successfully closed app"); } } //delete [] processHandlers; } else { visitEvent->setErrorCode(CAPTURE_VISITATION_PROCESS_ERROR); //url->setMajorErrorCode(CAPTURE_VISITATION_PROCESS_ERROR); //url->setMinorErrorCode(CAPTURE_PE_PROCESS_PATH_NOT_FOUND); } }
void FileDownloader::cancel(const FileDownloader &fd) { fd.abort(); }
void Calaos::CallUrl(string url, string post_data) { FileDownloader *downloader = new FileDownloader(url, post_data, "text/plain", true); downloader->Start(); }
static void NM_OnState(struct _netdownloader *nd) { FileDownloader *dnload; dnload = (FileDownloader *)nd->user_cbck; if (dnload->OnState) dnload->OnState(dnload->usr_cbk); }