1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-05 11:24:15 +00:00

Merge pull request #16428 from Chocobo1/path

Improve Path constructor
This commit is contained in:
Chocobo1 2022-02-14 14:02:50 +08:00 committed by GitHub
commit bc94de5626
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -65,6 +65,6 @@ namespace BitTorrent::LT
for (int i = 0; i < dataLength; ++i) for (int i = 0; i < dataLength; ++i)
tmp[i] = reverseByte(bitsData[i]); tmp[i] = reverseByte(bitsData[i]);
return QBitArray::fromBits(tmp.data(), tmp.size()); return QBitArray::fromBits(tmp.data(), bits.size());
} }
} }

View File

@ -29,6 +29,8 @@
#include "path.h" #include "path.h"
#include <algorithm>
#include <QDataStream> #include <QDataStream>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
@ -44,8 +46,20 @@ const Qt::CaseSensitivity CASE_SENSITIVITY = Qt::CaseSensitive;
const int PATHLIST_TYPEID = qRegisterMetaType<PathList>("PathList"); const int PATHLIST_TYPEID = qRegisterMetaType<PathList>("PathList");
namespace
{
QString cleanPath(const QString &path)
{
const bool hasSeparator = std::any_of(path.cbegin(), path.cend(), [](const QChar c)
{
return (c == u'/') || (c == u'\\');
});
return hasSeparator ? QDir::cleanPath(path) : path;
}
}
Path::Path(const QString &pathStr) Path::Path(const QString &pathStr)
: m_pathStr {QDir::cleanPath(pathStr)} : m_pathStr {cleanPath(pathStr)}
{ {
} }