void NodeVersionLoader::startDownload() { auto self = shared_from_this(); checkThread(); auto& item = currentDownloadItem(); { std::lock_guard<std::mutex> lock(downloadQueueMutex); --item.retryCount; } state = State::Connecting; log.setChannel("Download:" + item.version); std::string fileName; auto ver = item.version; try { onNeedsDownloadFileName(ver, fileName); if (fileName.empty()) { MSCThrow(InvalidOperationException("File name is empty.")); } } catch (...) { downloadFailed("Failed to determine the downloaded file path.: " + boost::current_exception_diagnostic_information()); return; } try { file.reset(new std::ofstream(fileName.c_str(), std::ios::out | std::ios::trunc | std::ios::binary)); file->exceptions(std::ios::failbit | std::ios::badbit); } catch (...) { file.reset(); downloadFailed("Failed to open the destination file '" + fileName + "'.: " + boost::current_exception_diagnostic_information()); return; } BOOST_LOG_SEV(log, LogLevel::Info) << "Connecting to the master server."; socket.async_connect(endpoint, [this, self, &item](const error_code& error) { checkThread(); if (disposed) { downloadCancelled(); return; } if (error) { downloadFailed(error.message()); return; } sendHeader(); }); }
void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = response; m_download->didReceiveResponse(response); if (response.httpStatusCode() >= 400) { downloadFailed(platformDownloadNetworkError(response.httpStatusCode(), response.url(), response.httpStatusText())); return; } String suggestedFilename = response.suggestedFilename(); if (suggestedFilename.isEmpty()) { URL url = response.url(); url.setQuery(String()); url.removeFragmentIdentifier(); suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); } String destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, m_allowOverwrite); if (destinationURI.isEmpty()) { #if PLATFORM(GTK) GUniquePtr<char> buffer(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); String errorMessage = String::fromUTF8(buffer.get()); #else String errorMessage = makeString("Cannot determine destination URI for download with suggested filename ", suggestedFilename); #endif downloadFailed(platformDownloadDestinationError(response, errorMessage)); return; } m_destinationFile = adoptGRef(g_file_new_for_uri(destinationURI.utf8().data())); GRefPtr<GFileOutputStream> outputStream; GUniqueOutPtr<GError> error; if (m_allowOverwrite) outputStream = adoptGRef(g_file_replace(m_destinationFile.get(), nullptr, FALSE, G_FILE_CREATE_NONE, nullptr, &error.outPtr())); else outputStream = adoptGRef(g_file_create(m_destinationFile.get(), G_FILE_CREATE_NONE, nullptr, &error.outPtr())); if (!outputStream) { m_destinationFile.clear(); downloadFailed(platformDownloadDestinationError(response, error->message)); return; } String intermediateURI = destinationURI + ".wkdownload"; m_intermediateFile = adoptGRef(g_file_new_for_uri(intermediateURI.utf8().data())); m_outputStream = adoptGRef(g_file_replace(m_intermediateFile.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); if (!m_outputStream) { downloadFailed(platformDownloadDestinationError(response, error->message)); return; } m_download->didCreateDestination(destinationURI); }
void NodeVersionLoader::receiveHeader() { auto self = shared_from_this(); checkThread(); auto& item = currentDownloadItem(); state = State::ReceivingHeader; auto buf = std::make_shared<std::uint64_t>(); timer.expires_from_now(boost::posix_time::seconds(8)); timer.async_wait([this, self] (const error_code& error) { if (error) { return; } if (disposed) { return; } if (state == State::ReceivingHeader) { BOOST_LOG_SEV(log, LogLevel::Warn) << "Timed out."; socket.cancel(); } }); asio::async_read(socket, asio::buffer(buf.get(), 8), [this, self, &item, buf](const error_code& error, std::size_t) { checkThread(); if (disposed) { downloadCancelled(); return; } if (error) { downloadFailed(error.message()); return; } timer.cancel(); auto size = *buf; if (size == 0) { downloadFailed("Version cannot be downloaded for some reason."); return; } receiveData(size); }); }
void AddNewTorrentDialog::show(QString source, QWidget *parent) { AddNewTorrentDialog *dlg = new AddNewTorrentDialog(parent); if (Utils::Misc::isUrl(source)) { // Launch downloader Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true); connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString))); connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString))); connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString))); } else { bool ok = false; BitTorrent::MagnetUri magnetUri(source); if (magnetUri.isValid()) ok = dlg->loadMagnet(magnetUri); else ok = dlg->loadTorrent(source); if (ok) dlg->open(); else delete dlg; } }
void FileDownloader::onDownloadFailed(QNetworkReply::NetworkError code) { m_lastError = result_code::Type::NetworkError; // FIXME: map the NetworkError to the ResultCode emit downloadFailed(result_code::Type::NetworkError/*, code*/); }
void AddNewTorrentDialog::show(QString source, QWidget *parent) { if (source.startsWith("bc://bt/", Qt::CaseInsensitive)) { qDebug("Converting bc link to magnet link"); source = Utils::Misc::bcLinkToMagnet(source); } AddNewTorrentDialog *dlg = new AddNewTorrentDialog(parent); if (Utils::Misc::isUrl(source)) { // Launch downloader Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true, 10485760 /* 10MB */, true); connect(handler, SIGNAL(downloadFinished(QString, QString)), dlg, SLOT(handleDownloadFinished(QString, QString))); connect(handler, SIGNAL(downloadFailed(QString, QString)), dlg, SLOT(handleDownloadFailed(QString, QString))); connect(handler, SIGNAL(redirectedToMagnet(QString, QString)), dlg, SLOT(handleRedirectedToMagnet(QString, QString))); } else { bool ok = false; if (source.startsWith("magnet:", Qt::CaseInsensitive)) ok = dlg->loadMagnet(source); else ok = dlg->loadTorrent(source); if (ok) dlg->open(); else delete dlg; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), downloader(this), ui(new Ui::MainWindow) { ui->setupUi(this); curstep = 0; totalSteps = 0; tempDir = AppPathManager::userAppDir() + "/PGE Content Manager"; ui->cpack_info_box->setEnabled(false); connect(&downloader, SIGNAL(finished()), this, SLOT(downloadSuccess())); connect(&downloader, SIGNAL(canceled()), this, SLOT(downloadAborted())); connect(&downloader, SIGNAL(failed(QString)), this, SLOT(downloadFailed(QString))); connect(&downloader, SIGNAL(progress(qint64, qint64)), this, SLOT(setProgress(qint64, qint64))); ui->progressBar->hide(); cancelStatusBarButton = new QToolButton(ui->statusBar); cancelStatusBarButton->setText("x"); cancelStatusBarButton->setToolTip("Cancel current action."); statusBar()->addPermanentWidget(cancelStatusBarButton); cancelStatusBarButton->hide(); connect(cancelStatusBarButton, &QToolButton::clicked, this, &MainWindow::cancelStatusBarButtonClicked); if(MainWindow::autoRefresh) { refreshRepos(); } ui->actionAuto_Refresh_on_Startup->setChecked(MainWindow::autoRefresh); }
void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = adoptGRef(response.toSoupMessage()); m_download->didReceiveResponse(response); if (response.httpStatusCode() >= 400) { downloadFailed(platformDownloadNetworkError(response.httpStatusCode(), response.url().string(), response.httpStatusText())); return; } String suggestedFilename = response.suggestedFilename(); if (suggestedFilename.isEmpty()) { URL url = response.url(); url.setQuery(String()); url.removeFragmentIdentifier(); suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); } bool overwrite; String destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, overwrite); if (destinationURI.isEmpty()) { #if PLATFORM(GTK) GOwnPtr<char> buffer(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); String errorMessage = String::fromUTF8(buffer.get()); #else String errorMessage = makeString("Cannot determine destination URI for download with suggested filename ", suggestedFilename); #endif downloadFailed(platformDownloadDestinationError(response, errorMessage)); return; } GRefPtr<GFile> file = adoptGRef(g_file_new_for_uri(destinationURI.utf8().data())); GOwnPtr<GError> error; m_outputStream = adoptGRef(g_file_replace(file.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); if (!m_outputStream) { downloadFailed(platformDownloadDestinationError(response, error->message)); return; } GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); g_file_info_set_attribute_string(info.get(), "metadata::download-uri", response.url().string().utf8().data()); g_file_set_attributes_async(file.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, 0, 0, 0); m_download->didCreateDestination(destinationURI); }
void FileDownloader::readResponseHeader(const QHttpResponseHeader &responseHeader) { if (responseHeader.statusCode() != 200) { emit downloadFailed(responseHeader.reasonPhrase()); http_request_aborted = true; hide(); http->abort(); return; } }
void TrackersAdditionDlg::on_uTorrentListButton_clicked() { uTorrentListButton->setEnabled(false); Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(QString("http://www.torrentz.com/announce_%1").arg(m_torrent->hash()), true); connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(parseUTorrentList(QString, QString))); connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(getTrackerError(QString, QString))); //Just to show that it takes times setCursor(Qt::WaitCursor); }
void WebViewDownloadItem::onDownloadFailed(QWebDownloadItem::DownloadError, const QUrl&, const QString &description) { this->setCompleted(false); this->setError(true); this->setLastError(description); this->removeFile(); emit downloadFailed(this->fileName()); }
void Net::DownloadHandler::handleRedirection(QUrl newUrl) { // Resolve relative urls if (newUrl.isRelative()) newUrl = m_reply->url().resolved(newUrl); const QString newUrlString = newUrl.toString(); qDebug("Redirecting from %s to %s...", qUtf8Printable(m_reply->url().toString()), qUtf8Printable(newUrlString)); // Redirect to magnet workaround if (newUrlString.startsWith("magnet:", Qt::CaseInsensitive)) { qDebug("Magnet redirect detected."); m_reply->abort(); if (m_downloadRequest.handleRedirectToMagnet()) emit redirectedToMagnet(m_downloadRequest.url(), newUrlString); else emit downloadFailed(m_downloadRequest.url(), tr("Unexpected redirect to magnet URI.")); this->deleteLater(); } else { DownloadHandler *redirected = m_manager->download(DownloadRequest(m_downloadRequest).url(newUrlString)); connect(redirected, &DownloadHandler::destroyed, this, &DownloadHandler::deleteLater); connect(redirected, &DownloadHandler::downloadFailed, this, [this](const QString &, const QString &reason) { emit downloadFailed(url(), reason); }); connect(redirected, &DownloadHandler::redirectedToMagnet, this, [this](const QString &, const QString &magnetUri) { emit redirectedToMagnet(url(), magnetUri); }); connect(redirected, static_cast<void (DownloadHandler::*)(const QString &, const QString &)>(&DownloadHandler::downloadFinished) , this, [this](const QString &, const QString &fileName) { emit downloadFinished(url(), fileName); }); connect(redirected, static_cast<void (DownloadHandler::*)(const QString &, const QByteArray &)>(&DownloadHandler::downloadFinished) , this, [this](const QString &, const QByteArray &data) { emit downloadFinished(url(), data); }); } }
void Net::DownloadHandler::checkDownloadSize(qint64 bytesReceived, qint64 bytesTotal) { QString msg = tr("The file size is %1. It exceeds the download limit of %2."); if (bytesTotal > 0) { // Total number of bytes is available if (bytesTotal > m_downloadRequest.limit()) { m_reply->abort(); emit downloadFailed(m_downloadRequest.url(), msg.arg(Utils::Misc::friendlyUnit(bytesTotal), Utils::Misc::friendlyUnit(m_downloadRequest.limit()))); } else { disconnect(m_reply, &QNetworkReply::downloadProgress, this, &Net::DownloadHandler::checkDownloadSize); } } else if (bytesReceived > m_downloadRequest.limit()) { m_reply->abort(); emit downloadFailed(m_downloadRequest.url(), msg.arg(Utils::Misc::friendlyUnit(bytesReceived), Utils::Misc::friendlyUnit(m_downloadRequest.limit()))); } }
void didReceiveData(ResourceHandle*, const char* data, int length, int /*encodedDataLength*/) { gsize bytesWritten; GOwnPtr<GError> error; g_output_stream_write_all(G_OUTPUT_STREAM(m_outputStream.get()), data, length, &bytesWritten, 0, &error.outPtr()); if (error) { downloadFailed(downloadDestinationError(ResourceResponse(m_response.get()), error->message)); return; } m_download->didReceiveData(bytesWritten); }
void Net::DownloadHandler::processFinishedDownload() { QString url = m_reply->url().toString(); qDebug("Download finished: %s", qUtf8Printable(url)); // Check if the request was successful if (m_reply->error() != QNetworkReply::NoError) { // Failure qDebug("Download failure (%s), reason: %s", qUtf8Printable(url), qUtf8Printable(errorCodeToString(m_reply->error()))); emit downloadFailed(m_downloadRequest.url(), errorCodeToString(m_reply->error())); this->deleteLater(); } else { // Check if the server ask us to redirect somewhere else const QVariant redirection = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (redirection.isValid()) { // We should redirect handleRedirection(redirection.toUrl()); } else { // Success QByteArray replyData = m_reply->readAll(); if (m_reply->rawHeader("Content-Encoding") == "gzip") { // decompress gzip reply replyData = Utils::Gzip::decompress(replyData); } if (m_downloadRequest.saveToFile()) { QString filePath; if (saveToFile(replyData, filePath)) emit downloadFinished(m_downloadRequest.url(), filePath); else emit downloadFailed(m_downloadRequest.url(), tr("I/O Error")); } else { emit downloadFinished(m_downloadRequest.url(), replyData); } this->deleteLater(); } } }
void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = adoptGRef(response.toSoupMessage()); m_download->didReceiveResponse(response); if (response.httpStatusCode() >= 400) { downloadFailed(downloadNetworkError(ResourceError(errorDomainDownload, response.httpStatusCode(), response.url().string(), response.httpStatusText()))); return; } String suggestedFilename = response.suggestedFilename(); if (suggestedFilename.isEmpty()) { KURL url = response.url(); url.setQuery(String()); url.removeFragmentIdentifier(); suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); } bool overwrite; String destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename.utf8().data(), overwrite); if (destinationURI.isEmpty()) { GOwnPtr<char> errorMessage(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); downloadFailed(downloadDestinationError(response, errorMessage.get())); return; } GRefPtr<GFile> file = adoptGRef(g_file_new_for_uri(destinationURI.utf8().data())); GOwnPtr<GError> error; m_outputStream = adoptGRef(g_file_replace(file.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); if (!m_outputStream) { downloadFailed(downloadDestinationError(response, error->message)); return; } m_download->didCreateDestination(destinationURI); }
void didReceiveData(ResourceHandle*, const char* data, unsigned length, int /*encodedDataLength*/) { if (m_handleResponseLaterID) { g_source_remove(m_handleResponseLaterID); handleResponse(); } gsize bytesWritten; GOwnPtr<GError> error; g_output_stream_write_all(G_OUTPUT_STREAM(m_outputStream.get()), data, length, &bytesWritten, 0, &error.outPtr()); if (error) { downloadFailed(platformDownloadDestinationError(m_response, error->message)); return; } m_download->didReceiveData(bytesWritten); }
void NodeVersionLoader::sendHeader() { auto self = shared_from_this(); checkThread(); auto& item = currentDownloadItem(); state = State::SendingHeader; PacketGenerator gen; gen.write(VersionDownloadRequestMagic); gen.writeString(item.version); auto buf = std::make_shared<std::vector<char>>(std::move(gen.vector())); timer.expires_from_now(boost::posix_time::seconds(8)); timer.async_wait([this, self] (const error_code& error) { if (error) { return; } if (disposed) { return; } if (state == State::SendingHeader) { BOOST_LOG_SEV(log, LogLevel::Warn) << "Timed out."; socket.cancel(); } }); asio::async_write(socket, asio::buffer(buf->data(), buf->size()), [this, self, &item](const error_code& error, std::size_t) { checkThread(); if (disposed) { downloadCancelled(); return; } if (error) { downloadFailed(error.message()); return; } timer.cancel(); receiveHeader(); }); }
void FileDownloader::httpRequestFinished(int request_id, bool error) { qDebug("FileDownloader::httpRequestFinished: request_id %d, error %d", request_id, error); if (request_id != http_get_id) return; if (http_request_aborted) { hide(); return; } hide(); if (error) { emit downloadFailed(http->errorString()); } else { emit downloadFinished(buffer.data()); } }
void DownloadDialog::dispose() { _destination.close(); if (_download) { if (_download->error()) qDebug() << _download->errorString(); if (_completed) emit downloadSucceeded(); else emit downloadFailed(); _download->deleteLater(); _download = nullptr; } }
void didFinishLoading(ResourceHandle*, double) { m_outputStream = 0; ASSERT(m_intermediateFile); GRefPtr<GFile> destinationFile = adoptGRef(g_file_new_for_uri(m_destinationURI.utf8().data())); GOwnPtr<GError> error; if (!g_file_move(m_intermediateFile.get(), destinationFile.get(), G_FILE_COPY_NONE, nullptr, nullptr, nullptr, &error.outPtr())) { downloadFailed(platformDownloadDestinationError(m_response, error->message)); return; } GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); CString uri = m_response.url().string().utf8(); g_file_info_set_attribute_string(info.get(), "metadata::download-uri", uri.data()); g_file_info_set_attribute_string(info.get(), "xattr::xdg.origin.url", uri.data()); g_file_set_attributes_async(destinationFile.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, nullptr, nullptr, nullptr); m_download->didFinish(); }
void FileDownloader::gotResponse(QNetworkReply* reply) { if (reply->error() == QNetworkReply::NoError) { int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug("FileDownloader::gotResponse: status: %d", status); switch (status) { case 301: case 302: case 307: QString r_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl().toString(); qDebug("FileDownloader::gotResponse: redirected: %s", r_url.toLatin1().constData()); download(r_url); return; } } else { hide(); emit downloadFailed(reply->errorString()); return; } hide(); emit downloadFinished(reply->readAll()); }
void SimpleHttp::readResponseHeader(const QHttpResponseHeader &responseHeader) { qDebug("SimpleHttp::readResponseHeader: statusCode: %d", responseHeader.statusCode()); if (responseHeader.statusCode() == 301) { QString new_url = responseHeader.value("Location"); qDebug("SimpleHttp::readResponseHeader: Location: '%s'", new_url.toLatin1().constData()); download(new_url); } else if (responseHeader.statusCode() == 302) { QString location = responseHeader.value("Location"); qDebug("SimpleHttp::readResponseHeader: Location: '%s'", location.toLatin1().constData()); /* http_get_id = get( location ); */ download(location); } else if (responseHeader.statusCode() != 200) { qDebug("SimpleHttp::readResponseHeader: error: '%s'", responseHeader.reasonPhrase().toLatin1().constData()); emit downloadFailed(responseHeader.reasonPhrase()); abort(); } }
FindSubtitlesWindow::FindSubtitlesWindow( QWidget * parent, Qt::WindowFlags f ) : QDialog(parent,f) { setupUi(this); set = 0; // settings subtitles_for_label->setBuddy(file_chooser->lineEdit()); progress->hide(); connect( file_chooser, SIGNAL(fileChanged(QString)), this, SLOT(setMovie(QString)) ); connect( file_chooser->lineEdit(), SIGNAL(textChanged(const QString &)), this, SLOT(updateRefreshButton()) ); connect( refresh_button, SIGNAL(clicked()), this, SLOT(refresh()) ); connect( download_button, SIGNAL(clicked()), this, SLOT(download()) ); /* connect( language_filter, SIGNAL(editTextChanged(const QString &)), this, SLOT(applyFilter(const QString &)) ); */ connect( language_filter, SIGNAL(activated(int)), this, SLOT(applyCurrentFilter()) ); table = new QStandardItemModel(this); table->setColumnCount(COL_USER + 1); proxy_model = new QSortFilterProxyModel(this); proxy_model->setSourceModel(table); proxy_model->setFilterKeyColumn(COL_LANG); proxy_model->setFilterRole(Qt::UserRole); view->setModel(proxy_model); view->setRootIsDecorated(false); view->setSortingEnabled(true); view->setAlternatingRowColors(true); view->header()->setSortIndicator(COL_LANG, Qt::AscendingOrder); view->setEditTriggers(QAbstractItemView::NoEditTriggers); view->setContextMenuPolicy( Qt::CustomContextMenu ); connect(view, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &)) ); connect(view->selectionModel(), SIGNAL(currentChanged(const QModelIndex &,const QModelIndex &)), this, SLOT(currentItemChanged(const QModelIndex &,const QModelIndex &)) ); connect(view, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showContextMenu(const QPoint &)) ); downloader = new SimpleHttp(this); connect( downloader, SIGNAL(downloadFailed(QString)), this, SLOT(showError(QString)) ); connect( downloader, SIGNAL(downloadFinished(QByteArray)), this, SLOT(downloadFinished()) ); connect( downloader, SIGNAL(downloadFinished(QByteArray)), this, SLOT(parseInfo(QByteArray)) ); connect( downloader, SIGNAL(stateChanged(int)), this, SLOT(updateRefreshButton()) ); connect( downloader, SIGNAL(connecting(QString)), this, SLOT(connecting(QString)) ); connect( downloader, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)) ); #ifdef DOWNLOAD_SUBS include_lang_on_filename = true; file_downloader = new FileDownloader(this); file_downloader->setModal(true); connect( file_downloader, SIGNAL(downloadFailed(QString)), this, SLOT(showError(QString)), Qt::QueuedConnection ); connect( file_downloader, SIGNAL(downloadFinished(const QByteArray &)), this, SLOT(archiveDownloaded(const QByteArray &)), Qt::QueuedConnection ); #endif // Actions downloadAct = new QAction(this); downloadAct->setEnabled(false); connect( downloadAct, SIGNAL(triggered()), this, SLOT(download()) ); copyLinkAct = new QAction(this); copyLinkAct->setEnabled(false); connect( copyLinkAct, SIGNAL(triggered()), this, SLOT(copyLink()) ); context_menu = new QMenu(this); context_menu->addAction(downloadAct); context_menu->addAction(copyLinkAct); retranslateStrings(); language_filter->setCurrentIndex(0); }
void NodeVersionLoader::receiveChunk() { auto self = shared_from_this(); checkThread(); auto& item = currentDownloadItem(); auto chunkSize = static_cast<std::size_t> (std::min<std::uint64_t>(readBuffer.size(), static_cast<std::uint64_t>(remainingBytes))); if (chunkSize == 0) { // Done! BOOST_LOG_SEV(log, LogLevel::Info) << "Download completed."; auto ver = item.version; { std::lock_guard<std::mutex> lock(downloadQueueMutex); downloadQueue.pop_front(); // note: `item` is a dangling reference now } file.reset(); timer.cancel(); onVersionDownloaded(ver); log.setChannel(std::string("(none)")); state = State::Waiting; timer.expires_from_now(boost::posix_time::seconds(1)); timer.async_wait([this, self] (const error_code& error) { if (error) { return; } if (disposed) { BOOST_LOG_SEV(log, LogLevel::Debug) << "Retry timer aborted.: Disposed."; return; } state = State::Idle; checkQueue(); }); return; } asio::async_read(socket, asio::buffer(readBuffer.data(), chunkSize), [this, self, &item, chunkSize](const error_code& error, std::size_t) { checkThread(); if (disposed) { downloadCancelled(); return; } if (error) { downloadFailed(error.message()); return; } lastReceiveTime = boost::posix_time::second_clock::local_time(); try { file->write(readBuffer.data(), chunkSize); } catch (...) { downloadFailed("Failed to write to the downloaded file.: " + boost::current_exception_diagnostic_information()); return; } remainingBytes -= static_cast<std::uint64_t>(chunkSize); receiveChunk(); }); }
void didFail(ResourceHandle*, const ResourceError& error) { downloadFailed(platformDownloadNetworkError(error.errorCode(), error.failingURL(), error.localizedDescription())); }
void didFail(ResourceHandle*, const ResourceError& error) { downloadFailed(downloadNetworkError(error)); }