|
@@ -41,11 +41,15 @@
|
|
|
#include "A2STR.h"
|
|
|
#include "DownloadContext.h"
|
|
|
#include "Logger.h"
|
|
|
+#include "LogFactory.h"
|
|
|
#include "util.h"
|
|
|
#include "a2functional.h"
|
|
|
#include "DiskAdaptor.h"
|
|
|
#include "PieceStorage.h"
|
|
|
#include "bencode.h"
|
|
|
+#include "message.h"
|
|
|
+#include "prefs.h"
|
|
|
+#include "Option.h"
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
@@ -63,7 +67,8 @@ bool UTMetadataPostDownloadHandler::Criteria::match
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler()
|
|
|
+UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler():
|
|
|
+ _logger(LogFactory::getInstance())
|
|
|
{
|
|
|
setCriteria(SharedHandle<Criteria>(new Criteria()));
|
|
|
}
|
|
@@ -82,6 +87,22 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups
|
|
|
std::deque<std::string>(), torrent);
|
|
|
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
|
|
groups.insert(groups.end(), newRgs.begin(), newRgs.end());
|
|
|
+
|
|
|
+ if(!newRgs.empty() &&
|
|
|
+ requestGroup->getOption()->getAsBool(PREF_BT_SAVE_METADATA)) {
|
|
|
+ SharedHandle<DownloadContext> dctx = newRgs.front()->getDownloadContext();
|
|
|
+ assert(dctx->hasAttribute(bittorrent::BITTORRENT));
|
|
|
+ std::string filename = requestGroup->getOption()->get(PREF_DIR);
|
|
|
+ filename += A2STR::SLASH_C;
|
|
|
+ filename +=
|
|
|
+ dctx->getAttribute(bittorrent::BITTORRENT)[bittorrent::NAME].s();
|
|
|
+ filename += ".torrent";
|
|
|
+ if(util::saveAs(filename, torrent)) {
|
|
|
+ _logger->notice(MSG_METADATA_SAVED, filename.c_str());
|
|
|
+ } else {
|
|
|
+ _logger->notice(MSG_METADATA_NOT_SAVED, filename.c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
} // namespace aria2
|