Join the similar code paths

This commit is contained in:
Vladimir Golovnev (Glassez) 2025-05-02 14:05:26 +03:00
parent 76bb4e5f98
commit 3691eb948e
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7

View file

@ -2903,14 +2903,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
}
if (!loadTorrentParams.hasFinishedStatus)
{
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
// 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);
}
p.save_path = actualSavePath.toString().toStdString();
if (isAddTrackersEnabled() && !(hasMetadata && p.ti->priv()))
{
const auto maxTierIter = std::max_element(p.tracker_tiers.cbegin(), p.tracker_tiers.cend());
@ -3006,12 +2997,17 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
if (infoHash.isHybrid())
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;
findIncompleteFiles(actualSavePath, actualDownloadPath, filePaths).then(this
, [this, id](const FileSearchResult &result)
return findIncompleteFiles(actualSavePath, actualDownloadPath, filePaths);
};
resolveFileNames().then(this, [this, id](const FileSearchResult &result)
{
const auto loadingTorrentsIter = m_loadingTorrents.find(id);
Q_ASSERT(loadingTorrentsIter != m_loadingTorrents.end());
@ -3022,18 +3018,16 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
lt::add_torrent_params &p = params.ltAddTorrentParams;
p.save_path = result.savePath.toString().toStdString();
if (p.ti)
{
const TorrentInfo torrentInfo {*p.ti};
const auto nativeIndexes = torrentInfo.nativeIndexes();
for (int i = 0; i < result.fileNames.size(); ++i)
p.renamed_files[nativeIndexes[i]] = result.fileNames[i].toString().toStdString();
}
m_nativeSession->async_add_torrent(p);
});
}
else
{
m_nativeSession->async_add_torrent(p);
}
return true;
}