2009-05-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

DownloadResult now has the list of FileEntry.  The download
	summary displays the path of first selected file and the number of
	remaining files for multi-file torrent.
	* src/DownloadResult.h
	* src/RequestGroup.cc
	* src/RequestGroupMan.cc
	* test/RequestGroupTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-05-12 15:16:11 +00:00
parent d38b21acb0
commit 8bbbc9c33b
5 changed files with 66 additions and 11 deletions

View File

@ -1,3 +1,13 @@
2009-05-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
DownloadResult now has the list of FileEntry. The download
summary displays the path of first selected file and the number of
remaining files for multi-file torrent.
* src/DownloadResult.h
* src/RequestGroup.cc
* src/RequestGroupMan.cc
* test/RequestGroupTest.cc
2009-05-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed segmentation fault error when no file is selected in

View File

@ -40,8 +40,10 @@
#include <stdint.h>
#include <string>
#include <deque>
#include "SharedHandle.h"
#include "FileEntry.h"
namespace aria2 {
@ -62,7 +64,7 @@ public:
int32_t gid;
std::string filePath;
std::deque<SharedHandle<FileEntry> > fileEntries;
uint64_t totalLength;
@ -78,7 +80,7 @@ public:
RESULT result;
DownloadResult(int32_t gid,
const std::string& filePath,
const std::deque<SharedHandle<FileEntry> >& fileEntries,
uint64_t totalLength,
const std::string& uri,
size_t numUri,
@ -86,7 +88,7 @@ public:
int64_t sessionTime,
RESULT result):
gid(gid),
filePath(filePath),
fileEntries(fileEntries),
totalLength(totalLength),
uri(uri),
numUri(numUri),

View File

@ -1025,7 +1025,7 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
return
SharedHandle<DownloadResult>
(new DownloadResult(_gid,
getFilePath(),
_downloadContext->getFileEntries(),
getTotalLength(),
uris.empty() ? A2STR::NIL:uris.front(),
uris.size(),

View File

@ -538,6 +538,50 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
}
}
template<typename InputIterator>
static SharedHandle<FileEntry> getFirstRequestedFileEntry
(InputIterator first, InputIterator last)
{
for(; first != last; ++first) {
if((*first)->isRequested()) {
return *first;
}
}
return SharedHandle<FileEntry>();
}
template<typename InputIterator>
static size_t countRequestedFileEntry(InputIterator first, InputIterator last)
{
size_t count = 0;
for(; first != last; ++first) {
if((*first)->isRequested()) {
++count;
}
}
return count;
}
template<typename InputIterator>
static void writeFilePath
(InputIterator first, InputIterator last, std::ostream& o)
{
SharedHandle<FileEntry> e = getFirstRequestedFileEntry(first, last);
if(e.isNull()) {
o << "n/a";
} else {
if(e->getPath().empty()) {
o << "n/a";
} else {
o << e->getPath();
}
size_t count = countRequestedFileEntry(first, last);
if(count > 1) {
o << " (" << count-1 << "more)";
}
}
}
std::string RequestGroupMan::formatDownloadResult(const std::string& status, const DownloadResultHandle& downloadResult) const
{
std::stringstream o;
@ -552,15 +596,13 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con
o << "n/a";
}
o << "|";
const std::deque<SharedHandle<FileEntry> >& fileEntries =
downloadResult->fileEntries;
if(downloadResult->result == DownloadResult::FINISHED) {
o << downloadResult->filePath;
writeFilePath(fileEntries.begin(), fileEntries.end(), o);
} else {
if(downloadResult->numUri == 0) {
if(downloadResult->filePath.empty()) {
o << "n/a";
} else {
o << downloadResult->filePath;
}
writeFilePath(fileEntries.begin(), fileEntries.end(), o);
} else {
o << downloadResult->uri;
if(downloadResult->numUri > 1) {

View File

@ -112,7 +112,8 @@ void RequestGroupTest::testCreateDownloadResult()
{
SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), result->filePath);
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"),
result->fileEntries[0]->getPath());
CPPUNIT_ASSERT_EQUAL((uint64_t)1024*1024, result->totalLength);
CPPUNIT_ASSERT_EQUAL(std::string("http://first/file"), result->uri);
CPPUNIT_ASSERT_EQUAL((size_t)2, result->numUri);