31 #include <libtorrent/create_torrent.hpp>
32 #include <libtorrent/error_code.hpp>
39 #include <QStringList>
55 : m_nativeInfo {
std::make_shared<const lt::torrent_info>(nativeInfo)}
59 const lt::file_storage &fileStorage =
m_nativeInfo->orig_files();
61 for (
const lt::file_index_t nativeIndex : fileStorage.file_range())
63 if (!fileStorage.pad_file_at(nativeIndex))
69 : m_nativeInfo {other.m_nativeInfo}
70 , m_nativeIndexes {other.m_nativeIndexes}
93 const int depthLimit = 100;
94 const int tokenLimit = 10000000;
97 const lt::bdecode_node node = lt::bdecode(data, ec
98 ,
nullptr, depthLimit, tokenLimit);
100 return nonstd::make_unexpected(QString::fromStdString(ec.message()));
102 lt::torrent_info nativeInfo {node, ec};
104 return nonstd::make_unexpected(QString::fromStdString(ec.message()));
112 if (!
file.open(QIODevice::ReadOnly))
113 return nonstd::make_unexpected(
file.errorString());
121 data =
file.readAll();
123 catch (
const std::bad_alloc &
e)
125 return nonstd::make_unexpected(tr(
"Torrent file read error: %1").arg(
e.what()));
128 if (data.size() !=
file.size())
129 return nonstd::make_unexpected(tr(
"Torrent file read error: size mismatch"));
139 return nonstd::make_unexpected(tr(
"Invalid metadata"));
143 const auto torrentCreator = lt::create_torrent(*
nativeInfo());
144 const lt::entry torrentEntry = torrentCreator.generate();
147 return result.get_unexpected();
149 catch (
const lt::system_error &err)
151 return nonstd::make_unexpected(QString::fromLocal8Bit(err.what()));
161 #ifdef QBT_USES_LIBTORRENT2
172 return QString::fromStdString(
m_nativeInfo->orig_files().name());
180 return ((date != 0) ? QDateTime::fromSecsSinceEpoch(date) : QDateTime());
229 return m_nativeInfo->piece_size(lt::piece_index_t {index});
277 QVector<TrackerEntry> ret;
278 ret.reserve(
static_cast<decltype(ret)::size_type
>(
trackers.size()));
280 for (
const lt::announce_entry &tracker :
trackers)
281 ret.append({QString::fromStdString(tracker.url)});
290 const std::vector<lt::web_seed_entry> &nativeWebSeeds =
m_nativeInfo->web_seeds();
293 urlSeeds.reserve(
static_cast<decltype(
urlSeeds)::size_type
>(nativeWebSeeds.size()));
295 for (
const lt::web_seed_entry &webSeed : nativeWebSeeds)
297 if (webSeed.type == lt::web_seed_entry::url_seed)
298 urlSeeds.append(QUrl(webSeed.url.c_str()));
307 #ifdef QBT_USES_LIBTORRENT2
308 const lt::span<const char> infoSection {
m_nativeInfo->info_section()};
309 return {infoSection.data(),
static_cast<int>(infoSection.size())};
321 res.reserve(fileIndices.size());
322 std::transform(fileIndices.begin(), fileIndices.end(), std::back_inserter(res),
323 [
this](
int i) { return filePath(i); });
334 lt::piece_index_t {pieceIndex}, 0,
m_nativeInfo->piece_size(lt::piece_index_t {pieceIndex}));
336 res.reserve(
static_cast<decltype(res)::size_type
>(
files.size()));
337 for (
const lt::file_slice &fileSlice :
files)
353 QVector<QByteArray> hashes;
354 hashes.reserve(count);
356 for (
int i = 0; i < count; ++i)
370 qDebug() <<
"Filename" <<
file <<
"was not found in torrent" <<
name();
383 qDebug() <<
"File index (" <<
fileIndex <<
") is out of range for torrent" <<
name();
395 return {beginIdx, 0};
428 return TorrentContentLayout::Original;
438 return std::make_shared<lt::torrent_info>(*
m_nativeInfo);
QVector< QUrl > urlSeeds() const
static nonstd::expected< TorrentInfo, QString > load(const QByteArray &data) noexcept
QStringList filesForPiece(int pieceIndex) const
qlonglong totalSize() const
QVector< lt::file_index_t > nativeIndexes() const
QVector< TrackerEntry > trackers() const
qlonglong fileOffset(int index) const
QString filePath(int index) const
InfoHash infoHash() const
int fileIndex(const QString &fileName) const
QVector< lt::file_index_t > m_nativeIndexes
TorrentInfo & operator=(const TorrentInfo &other)
TorrentContentLayout contentLayout() const
PieceRange filePieces(const QString &file) const
std::shared_ptr< lt::torrent_info > nativeInfo() const
QStringList filePaths() const
QDateTime creationDate() const
QByteArray metadata() const
std::shared_ptr< const lt::torrent_info > m_nativeInfo
bool hasRootFolder() const
QString rootFolder() const
QVector< QByteArray > pieceHashes() const
qlonglong fileSize(int index) const
QVector< int > fileIndicesForPiece(int pieceIndex) const
nonstd::expected< void, QString > saveToFile(const QString &path) const
static nonstd::expected< TorrentInfo, QString > loadFromFile(const QString &path) noexcept
static constexpr int length()
const int MAX_TORRENT_SIZE
flag icons free of to any person obtaining a copy of this software and associated documentation files(the "Software")
constexpr IndexInterval< T > makeInterval(const T first, const T last)
TorrentContentLayout detectContentLayout(const QStringList &filePaths)
QString fileName(const QString &filePath)
QString findRootFolder(const QStringList &filePaths)
QString toUniformPath(const QString &path)
nonstd::expected< void, QString > saveToFile(const QString &path, const QByteArray &data)
QString friendlyUnit(qint64 bytes, bool isSpeed=false)
file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts") set_source_files_properties($