mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-11 07:46:17 -07:00
Join the similar code paths
This commit is contained in:
parent
76bb4e5f98
commit
3691eb948e
1 changed files with 22 additions and 28 deletions
|
@ -2903,14 +2903,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loadTorrentParams.hasFinishedStatus)
|
if (!loadTorrentParams.hasFinishedStatus)
|
||||||
{
|
|
||||||
needFindIncompleteFiles = true;
|
needFindIncompleteFiles = true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int index = 0; index < filePaths.size(); ++index)
|
|
||||||
p.renamed_files[nativeIndexes[index]] = filePaths.at(index).toString().toStdString();
|
|
||||||
}
|
|
||||||
|
|
||||||
const int internalFilesCount = torrentInfo.nativeInfo()->files().num_files(); // including .pad files
|
const int internalFilesCount = torrentInfo.nativeInfo()->files().num_files(); // including .pad files
|
||||||
// Use qBittorrent default priority rather than libtorrent's (4)
|
// Use qBittorrent default priority rather than libtorrent's (4)
|
||||||
|
@ -2930,8 +2923,6 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
|
||||||
loadTorrentParams.name = QString::fromStdString(p.name);
|
loadTorrentParams.name = QString::fromStdString(p.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.save_path = actualSavePath.toString().toStdString();
|
|
||||||
|
|
||||||
if (isAddTrackersEnabled() && !(hasMetadata && p.ti->priv()))
|
if (isAddTrackersEnabled() && !(hasMetadata && p.ti->priv()))
|
||||||
{
|
{
|
||||||
const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend());
|
const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend());
|
||||||
|
@ -3006,34 +2997,37 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
|
||||||
if (infoHash.isHybrid())
|
if (infoHash.isHybrid())
|
||||||
m_hybridTorrentsByAltID.insert(altID, nullptr);
|
m_hybridTorrentsByAltID.insert(altID, nullptr);
|
||||||
|
|
||||||
if (needFindIncompleteFiles)
|
const auto resolveFileNames = [&, this]
|
||||||
{
|
{
|
||||||
const Path actualDownloadPath = useAutoTMM
|
if (!needFindIncompleteFiles)
|
||||||
|
return QtFuture::makeReadyValueFuture(FileSearchResult {.savePath = actualSavePath, .fileNames = filePaths});
|
||||||
|
|
||||||
|
const Path actualDownloadPath = loadTorrentParams.useAutoTMM
|
||||||
? categoryDownloadPath(loadTorrentParams.category) : loadTorrentParams.downloadPath;
|
? categoryDownloadPath(loadTorrentParams.category) : loadTorrentParams.downloadPath;
|
||||||
findIncompleteFiles(actualSavePath, actualDownloadPath, filePaths).then(this
|
return findIncompleteFiles(actualSavePath, actualDownloadPath, filePaths);
|
||||||
, [this, id](const FileSearchResult &result)
|
};
|
||||||
|
|
||||||
|
resolveFileNames().then(this, [this, id](const FileSearchResult &result)
|
||||||
|
{
|
||||||
|
const auto loadingTorrentsIter = m_loadingTorrents.find(id);
|
||||||
|
Q_ASSERT(loadingTorrentsIter != m_loadingTorrents.end());
|
||||||
|
if (loadingTorrentsIter == m_loadingTorrents.end()) [[unlikely]]
|
||||||
|
return;
|
||||||
|
|
||||||
|
LoadTorrentParams ¶ms = loadingTorrentsIter.value();
|
||||||
|
lt::add_torrent_params &p = params.ltAddTorrentParams;
|
||||||
|
|
||||||
|
p.save_path = result.savePath.toString().toStdString();
|
||||||
|
if (p.ti)
|
||||||
{
|
{
|
||||||
const auto loadingTorrentsIter = m_loadingTorrents.find(id);
|
|
||||||
Q_ASSERT(loadingTorrentsIter != m_loadingTorrents.end());
|
|
||||||
if (loadingTorrentsIter == m_loadingTorrents.end()) [[unlikely]]
|
|
||||||
return;
|
|
||||||
|
|
||||||
LoadTorrentParams ¶ms = loadingTorrentsIter.value();
|
|
||||||
lt::add_torrent_params &p = params.ltAddTorrentParams;
|
|
||||||
|
|
||||||
p.save_path = result.savePath.toString().toStdString();
|
|
||||||
const TorrentInfo torrentInfo {*p.ti};
|
const TorrentInfo torrentInfo {*p.ti};
|
||||||
const auto nativeIndexes = torrentInfo.nativeIndexes();
|
const auto nativeIndexes = torrentInfo.nativeIndexes();
|
||||||
for (int i = 0; i < result.fileNames.size(); ++i)
|
for (int i = 0; i < result.fileNames.size(); ++i)
|
||||||
p.renamed_files[nativeIndexes[i]] = result.fileNames[i].toString().toStdString();
|
p.renamed_files[nativeIndexes[i]] = result.fileNames[i].toString().toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
m_nativeSession->async_add_torrent(p);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_nativeSession->async_add_torrent(p);
|
m_nativeSession->async_add_torrent(p);
|
||||||
}
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue