diff --git a/.gitignore b/.gitignore index 282ebe32..69a81a20 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ compile main.log main.trs test-suite.log +.vscode/ diff --git a/src/File.cc b/src/File.cc index a98dca61..753fdcc4 100644 --- a/src/File.cc +++ b/src/File.cc @@ -372,6 +372,11 @@ Time File::getModifiedTime() return Time(fstat.st_mtime); } +std::string File::getExtension() const +{ + return name_.substr(name_.find_last_of(".")); +} + std::string File::getCurrentDir() { #ifdef __MINGW32__ diff --git a/src/File.h b/src/File.h index 6d304640..85a69a5d 100644 --- a/src/File.h +++ b/src/File.h @@ -120,6 +120,8 @@ public: Time getModifiedTime(); + std::string getExtension() const; + // Returns the current working directory. If the current working // directory cannot be retrieved or its length is larger than 2048, // returns ".". diff --git a/src/ProtocolDetector.cc b/src/ProtocolDetector.cc index cc7016fc..1e496202 100644 --- a/src/ProtocolDetector.cc +++ b/src/ProtocolDetector.cc @@ -46,6 +46,7 @@ #ifdef ENABLE_BITTORRENT # include "bittorrent_helper.h" #endif // ENABLE_BITTORRENT +#include "DefaultBtProgressInfoFile.h" namespace aria2 { @@ -107,4 +108,16 @@ 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/ProtocolDetector.h b/src/ProtocolDetector.h index 54652cb1..a638eb24 100644 --- a/src/ProtocolDetector.h +++ b/src/ProtocolDetector.h @@ -60,6 +60,10 @@ public: // Returns true if ProtocolDetector thinks uri is a path of Metalink XML // file, otherwise return false. bool guessMetalinkFile(const std::string& uri) const; + + // Returns true if ProtocolDetector thinks uri is a path to aria2 control + // file, otherwise return false + bool guessAria2ControlFile(const std::string& uri) const; }; } // namespace aria2 diff --git a/src/download_helper.cc b/src/download_helper.cc index 6118aa14..ca903f71 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -445,7 +445,13 @@ public: } } } + #endif // ENABLE_METALINK +//TOOD: ifdef of ENABLE aria2 + else if (!ignoreLocalPath_ && detector_.guessAria2ControlFile(uri)) + { + + } else { if (throwOnError_) { throw DL_ABORT_EX(fmt(MSG_UNRECOGNIZED_URI, uri.c_str())); diff --git a/test/ProtocolDetectorTest.cc b/test/ProtocolDetectorTest.cc index a2b6c790..3d5d988b 100644 --- a/test/ProtocolDetectorTest.cc +++ b/test/ProtocolDetectorTest.cc @@ -14,6 +14,7 @@ class ProtocolDetectorTest : public CppUnit::TestFixture { CPPUNIT_TEST(testGuessTorrentFile); CPPUNIT_TEST(testGuessTorrentMagnet); CPPUNIT_TEST(testGuessMetalinkFile); + CPPUNIT_TEST(testGuessAria2ControlFile); CPPUNIT_TEST_SUITE_END(); public: @@ -25,6 +26,7 @@ public: void testGuessTorrentFile(); void testGuessTorrentMagnet(); void testGuessMetalinkFile(); + void testGuessAria2ControlFile(); }; CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest); @@ -66,4 +68,12 @@ void ProtocolDetectorTest::testGuessMetalinkFile() CPPUNIT_ASSERT(!detector.guessMetalinkFile(A2_TEST_DIR "/test.torrent")); } +void ProtocolDetectorTest::testGuessAria2ControlFile() +{ + const ProtocolDetector detector; + CPPUNIT_ASSERT(detector.guessAria2ControlFile(A2_TEST_DIR "/control_file.aria2")); + CPPUNIT_ASSERT(!detector.guessAria2ControlFile(A2_TEST_DIR)); + CPPUNIT_ASSERT(detector.guessAria2ControlFile(A2_TEST_DIR "/control_file.aria")); +} + } // namespace aria2