mirror of https://github.com/aria2/aria2
[ProtocolDetector] Added detector for aria2 control file
parent
02f2d0d847
commit
273dee180c
|
@ -44,3 +44,4 @@ compile
|
||||||
main.log
|
main.log
|
||||||
main.trs
|
main.trs
|
||||||
test-suite.log
|
test-suite.log
|
||||||
|
.vscode/
|
||||||
|
|
|
@ -372,6 +372,11 @@ Time File::getModifiedTime()
|
||||||
return Time(fstat.st_mtime);
|
return Time(fstat.st_mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string File::getExtension() const
|
||||||
|
{
|
||||||
|
return name_.substr(name_.find_last_of("."));
|
||||||
|
}
|
||||||
|
|
||||||
std::string File::getCurrentDir()
|
std::string File::getCurrentDir()
|
||||||
{
|
{
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
|
|
|
@ -120,6 +120,8 @@ public:
|
||||||
|
|
||||||
Time getModifiedTime();
|
Time getModifiedTime();
|
||||||
|
|
||||||
|
std::string getExtension() const;
|
||||||
|
|
||||||
// Returns the current working directory. If the current working
|
// Returns the current working directory. If the current working
|
||||||
// directory cannot be retrieved or its length is larger than 2048,
|
// directory cannot be retrieved or its length is larger than 2048,
|
||||||
// returns ".".
|
// returns ".".
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "bittorrent_helper.h"
|
# include "bittorrent_helper.h"
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
#include "DefaultBtProgressInfoFile.h"
|
||||||
|
|
||||||
namespace aria2 {
|
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
|
} // namespace aria2
|
||||||
|
|
|
@ -60,6 +60,10 @@ public:
|
||||||
// Returns true if ProtocolDetector thinks uri is a path of Metalink XML
|
// Returns true if ProtocolDetector thinks uri is a path of Metalink XML
|
||||||
// file, otherwise return false.
|
// file, otherwise return false.
|
||||||
bool guessMetalinkFile(const std::string& uri) const;
|
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
|
} // namespace aria2
|
||||||
|
|
|
@ -445,7 +445,13 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
|
//TOOD: ifdef of ENABLE aria2
|
||||||
|
else if (!ignoreLocalPath_ && detector_.guessAria2ControlFile(uri))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (throwOnError_) {
|
if (throwOnError_) {
|
||||||
throw DL_ABORT_EX(fmt(MSG_UNRECOGNIZED_URI, uri.c_str()));
|
throw DL_ABORT_EX(fmt(MSG_UNRECOGNIZED_URI, uri.c_str()));
|
||||||
|
|
|
@ -14,6 +14,7 @@ class ProtocolDetectorTest : public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testGuessTorrentFile);
|
CPPUNIT_TEST(testGuessTorrentFile);
|
||||||
CPPUNIT_TEST(testGuessTorrentMagnet);
|
CPPUNIT_TEST(testGuessTorrentMagnet);
|
||||||
CPPUNIT_TEST(testGuessMetalinkFile);
|
CPPUNIT_TEST(testGuessMetalinkFile);
|
||||||
|
CPPUNIT_TEST(testGuessAria2ControlFile);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -25,6 +26,7 @@ public:
|
||||||
void testGuessTorrentFile();
|
void testGuessTorrentFile();
|
||||||
void testGuessTorrentMagnet();
|
void testGuessTorrentMagnet();
|
||||||
void testGuessMetalinkFile();
|
void testGuessMetalinkFile();
|
||||||
|
void testGuessAria2ControlFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(ProtocolDetectorTest);
|
||||||
|
@ -66,4 +68,12 @@ void ProtocolDetectorTest::testGuessMetalinkFile()
|
||||||
CPPUNIT_ASSERT(!detector.guessMetalinkFile(A2_TEST_DIR "/test.torrent"));
|
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
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue