MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / download

Method download

src/openms/source/SYSTEM/File.cpp:919–952  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

917
918// static
919void File::download(const std::string& url, const std::string& download_folder)
920{
921 // We need to use a QCoreApplication to fire up the QEventLoop to process the signals and slots.
922 char const * argv2[] = { "dummyname", nullptr };
923 int argc = 1;
924 QCoreApplication event_loop(argc, const_cast<char**>(argv2));
925 NetworkGetRequest* query = new NetworkGetRequest(&event_loop);
926 auto qURL = QUrl(QString::fromUtf8(url.c_str()));
927 query->setUrl(qURL);
928 QObject::connect(query, SIGNAL(done()), &event_loop, SLOT(quit()));
929 QTimer::singleShot(1000, query, SLOT(run()));
930 QTimer::singleShot(600000, query, SLOT(timeOut())); // 10 minutes timeout
931 event_loop.exec();
932
933 if (!query->hasError())
934 {
935 QString folder = download_folder.empty() ? QString("./") : QString(download_folder.c_str());
936 QString filename = QString(folder) + "/" + saveFileName_(qURL);
937 QFile file(filename);
938 file.open(QIODevice::ReadWrite);
939 file.write(query->getResponseBinary().data(), query->getResponseBinary().size());
940 file.close();
941 OPENMS_LOG_INFO << "Download of '" << url << "' successful." << endl;
942 OPENMS_LOG_INFO << "Stored as '" << filename.toStdString() << "'." << endl;
943 }
944 else
945 {
946 String error = "Download of '" + url + "' failed!. Error: " + String(query->getErrorString()) + '\n';
947 throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, error);
948 }
949
950 delete query;
951 event_loop.quit();
952}
953
954
955} // namespace OpenMS

Callers

nothing calls this directly

Calls 11

saveFileName_Function · 0.85
setUrlMethod · 0.80
getErrorStringMethod · 0.80
QStringClass · 0.50
StringClass · 0.50
hasErrorMethod · 0.45
emptyMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
sizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected