@@ -2769,26 +2769,22 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
2769
2769
Q_ASSERT (p.file_priorities .empty ());
2770
2770
Q_ASSERT (addTorrentParams.filePriorities .isEmpty () || (addTorrentParams.filePriorities .size () == nativeIndexes.size ()));
2771
2771
2772
+ QList<DownloadPriority> filePriorities = addTorrentParams.filePriorities ;
2773
+
2774
+ if (filePriorities.isEmpty () && isExcludedFileNamesEnabled ())
2775
+ {
2776
+ // Check file name blacklist when priorities are not explicitly set
2777
+ applyFilenameFilter (filePaths, filePriorities);
2778
+ }
2779
+
2772
2780
const int internalFilesCount = torrentInfo.nativeInfo ()->files ().num_files (); // including .pad files
2773
2781
// Use qBittorrent default priority rather than libtorrent's (4)
2774
2782
p.file_priorities = std::vector (internalFilesCount, LT::toNative (DownloadPriority::Normal));
2775
2783
2776
- if (addTorrentParams. filePriorities .isEmpty ())
2784
+ if (! filePriorities.isEmpty ())
2777
2785
{
2778
- if (isExcludedFileNamesEnabled ())
2779
- {
2780
- // Check file name blacklist when priorities are not explicitly set
2781
- for (int i = 0 ; i < filePaths.size (); ++i)
2782
- {
2783
- if (isFilenameExcluded (filePaths.at (i).filename ()))
2784
- p.file_priorities [LT::toUnderlyingType (nativeIndexes[i])] = lt::dont_download;
2785
- }
2786
- }
2787
- }
2788
- else
2789
- {
2790
- for (int i = 0 ; i < addTorrentParams.filePriorities .size (); ++i)
2791
- p.file_priorities [LT::toUnderlyingType (nativeIndexes[i])] = LT::toNative (addTorrentParams.filePriorities [i]);
2786
+ for (int i = 0 ; i < filePriorities.size (); ++i)
2787
+ p.file_priorities [LT::toUnderlyingType (nativeIndexes[i])] = LT::toNative (filePriorities[i]);
2792
2788
}
2793
2789
2794
2790
Q_ASSERT (p.ti );
@@ -3874,21 +3870,41 @@ void SessionImpl::populateExcludedFileNamesRegExpList()
3874
3870
3875
3871
for (const QString &str : excludedNames)
3876
3872
{
3877
- const QString pattern = QRegularExpression::anchoredPattern ( QRegularExpression:: wildcardToRegularExpression (str) );
3873
+ const QString pattern = QRegularExpression::wildcardToRegularExpression (str);
3878
3874
const QRegularExpression re {pattern, QRegularExpression::CaseInsensitiveOption};
3879
3875
m_excludedFileNamesRegExpList.append (re);
3880
3876
}
3881
3877
}
3882
3878
3883
- bool SessionImpl::isFilenameExcluded (const QString &fileName) const
3879
+ void SessionImpl::applyFilenameFilter (const PathList &files, QList<DownloadPriority> &priorities)
3884
3880
{
3885
3881
if (!isExcludedFileNamesEnabled ())
3886
- return false ;
3882
+ return ;
3887
3883
3888
- return std::any_of (m_excludedFileNamesRegExpList. begin (), m_excludedFileNamesRegExpList. end (), [&fileName ](const QRegularExpression &re )
3884
+ const auto isFilenameExcluded = [patterns = m_excludedFileNamesRegExpList ](const Path &fileName )
3889
3885
{
3890
- return re.match (fileName).hasMatch ();
3891
- });
3886
+ return std::any_of (patterns.begin (), patterns.end (), [&fileName](const QRegularExpression &re)
3887
+ {
3888
+ Path path = fileName;
3889
+ while (!re.match (path.filename ()).hasMatch ())
3890
+ {
3891
+ path = path.parentPath ();
3892
+ if (path.isEmpty ())
3893
+ return false ;
3894
+ }
3895
+ return true ;
3896
+ });
3897
+ };
3898
+
3899
+ priorities.resize (files.count (), DownloadPriority::Normal);
3900
+ for (int i = 0 ; i < priorities.size (); ++i)
3901
+ {
3902
+ if (priorities[i] == BitTorrent::DownloadPriority::Ignored)
3903
+ continue ;
3904
+
3905
+ if (isFilenameExcluded (files.at (i)))
3906
+ priorities[i] = BitTorrent::DownloadPriority::Ignored;
3907
+ }
3892
3908
}
3893
3909
3894
3910
void SessionImpl::setBannedIPs (const QStringList &newList)
0 commit comments