From 886c8d2da6da5e47f3ab018316eed63840f7d688 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 15 Jun 2015 19:58:23 +0200 Subject: [PATCH] Reenable bootstrapping of torrent DHTs Enable setting of overwrite settings for download files --- apps/Launcher/syncwidget.cpp | 23 +++++++++++++++------- include/openspace/engine/downloadmanager.h | 2 ++ src/engine/downloadmanager.cpp | 14 ++++++++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index aae73d94ab..a9b5fc615e 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -119,7 +119,11 @@ SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f) } _session->start_upnp(); _session->start_dht(); - + + _session->add_dht_router({ "dht.transmissionbt.com", 6881}); + _session->add_dht_router({ "router.bittorrent.com", 6881}); + _session->add_dht_router({ "router.utorrent.com", 6881 }); + _session->add_dht_router({ "router.bitcomet.com", 6881 }); QTimer* timer = new QTimer(this); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(handleTimer())); @@ -160,17 +164,21 @@ void SyncWidget::clear() { void SyncWidget::handleDirectFiles() { qDebug() << "Direct Files"; for (const DirectFile& f : _directFiles) { - InfoWidget* w = new InfoWidget(f.destination); - _downloadLayout->addWidget(w); qDebug() << f.url << " -> " << f.destination; openspace::DownloadManager::FileFuture* future = DlManager.downloadFile( f.url.toStdString(), - fullPath(f.module, f.destination).toStdString() + fullPath(f.module, f.destination).toStdString(), + false ); - _futures.push_back(future); - _futureInfoWidgetMap[future] = w; + if (future) { + InfoWidget* w = new InfoWidget(f.destination); + _downloadLayout->addWidget(w); + + _futures.push_back(future); + _futureInfoWidgetMap[future] = w; + } } } @@ -186,7 +194,8 @@ void SyncWidget::handleFileRequest() { DlManager.downloadRequestFiles( identifier, path, - version + version, + false ); _futures.insert(_futures.end(), futures.begin(), futures.end()); diff --git a/include/openspace/engine/downloadmanager.h b/include/openspace/engine/downloadmanager.h index c6423f4aee..460f77581b 100644 --- a/include/openspace/engine/downloadmanager.h +++ b/include/openspace/engine/downloadmanager.h @@ -57,6 +57,7 @@ public: FileFuture* downloadFile( const std::string& url, const ghoul::filesystem::File& file, + bool overrideFile = true, DownloadFinishedCallback finishedCallback = DownloadFinishedCallback(), DownloadProgressCallback progressCallback = DownloadProgressCallback() ); @@ -65,6 +66,7 @@ public: const std::string& identifier, const ghoul::filesystem::Directory& destination, int version, + bool overrideFiles = true, DownloadFinishedCallback finishedCallback = DownloadFinishedCallback(), DownloadProgressCallback progressCallback = DownloadProgressCallback() ); diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index 764940012e..5a501faadb 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -106,9 +106,13 @@ DownloadManager::DownloadManager(std::string requestURL, int applicationVersion) DownloadManager::FileFuture* DownloadManager::downloadFile( const std::string& url, const ghoul::filesystem::File& file, + bool overrideFile, DownloadFinishedCallback finishedCallback, DownloadProgressCallback progressCallback) { + if (!overrideFile && FileSys.fileExists(file)) + return nullptr; + FileFuture* future = new FileFuture( file.filename() ); @@ -154,6 +158,7 @@ std::vector DownloadManager::downloadRequestFiles( const std::string& identifier, const ghoul::filesystem::Directory& destination, int version, + bool overrideFiles, DownloadFinishedCallback finishedCallback, DownloadProgressCallback progressCallback) { @@ -171,7 +176,7 @@ std::vector DownloadManager::downloadRequestFiles( LDEBUG("Request File: " << requestFile); bool isFinished = false; - auto callback = [&futures, destination, &progressCallback, &isFinished, requestFile](const FileFuture& f) { + auto callback = [&futures, destination, &progressCallback, &isFinished, requestFile, overrideFiles](const FileFuture& f) { LDEBUG("Finished: " << requestFile); std::ifstream temporary(requestFile); std::string line; @@ -185,9 +190,11 @@ std::vector DownloadManager::downloadRequestFiles( FileFuture* future = DlManager.downloadFile( line, - destination.path() + "/" + file + destination.path() + "/" + file, + overrideFiles ); - futures.push_back(future); + if (future) + futures.push_back(future); } isFinished = true; }; @@ -195,6 +202,7 @@ std::vector DownloadManager::downloadRequestFiles( FileFuture* f = downloadFile( fullRequest, requestFile, + true, callback );