From 9f27580f14cd95d8f433e11932491c36135cfc1b Mon Sep 17 00:00:00 2001 From: Idan Geraffi Date: Sun, 18 Feb 2024 17:14:44 +0200 Subject: [PATCH] [Config] Added support for ENABLE_CONTROL_FILE --- src/DefaultBtProgressInfoFile.cc | 4 ++-- src/ProtocolDetector.cc | 33 ++++++++++++++++++-------------- src/download_helper.cc | 12 +++++++----- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index 2a59d863..d7692206 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -256,7 +256,7 @@ std::array DefaultBtProgressInfoFile::getInfoHa throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_READ, control_file.c_str())); } - auto version = getControlFileVersion(fp, control_file); + const auto version = getControlFileVersion(fp, control_file); unsigned char extension[4]; READ_CHECK_STATIC(fp, extension, sizeof(extension), control_file); @@ -289,7 +289,7 @@ void DefaultBtProgressInfoFile::load() throw DL_ABORT_EX(fmt(EX_SEGMENT_FILE_READ, filename_.c_str())); } - auto version = getControlFileVersion(fp, filename_); + const auto version = getControlFileVersion(fp, filename_); unsigned char extension[4]; READ_CHECK(fp, extension, sizeof(extension)); diff --git a/src/ProtocolDetector.cc b/src/ProtocolDetector.cc index 9a50a5a9..94ab2492 100644 --- a/src/ProtocolDetector.cc +++ b/src/ProtocolDetector.cc @@ -46,7 +46,9 @@ #ifdef ENABLE_BITTORRENT # include "bittorrent_helper.h" #endif // ENABLE_BITTORRENT -#include "DefaultBtProgressInfoFile.h" +#ifdef ENABLE_CONTROL_FILE +# include "DefaultBtProgressInfoFile.h" +#endif // ENABLE_CONTROL_FILE namespace aria2 { @@ -91,6 +93,22 @@ bool ProtocolDetector::guessTorrentMagnet(const std::string& uri) const #endif // !ENABLE_BITTORRENT } +bool ProtocolDetector::guessAria2ControlFile(const std::string& uri) const +{ +#ifdef ENABLE_CONTROL_FILE + File control_file(uri); + + if(!control_file.isFile()) + { + return false; + } + + return control_file.getExtension() == DefaultBtProgressInfoFile::getSuffix(); +#else // !ENABLE_CONTROL_FILE + return false; +#endif // !ENABLE_CONTROL_FILE +} + bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const { BufferedFile fp(uri.c_str(), BufferedFile::READ); @@ -108,17 +126,4 @@ bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const } } -bool ProtocolDetector::guessAria2ControlFile(const std::string& uri) const -{ - File control_file(uri); - - if(!control_file.isFile()) - { - return false; - } - - const auto control_file_suffix = DefaultBtProgressInfoFile::getSuffix(); - return control_file.getExtension() == control_file_suffix; -} - } // namespace aria2 diff --git a/src/download_helper.cc b/src/download_helper.cc index 2879b8c3..155b5284 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -67,10 +67,11 @@ # include "BtConstants.h" # include "ValueBaseBencodeParser.h" #endif // ENABLE_BITTORRENT -// TODO ENABLE CONTROLFILE -#include "TorrentAttribute.h" -#include "bittorrent_helper.h" -#include "DefaultBtProgressInfoFile.h" +#ifdef ENABLE_CONTROL_FILE +# include "TorrentAttribute.h" +# include "bittorrent_helper.h" +# include "DefaultBtProgressInfoFile.h" +#endif // ENABLE_CONTROL_FILE namespace aria2 { @@ -450,7 +451,7 @@ public: } #endif // ENABLE_METALINK -//TOOD: ifdef of ENABLE aria2 +#ifdef ENABLE_CONTROL_FILE else if (!ignoreLocalPath_ && detector_.guessAria2ControlFile(uri)) { // Extract hash and construct a magnet to feed into createBtMagentRequestGroup @@ -471,6 +472,7 @@ public: } } } +#endif // ENABLE_CONTROL_FILE }; } // namespace