mirror of https://github.com/aria2/aria2
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Code clean up * src/BtPostDownloadHandler.cc * src/ContentTypeRequestGroupCriteria.cc * src/ContentTypeRequestGroupCriteria.h * src/DownloadHandlerConstants.cc * src/DownloadHandlerConstants.h * src/DownloadHandlerFactory.cc * src/MetalinkPostDownloadHandler.ccpull/1/head
parent
5f1d8c7897
commit
967dade8b2
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Code clean up
|
||||
* src/BtPostDownloadHandler.cc
|
||||
* src/ContentTypeRequestGroupCriteria.cc
|
||||
* src/ContentTypeRequestGroupCriteria.h
|
||||
* src/DownloadHandlerConstants.cc
|
||||
* src/DownloadHandlerConstants.h
|
||||
* src/DownloadHandlerFactory.cc
|
||||
* src/MetalinkPostDownloadHandler.cc
|
||||
|
||||
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Don't save control file when aria2 exists while checking piece
|
||||
|
|
|
@ -52,8 +52,11 @@ namespace aria2 {
|
|||
BtPostDownloadHandler::BtPostDownloadHandler()
|
||||
{
|
||||
SharedHandle<RequestGroupCriteria> cri
|
||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getBtContentTypes(),
|
||||
DownloadHandlerConstants::getBtExtensions()));
|
||||
(new ContentTypeRequestGroupCriteria
|
||||
(DownloadHandlerConstants::getBtContentTypes().begin(),
|
||||
DownloadHandlerConstants::getBtContentTypes().end(),
|
||||
DownloadHandlerConstants::getBtExtensions().begin(),
|
||||
DownloadHandlerConstants::getBtExtensions().end()));
|
||||
setCriteria(cri);
|
||||
}
|
||||
|
||||
|
@ -79,8 +82,8 @@ void BtPostDownloadHandler::getNextRequestGroups
|
|||
}
|
||||
SharedHandle<DownloadContext> context(new DownloadContext());
|
||||
context->setDir(requestGroup->getDownloadContext()->getDir());
|
||||
bittorrent::loadFromMemory(content, context,
|
||||
File(requestGroup->getFirstFilePath()).getBasename());
|
||||
bittorrent::loadFromMemory
|
||||
(content, context, File(requestGroup->getFirstFilePath()).getBasename());
|
||||
rg->setDownloadContext(context);
|
||||
context->setOwnerRequestGroup(rg.get());
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "ContentTypeRequestGroupCriteria.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "RequestGroup.h"
|
||||
#include "Util.h"
|
||||
#include "FileEntry.h"
|
||||
|
@ -40,45 +43,33 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
ContentTypeRequestGroupCriteria::ContentTypeRequestGroupCriteria(const std::deque<std::string>& contentTypes,
|
||||
const std::deque<std::string>& extensions):
|
||||
_contentTypes(contentTypes),
|
||||
_extensions(extensions) {}
|
||||
template<typename InputIterator>
|
||||
bool tailMatch
|
||||
(InputIterator first, InputIterator last, const std::string& target)
|
||||
{
|
||||
for(; first != last; ++first) {
|
||||
if(Util::endsWith(target, *first)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ContentTypeRequestGroupCriteria::~ContentTypeRequestGroupCriteria() {}
|
||||
|
||||
bool ContentTypeRequestGroupCriteria::match(const RequestGroup* requestGroup) const
|
||||
bool ContentTypeRequestGroupCriteria::match
|
||||
(const RequestGroup* requestGroup) const
|
||||
{
|
||||
if(requestGroup->getDownloadContext()->getFileEntries().size() != 1) {
|
||||
return false;
|
||||
}
|
||||
if(forwardMatch(requestGroup->getFirstFilePath(), _extensions)) {
|
||||
if(tailMatch(_extensions.begin(), _extensions.end(),
|
||||
requestGroup->getFirstFilePath())) {
|
||||
return true;
|
||||
} else {
|
||||
return exactMatch
|
||||
(requestGroup->getDownloadContext()->getFirstFileEntry()->getContentType(),
|
||||
_contentTypes);
|
||||
return
|
||||
std::find(_contentTypes.begin(), _contentTypes.end(),
|
||||
requestGroup->getDownloadContext()->getFirstFileEntry()->
|
||||
getContentType()) != _contentTypes.end();
|
||||
}
|
||||
}
|
||||
|
||||
bool ContentTypeRequestGroupCriteria::forwardMatch(const std::string& target, const std::deque<std::string>& candidates) const
|
||||
{
|
||||
for(std::deque<std::string>::const_iterator itr = candidates.begin(); itr != candidates.end(); ++itr) {
|
||||
if(Util::endsWith(target, *itr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ContentTypeRequestGroupCriteria::exactMatch(const std::string& target, const std::deque<std::string>& candidates) const
|
||||
{
|
||||
for(std::deque<std::string>::const_iterator itr = candidates.begin(); itr != candidates.end(); ++itr) {
|
||||
if(target == *itr) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -37,25 +37,23 @@
|
|||
|
||||
#include "RequestGroupCriteria.h"
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class ContentTypeRequestGroupCriteria:public RequestGroupCriteria
|
||||
{
|
||||
private:
|
||||
std::deque<std::string> _contentTypes;
|
||||
std::deque<std::string> _extensions;
|
||||
|
||||
bool forwardMatch(const std::string& target, const std::deque<std::string>& candidates) const;
|
||||
|
||||
bool exactMatch(const std::string& target, const std::deque<std::string>& candidates) const;
|
||||
|
||||
std::vector<std::string> _contentTypes;
|
||||
std::vector<std::string> _extensions;
|
||||
public:
|
||||
ContentTypeRequestGroupCriteria(const std::deque<std::string>& contentTypes,
|
||||
const std::deque<std::string>& extensions);
|
||||
|
||||
virtual ~ContentTypeRequestGroupCriteria();
|
||||
template<typename InputIterator>
|
||||
ContentTypeRequestGroupCriteria(InputIterator contentTypeFirst,
|
||||
InputIterator contentTypeLast,
|
||||
InputIterator extensionFirst,
|
||||
InputIterator extensionLast):
|
||||
_contentTypes(contentTypeFirst, contentTypeLast),
|
||||
_extensions(extensionFirst, extensionLast) {}
|
||||
|
||||
virtual bool match(const RequestGroup* requestGroup) const;
|
||||
};
|
||||
|
|
|
@ -49,33 +49,35 @@ const char* DownloadHandlerConstants::BT_CONTENT_TYPES[] = {
|
|||
"application/x-bittorrent"
|
||||
};
|
||||
|
||||
const std::deque<std::string>& DownloadHandlerConstants::getMetalinkExtensions()
|
||||
const std::vector<std::string>&
|
||||
DownloadHandlerConstants::getMetalinkExtensions()
|
||||
{
|
||||
static const std::deque<std::string> l
|
||||
static const std::vector<std::string> l
|
||||
(&METALINK_EXTENSIONS[0],
|
||||
&METALINK_EXTENSIONS[arrayLength(METALINK_EXTENSIONS)]);
|
||||
return l;
|
||||
}
|
||||
|
||||
const std::deque<std::string>& DownloadHandlerConstants::getMetalinkContentTypes()
|
||||
const std::vector<std::string>&
|
||||
DownloadHandlerConstants::getMetalinkContentTypes()
|
||||
{
|
||||
static const std::deque<std::string> l
|
||||
static const std::vector<std::string> l
|
||||
(&METALINK_CONTENT_TYPES[0],
|
||||
&METALINK_CONTENT_TYPES[arrayLength(METALINK_CONTENT_TYPES)]);
|
||||
return l;
|
||||
}
|
||||
|
||||
const std::deque<std::string>& DownloadHandlerConstants::getBtExtensions()
|
||||
const std::vector<std::string>& DownloadHandlerConstants::getBtExtensions()
|
||||
{
|
||||
static const std::deque<std::string> l
|
||||
static const std::vector<std::string> l
|
||||
(&BT_EXTENSIONS[0],
|
||||
&BT_EXTENSIONS[arrayLength(BT_EXTENSIONS)]);
|
||||
return l;
|
||||
}
|
||||
|
||||
const std::deque<std::string>& DownloadHandlerConstants::getBtContentTypes()
|
||||
const std::vector<std::string>& DownloadHandlerConstants::getBtContentTypes()
|
||||
{
|
||||
static const std::deque<std::string> l
|
||||
static const std::vector<std::string> l
|
||||
(&BT_CONTENT_TYPES[0],
|
||||
&BT_CONTENT_TYPES[arrayLength(BT_CONTENT_TYPES)]);
|
||||
return l;
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -46,19 +46,19 @@ class DownloadHandlerConstants
|
|||
public:
|
||||
static const char* METALINK_EXTENSIONS[];
|
||||
|
||||
static const std::deque<std::string>& getMetalinkExtensions();
|
||||
static const std::vector<std::string>& getMetalinkExtensions();
|
||||
|
||||
static const char* METALINK_CONTENT_TYPES[];
|
||||
|
||||
static const std::deque<std::string>& getMetalinkContentTypes();
|
||||
static const std::vector<std::string>& getMetalinkContentTypes();
|
||||
|
||||
static const char* BT_EXTENSIONS[];
|
||||
|
||||
static const std::deque<std::string>& getBtExtensions();
|
||||
static const std::vector<std::string>& getBtExtensions();
|
||||
|
||||
static const char* BT_CONTENT_TYPES[];
|
||||
|
||||
static const std::deque<std::string>& getBtContentTypes();
|
||||
static const std::vector<std::string>& getBtContentTypes();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -70,8 +70,11 @@ DownloadHandlerFactory::getMetalinkPreDownloadHandler()
|
|||
_metalinkPreDownloadHandler.reset(new MemoryBufferPreDownloadHandler());
|
||||
|
||||
RequestGroupCriteriaHandle criteria
|
||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getMetalinkContentTypes(),
|
||||
DownloadHandlerConstants::getMetalinkExtensions()));
|
||||
(new ContentTypeRequestGroupCriteria
|
||||
(DownloadHandlerConstants::getMetalinkContentTypes().begin(),
|
||||
DownloadHandlerConstants::getMetalinkContentTypes().end(),
|
||||
DownloadHandlerConstants::getMetalinkExtensions().begin(),
|
||||
DownloadHandlerConstants::getMetalinkExtensions().end()));
|
||||
_metalinkPreDownloadHandler->setCriteria(criteria);
|
||||
}
|
||||
return _metalinkPreDownloadHandler;
|
||||
|
@ -97,8 +100,11 @@ DownloadHandlerFactory::getBtPreDownloadHandler()
|
|||
_btPreDownloadHandler.reset(new MemoryBufferPreDownloadHandler());
|
||||
|
||||
RequestGroupCriteriaHandle criteria
|
||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getBtContentTypes(),
|
||||
DownloadHandlerConstants::getBtExtensions()));
|
||||
(new ContentTypeRequestGroupCriteria
|
||||
(DownloadHandlerConstants::getBtContentTypes().begin(),
|
||||
DownloadHandlerConstants::getBtContentTypes().end(),
|
||||
DownloadHandlerConstants::getBtExtensions().begin(),
|
||||
DownloadHandlerConstants::getBtExtensions().end()));
|
||||
_btPreDownloadHandler->setCriteria(criteria);
|
||||
}
|
||||
return _btPreDownloadHandler;
|
||||
|
|
|
@ -50,8 +50,11 @@ namespace aria2 {
|
|||
MetalinkPostDownloadHandler::MetalinkPostDownloadHandler()
|
||||
{
|
||||
SharedHandle<RequestGroupCriteria> cri
|
||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getMetalinkContentTypes(),
|
||||
DownloadHandlerConstants::getMetalinkExtensions()));
|
||||
(new ContentTypeRequestGroupCriteria
|
||||
(DownloadHandlerConstants::getMetalinkContentTypes().begin(),
|
||||
DownloadHandlerConstants::getMetalinkContentTypes().end(),
|
||||
DownloadHandlerConstants::getMetalinkExtensions().begin(),
|
||||
DownloadHandlerConstants::getMetalinkExtensions().end()));
|
||||
setCriteria(cri);
|
||||
}
|
||||
|
||||
|
@ -63,7 +66,8 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
|
|||
{
|
||||
_logger->debug("Generating RequestGroups for Metalink file %s",
|
||||
requestGroup->getFirstFilePath().c_str());
|
||||
SharedHandle<DiskAdaptor> diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor();
|
||||
SharedHandle<DiskAdaptor> diskAdaptor =
|
||||
requestGroup->getPieceStorage()->getDiskAdaptor();
|
||||
try {
|
||||
diskAdaptor->openExistingFile();
|
||||
//requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
|
||||
|
|
Loading…
Reference in New Issue