From dbc8d549c7a7609af879924e3a434d0652896a79 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 28 Feb 2009 09:52:09 +0000 Subject: [PATCH] 2009-02-28 Tatsuhiro Tsujikawa Now select-file can be specified in the uri list(-i list). * src/BtContext.cc * src/BtContext.h * src/RequestGroup.cc * src/Sequence.h * src/download_helper.cc --- ChangeLog | 9 +++++++++ src/BtContext.cc | 10 ++++++++++ src/BtContext.h | 8 ++++++++ src/RequestGroup.cc | 2 +- src/Sequence.h | 2 ++ src/download_helper.cc | 24 ++++++++++++++++++++++-- 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2777ec6d..1a38c273 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-02-28 Tatsuhiro Tsujikawa + + Now select-file can be specified in the uri list(-i list). + * src/BtContext.cc + * src/BtContext.h + * src/RequestGroup.cc + * src/Sequence.h + * src/download_helper.cc + 2009-02-28 Tatsuhiro Tsujikawa Made the upper value of --max-concurrent-downloads options unlimited. diff --git a/src/BtContext.cc b/src/BtContext.cc index 4d306041..acf3b1a3 100644 --- a/src/BtContext.cc +++ b/src/BtContext.cc @@ -62,4 +62,14 @@ const std::string BtContext::C_ANNOUNCE_LIST("announce-list"); const std::string BtContext::C_NODES("nodes"); +void BtContext::setFileFilter(const IntSequence& seq) +{ + _fileFilter = seq; +} + +IntSequence BtContext::getFileFilter() const +{ + return _fileFilter; +} + } // namespace aria2 diff --git a/src/BtContext.h b/src/BtContext.h index 94066bb0..6a7f629e 100644 --- a/src/BtContext.h +++ b/src/BtContext.h @@ -39,6 +39,8 @@ #include #include +#include "IntSequence.h" + namespace aria2 { class AnnounceTier; @@ -47,6 +49,8 @@ class RequestGroup; class BtContext:public DownloadContext { protected: bool _private; + + IntSequence _fileFilter; public: BtContext():_private(false) {} @@ -81,6 +85,10 @@ public: virtual std::deque >& getNodes() = 0; + void setFileFilter(const IntSequence& seq); + + IntSequence getFileFilter() const; + static const std::string C_NAME; static const std::string C_FILES; diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index a82ae865..d910696e 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -215,7 +215,7 @@ void RequestGroup::createInitialCommand(std::deque& commands, _logger->debug("Clearing http/ftp URIs because the current implementation does not allow integrating multi-file torrent and http/ftp."); _uris.clear(); - _pieceStorage->setFileFilter(Util::parseIntRange(_option->get(PREF_SELECT_FILE))); + _pieceStorage->setFileFilter(btContext->getFileFilter()); } SharedHandle diff --git a/src/Sequence.h b/src/Sequence.h index d3efc3bf..9364d70e 100644 --- a/src/Sequence.h +++ b/src/Sequence.h @@ -69,6 +69,8 @@ public: Sequence(const Values& values): _values(values) {} + Sequence() {} + T next() { if(_values.empty()) { diff --git a/src/download_helper.cc b/src/download_helper.cc index 97ab72ad..67988b6e 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -55,6 +55,8 @@ #include "FileEntry.h" #include "LogFactory.h" #include "File.h" +#include "Util.h" +#include "array_fun.h" namespace aria2 { @@ -120,6 +122,8 @@ createBtRequestGroup(const std::string& torrentFilePath, btContext->setPeerIdPrefix(op->get(PREF_PEER_ID_PREFIX)); } btContext->setDir(requestOption.get(PREF_DIR)); + btContext->setFileFilter + (Util::parseIntRange(requestOption.get(PREF_SELECT_FILE))); rg->setDownloadContext(btContext); btContext->setOwnerRequestGroup(rg.get()); return rg; @@ -271,6 +275,15 @@ void createRequestGroupForUri createRequestGroupForUri(result, op, uris, *op); } +template +static void foreachCopyIfndef(InputIterator first, InputIterator last, + Option& dest, const Option& src) +{ + for(; first != last; ++first) { + copyIfndef(dest, src, *first); + } +} + static void createRequestGroupForUriList (std::deque >& result, Option* op, std::istream& in) { @@ -282,8 +295,15 @@ static void createRequestGroupForUriList if(uris.empty()) { continue; } - copyIfndef(requestOption, *op, PREF_DIR); - copyIfndef(requestOption, *op, PREF_OUT); + // These options can be specified in input list(-i list). + static const std::string REQUEST_OPTIONS[] = { + PREF_DIR, + PREF_OUT, + PREF_SELECT_FILE + }; + foreachCopyIfndef(&REQUEST_OPTIONS[0], + &REQUEST_OPTIONS[arrayLength(REQUEST_OPTIONS)], + requestOption, *op); createRequestGroupForUri(result, op, uris, requestOption); }