mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-26 16:15:10 -07:00
Optimize completed files handling
PR #16329. Co-authored-by: Vladimir Golovnev (Glassez) <glassez@yandex.ru>
This commit is contained in:
parent
b3d46ecb78
commit
71174edf72
2 changed files with 18 additions and 7 deletions
|
@ -273,13 +273,16 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
|
|||
m_torrentInfo = TorrentInfo(*m_ltAddTorrentParams.ti);
|
||||
|
||||
Q_ASSERT(m_filePaths.isEmpty());
|
||||
Q_ASSERT(m_indexMap.isEmpty());
|
||||
const int filesCount = m_torrentInfo.filesCount();
|
||||
m_filePaths.reserve(filesCount);
|
||||
m_indexMap.reserve(filesCount);
|
||||
const std::shared_ptr<const lt::torrent_info> currentInfo = m_nativeHandle.torrent_file();
|
||||
const lt::file_storage &fileStorage = currentInfo->files();
|
||||
for (int i = 0; i < filesCount; ++i)
|
||||
{
|
||||
const lt::file_index_t nativeIndex = m_torrentInfo.nativeIndexes().at(i);
|
||||
m_indexMap[nativeIndex] = i;
|
||||
const QString filePath = Utils::Fs::toUniformPath(QString::fromStdString(fileStorage.file_path(nativeIndex)));
|
||||
m_filePaths.append(filePath);
|
||||
}
|
||||
|
@ -1500,14 +1503,22 @@ void TorrentImpl::fileSearchFinished(const QString &savePath, const QStringList
|
|||
|
||||
void TorrentImpl::endReceivedMetadataHandling(const QString &savePath, const QStringList &fileNames)
|
||||
{
|
||||
Q_ASSERT(m_filePaths.isEmpty());
|
||||
Q_ASSERT(m_indexMap.isEmpty());
|
||||
|
||||
lt::add_torrent_params &p = m_ltAddTorrentParams;
|
||||
|
||||
const std::shared_ptr<lt::torrent_info> metadata = std::const_pointer_cast<lt::torrent_info>(m_nativeHandle.torrent_file());
|
||||
m_torrentInfo = TorrentInfo(*metadata);
|
||||
m_filePaths = fileNames;
|
||||
m_indexMap.reserve(filesCount());
|
||||
const auto nativeIndexes = m_torrentInfo.nativeIndexes();
|
||||
for (int i = 0; i < fileNames.size(); ++i)
|
||||
p.renamed_files[nativeIndexes[i]] = fileNames[i].toStdString();
|
||||
{
|
||||
const auto nativeIndex = nativeIndexes.at(i);
|
||||
m_indexMap[nativeIndex] = i;
|
||||
p.renamed_files[nativeIndex] = fileNames[i].toStdString();
|
||||
}
|
||||
p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
|
||||
p.ti = metadata;
|
||||
|
||||
|
@ -1862,7 +1873,7 @@ void TorrentImpl::handleFastResumeRejectedAlert(const lt::fastresume_rejected_al
|
|||
|
||||
void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p)
|
||||
{
|
||||
const int fileIndex = m_torrentInfo.nativeIndexes().indexOf(p->index);
|
||||
const int fileIndex = m_indexMap.value(p->index, -1);
|
||||
Q_ASSERT(fileIndex >= 0);
|
||||
|
||||
// Remove empty leftover folders
|
||||
|
@ -1908,7 +1919,7 @@ void TorrentImpl::handleFileRenamedAlert(const lt::file_renamed_alert *p)
|
|||
|
||||
void TorrentImpl::handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p)
|
||||
{
|
||||
const int fileIndex = m_torrentInfo.nativeIndexes().indexOf(p->index);
|
||||
const int fileIndex = m_indexMap.value(p->index, -1);
|
||||
Q_ASSERT(fileIndex >= 0);
|
||||
|
||||
LogMsg(tr("File rename failed. Torrent: \"%1\", file: \"%2\", reason: \"%3\"")
|
||||
|
@ -1923,12 +1934,11 @@ void TorrentImpl::handleFileRenameFailedAlert(const lt::file_rename_failed_alert
|
|||
|
||||
void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p)
|
||||
{
|
||||
const int fileIndex = m_torrentInfo.nativeIndexes().indexOf(p->index);
|
||||
Q_ASSERT(fileIndex >= 0);
|
||||
|
||||
qDebug("A file completed download in torrent \"%s\"", qUtf8Printable(name()));
|
||||
if (m_session->isAppendExtensionEnabled())
|
||||
{
|
||||
const int fileIndex = m_indexMap.value(p->index, -1);
|
||||
Q_ASSERT(fileIndex >= 0);
|
||||
|
||||
QString name = filePath(fileIndex);
|
||||
if (name.endsWith(QB_EXT))
|
||||
{
|
||||
|
|
|
@ -286,6 +286,7 @@ namespace BitTorrent
|
|||
TorrentState m_state = TorrentState::Unknown;
|
||||
TorrentInfo m_torrentInfo;
|
||||
QStringList m_filePaths;
|
||||
QHash<lt::file_index_t, int> m_indexMap;
|
||||
SpeedMonitor m_speedMonitor;
|
||||
|
||||
InfoHash m_infoHash;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue