Use BtFileMode for TorrentAttribute::mode

pull/89/head
Tatsuhiro Tsujikawa 2013-05-15 00:09:51 +09:00
parent 5dcc2b7842
commit 4f5d26a0c7
9 changed files with 36 additions and 14 deletions

View File

@ -706,8 +706,8 @@ void gatherBitTorrentMetadata
if(torrentAttrs->creationDate) {
btDict->put(KEY_CREATION_DATE, Integer::g(torrentAttrs->creationDate));
}
if(!torrentAttrs->mode.empty()) {
btDict->put(KEY_MODE, torrentAttrs->mode);
if(torrentAttrs->mode) {
btDict->put(KEY_MODE, bittorrent::getModeString(torrentAttrs->mode));
}
SharedHandle<List> destAnnounceList = List::g();
for(std::vector<std::vector<std::string> >::const_iterator l =

View File

@ -37,7 +37,10 @@
namespace aria2 {
TorrentAttribute::TorrentAttribute()
: metadataSize(0), privateTorrent(false), creationDate(0)
: mode(BT_FILE_MODE_NONE),
metadataSize(0),
privateTorrent(false),
creationDate(0)
{}
TorrentAttribute::~TorrentAttribute() {}

View File

@ -40,13 +40,14 @@
#include <string>
#include <vector>
#include <aria2/aria2.h>
#include "a2time.h"
namespace aria2 {
struct TorrentAttribute:public ContextAttribute {
std::string name;
std::string mode;
BtFileMode mode;
std::vector<std::vector<std::string> > announceList;
std::vector<std::pair<std::string, uint16_t> > nodes;
// raw hash value 20 bytes.

View File

@ -600,9 +600,7 @@ struct RequestGroupDH : public DownloadHandle {
res.announceList = torrentAttrs->announceList;
res.comment = torrentAttrs->comment;
res.creationDate = torrentAttrs->creationDate;
// TODO Use BtFileMode for torrentAttrs->mode
res.mode = torrentAttrs->mode == "single" ?
BT_FILE_MODE_SINGLE : BT_FILE_MODE_MULTI;
res.mode = torrentAttrs->mode;
if(!torrentAttrs->metadata.empty()) {
res.name = torrentAttrs->name;
}

View File

@ -235,7 +235,7 @@ void extractFileEntries
int64_t length = 0;
int64_t offset = 0;
// multi-file mode
torrent->mode = MULTI;
torrent->mode = BT_FILE_MODE_MULTI;
for(List::ValueType::const_iterator itr = filesList->begin(),
eoi = filesList->end(); itr != eoi; ++itr) {
const Dict* fileDict = downcast<Dict>(*itr);
@ -303,7 +303,7 @@ void extractFileEntries
}
} else {
// single-file mode;
torrent->mode = SINGLE;
torrent->mode = BT_FILE_MODE_SINGLE;
const Integer* lengthData = downcast<Integer>(infoDict->get(C_LENGTH));
if(!lengthData) {
throw DL_ABORT_EX2(fmt(MSG_MISSING_BT_INFO, C_LENGTH.c_str()),
@ -333,7 +333,7 @@ void extractFileEntries
fileEntries.push_back(fileEntry);
}
ctx->setFileEntries(fileEntries.begin(), fileEntries.end());
if(torrent->mode == MULTI) {
if(torrent->mode == BT_FILE_MODE_MULTI) {
ctx->setBasePath(util::applyDir(option->get(PREF_DIR),
util::escapePath(utf8Name)));
}
@ -1076,6 +1076,18 @@ void adjustAnnounceUri
addAnnounceUri(attrs, addUris);
}
const char* getModeString(BtFileMode mode)
{
switch(mode) {
case BT_FILE_MODE_SINGLE:
return "single";
case BT_FILE_MODE_MULTI:
return "multi";
default:
return "";
}
}
} // namespace bittorrent
} // namespace aria2

View File

@ -336,6 +336,9 @@ void extractPeer
int getCompactLength(int family);
// Returns textual representation of the |mode|.
const char* getModeString(BtFileMode mode);
// Writes the detailed information about torrent loaded in dctx.
template<typename Output>
void print(Output& o, const SharedHandle<DownloadContext>& dctx)
@ -352,7 +355,7 @@ void print(Output& o, const SharedHandle<DownloadContext>& dctx)
if(!torrentAttrs->createdBy.empty()) {
o.printf("Created By: %s\n", torrentAttrs->createdBy.c_str());
}
o.printf("Mode: %s\n", torrentAttrs->mode.c_str());
o.printf("Mode: %s\n", getModeString(torrentAttrs->mode));
o.write("Announce:\n");
for(std::vector<std::vector<std::string> >::const_iterator tierIter =
torrentAttrs->announceList.begin(),

View File

@ -453,6 +453,11 @@ struct FileData {
* BitTorrent file mode
*/
enum BtFileMode {
/**
* Indicating no mode. This value is used when file mode is not
* available.
*/
BT_FILE_MODE_NONE,
/**
* Indicating single file torrent
*/

View File

@ -219,14 +219,14 @@ void BittorrentHelperTest::testGetFileModeMulti() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
load(A2_TEST_DIR"/test.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(MULTI, getTorrentAttrs(dctx)->mode);
CPPUNIT_ASSERT_EQUAL(BT_FILE_MODE_MULTI, getTorrentAttrs(dctx)->mode);
}
void BittorrentHelperTest::testGetFileModeSingle() {
SharedHandle<DownloadContext> dctx(new DownloadContext());
load(A2_TEST_DIR"/single.torrent", dctx, option_);
CPPUNIT_ASSERT_EQUAL(SINGLE, getTorrentAttrs(dctx)->mode);
CPPUNIT_ASSERT_EQUAL(BT_FILE_MODE_SINGLE, getTorrentAttrs(dctx)->mode);
}
void BittorrentHelperTest::testGetNameMulti() {

View File

@ -915,7 +915,7 @@ void RpcMethodTest::testGatherBitTorrentMetadata()
SharedHandle<TorrentAttribute> modBtAttrs = bittorrent::getTorrentAttrs(dctx);
modBtAttrs->comment.clear();
modBtAttrs->creationDate = 0;
modBtAttrs->mode.clear();
modBtAttrs->mode = BT_FILE_MODE_NONE;
modBtAttrs->metadata.clear();
btDict = Dict::g();
gatherBitTorrentMetadata(btDict, modBtAttrs);