1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Add fast way of removing suggested extension

This commit is contained in:
Vladimir Golovnev (Glassez) 2022-02-15 09:31:35 +03:00
parent 293479a1f2
commit 1e45b7f50b
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
4 changed files with 12 additions and 7 deletions

View File

@ -209,7 +209,7 @@ void CustomDiskIOThread::handleCompleteFiles(lt::storage_index_t storage, const
{
const Path incompleteFilePath = savePath / filePath;
Path completeFilePath = incompleteFilePath;
completeFilePath.removeExtension();
completeFilePath.removeExtension(QB_EXT);
if (completeFilePath.exists())
{
Utils::Fs::removeFile(incompleteFilePath);

View File

@ -294,8 +294,7 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
m_indexMap[nativeIndex] = i;
Path filePath {fileStorage.file_path(nativeIndex)};
if (filePath.hasExtension(QB_EXT))
filePath.removeExtension();
filePath.removeExtension(QB_EXT);
m_filePaths.append(filePath);
const auto priority = LT::fromNative(filePriorities[LT::toUnderlyingType(nativeIndex)]);
@ -1511,8 +1510,7 @@ void TorrentImpl::endReceivedMetadataHandling(const Path &savePath, const PathLi
Path filePath = fileNames.at(i);
p.renamed_files[nativeIndex] = filePath.toString().toStdString();
if (filePath.hasExtension(QB_EXT))
filePath.removeExtension();
filePath.removeExtension(QB_EXT);
m_filePaths.append(filePath);
const auto priority = LT::fromNative(filePriorities[LT::toUnderlyingType(nativeIndex)]);

View File

@ -149,13 +149,13 @@ QString Path::extension() const
const int slashIndex = m_pathStr.lastIndexOf(QLatin1Char('/'));
const auto filename = QStringView(m_pathStr).mid(slashIndex + 1);
const int dotIndex = filename.lastIndexOf(QLatin1Char('.'));
const int dotIndex = filename.lastIndexOf(QLatin1Char('.'), -2);
return ((dotIndex == -1) ? QString() : filename.mid(dotIndex).toString());
}
bool Path::hasExtension(const QString &ext) const
{
Q_ASSERT(ext.startsWith(QLatin1Char('.')));
Q_ASSERT(ext.startsWith(QLatin1Char('.')) && (ext.size() >= 2));
return m_pathStr.endsWith(ext, Qt::CaseInsensitive);
}
@ -183,6 +183,12 @@ void Path::removeExtension()
m_pathStr.chop(extension().size());
}
void Path::removeExtension(const QString &ext)
{
if (hasExtension(ext))
m_pathStr.chop(ext.size());
}
QString Path::data() const
{
return m_pathStr;

View File

@ -58,6 +58,7 @@ public:
QString extension() const;
bool hasExtension(const QString &ext) const;
void removeExtension();
void removeExtension(const QString &ext);
bool hasAncestor(const Path &other) const;
Path relativePathOf(const Path &childPath) const;