forked from premiere/premiere-libtorrent
moved load_file into torrent_info.cpp to make it available on windows too. Fixed the exception free path in torrent_info
This commit is contained in:
parent
a71170e601
commit
40d7e2ce75
|
@ -1124,7 +1124,7 @@ The ``torrent_info`` has the following synopsis::
|
|||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
torrent_info(char const* filename);
|
||||
torrent_info(boost::filesystem::path const& filename);
|
||||
|
||||
void add_tracker(std::string const& url, int tier = 0);
|
||||
std::vector<announce_entry> const& trackers() const;
|
||||
|
@ -1181,7 +1181,7 @@ torrent_info()
|
|||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
torrent_info(char const* filename);
|
||||
torrent_info(boost::filesystem::path const& filename);
|
||||
|
||||
The constructor that takes an info-hash will initialize the info-hash to the given value,
|
||||
but leave all other fields empty. This is used internally when downloading torrents without
|
||||
|
|
|
@ -55,8 +55,6 @@ namespace libtorrent
|
|||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int load_file(fs::path const& filename, std::vector<char>& v);
|
||||
|
||||
class TORRENT_EXPORT file: public boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -64,6 +64,7 @@ namespace libtorrent
|
|||
{
|
||||
namespace pt = boost::posix_time;
|
||||
namespace gr = boost::gregorian;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
struct TORRENT_EXPORT announce_entry
|
||||
{
|
||||
|
@ -79,6 +80,8 @@ namespace libtorrent
|
|||
};
|
||||
#endif
|
||||
|
||||
int TORRENT_EXPORT load_file(fs::path const& filename, std::vector<char>& v);
|
||||
|
||||
class TORRENT_EXPORT torrent_info : public intrusive_ptr_base<torrent_info>
|
||||
{
|
||||
public:
|
||||
|
@ -86,7 +89,7 @@ namespace libtorrent
|
|||
torrent_info(sha1_hash const& info_hash);
|
||||
torrent_info(lazy_entry const& torrent_file);
|
||||
torrent_info(char const* buffer, int size);
|
||||
torrent_info(char const* filename);
|
||||
torrent_info(fs::path const& filename);
|
||||
~torrent_info();
|
||||
|
||||
file_storage const& files() const { return m_files; }
|
||||
|
|
14
src/file.cpp
14
src/file.cpp
|
@ -133,20 +133,6 @@ namespace libtorrent
|
|||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int load_file(fs::path const& filename, std::vector<char>& v)
|
||||
{
|
||||
file f;
|
||||
if (!f.open(filename, file::in)) return -1;
|
||||
f.seek(0, file::end);
|
||||
size_type s = f.tell();
|
||||
if (s > 5000000) return -2;
|
||||
v.resize(s);
|
||||
f.seek(0);
|
||||
size_type read = f.read(&v[0], s);
|
||||
if (read != s) return -3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const file::open_mode file::in(mode_in);
|
||||
const file::open_mode file::out(mode_out);
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/next_prior.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -208,6 +207,21 @@ namespace
|
|||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
int load_file(fs::path const& filename, std::vector<char>& v)
|
||||
{
|
||||
file f;
|
||||
if (!f.open(filename, file::in)) return -1;
|
||||
f.seek(0, file::end);
|
||||
size_type s = f.tell();
|
||||
if (s > 5000000) return -2;
|
||||
v.resize(s);
|
||||
f.seek(0);
|
||||
size_type read = f.read(&v[0], s);
|
||||
if (read != s) return -3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// standard constructor that parses a torrent file
|
||||
torrent_info::torrent_info(entry const& torrent_file)
|
||||
: m_creation_date(pt::ptime(pt::not_a_date_time))
|
||||
|
@ -227,7 +241,7 @@ namespace libtorrent
|
|||
if (!parse_torrent_file(e, error))
|
||||
throw invalid_torrent_file();
|
||||
#else
|
||||
read_torrent_info(e, error);
|
||||
parse_torrent_file(e, error);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -243,7 +257,7 @@ namespace libtorrent
|
|||
if (!parse_torrent_file(torrent_file, error))
|
||||
throw invalid_torrent_file();
|
||||
#else
|
||||
read_torrent_info(torrent_file, error);
|
||||
parse_torrent_file(torrent_file, error);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -261,7 +275,7 @@ namespace libtorrent
|
|||
if (!parse_torrent_file(e, error))
|
||||
throw invalid_torrent_file();
|
||||
#else
|
||||
read_torrent_info(e, error);
|
||||
parse_torrent_file(e, error);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -278,7 +292,7 @@ namespace libtorrent
|
|||
, m_piece_hashes(0)
|
||||
{}
|
||||
|
||||
torrent_info::torrent_info(char const* filename)
|
||||
torrent_info::torrent_info(fs::path const& filename)
|
||||
: m_creation_date(pt::ptime(pt::not_a_date_time))
|
||||
, m_multifile(false)
|
||||
, m_private(false)
|
||||
|
@ -294,7 +308,7 @@ namespace libtorrent
|
|||
if (!parse_torrent_file(e, error))
|
||||
throw invalid_torrent_file();
|
||||
#else
|
||||
read_torrent_info(e, error);
|
||||
parse_torrent_file(e, error);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue