mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 12:59:56 -07:00
Update QTorrentHandle
Guaranteed to accept strings with both native and qt-style separators; guaranteed to use native separators with libtorrent API
This commit is contained in:
parent
b706210349
commit
32b90a7b6d
2 changed files with 19 additions and 22 deletions
|
@ -223,11 +223,9 @@ int QTorrentHandle::num_incomplete() const {
|
||||||
|
|
||||||
QString QTorrentHandle::save_path() const {
|
QString QTorrentHandle::save_path() const {
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return misc::toQStringU(torrent_handle::save_path())
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::save_path()));
|
||||||
.replace("\\", "/");
|
|
||||||
#else
|
#else
|
||||||
return misc::toQStringU(status(torrent_handle::query_save_path).save_path)
|
return fsutils::fromNativePath(misc::toQStringU(status(torrent_handle::query_save_path).save_path));
|
||||||
.replace("\\", "/");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,13 +234,10 @@ QString QTorrentHandle::save_path_parsed() const {
|
||||||
if (has_metadata() && num_files() == 1) {
|
if (has_metadata() && num_files() == 1) {
|
||||||
p = firstFileSavePath();
|
p = firstFileSavePath();
|
||||||
} else {
|
} else {
|
||||||
p = TorrentPersistentData::getSavePath(hash());
|
p = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
||||||
if (p.isEmpty())
|
if (p.isEmpty())
|
||||||
p = save_path();
|
p = save_path();
|
||||||
}
|
}
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
|
||||||
p.replace("/", "\\");
|
|
||||||
#endif
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,18 +301,19 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const {
|
||||||
|
|
||||||
QString QTorrentHandle::filepath_at(unsigned int index) const {
|
QString QTorrentHandle::filepath_at(unsigned int index) const {
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return misc::toQStringU(torrent_handle::get_torrent_info().files().file_path(index));
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().files().file_path(index)));
|
||||||
#else
|
#else
|
||||||
return misc::toQStringU(torrent_handle::torrent_file()->files().file_path(index));
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::torrent_file()->files().file_path(index)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
|
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index));
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index)));
|
||||||
#else
|
#else
|
||||||
return misc::toQStringU(torrent_handle::torrent_file()->orig_files().file_path(index));
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::torrent_file()->orig_files().file_path(index)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent_status::state_t QTorrentHandle::state() const {
|
torrent_status::state_t QTorrentHandle::state() const {
|
||||||
|
@ -379,7 +375,7 @@ QStringList QTorrentHandle::absolute_files_path() const {
|
||||||
QDir saveDir(save_path());
|
QDir saveDir(save_path());
|
||||||
QStringList res;
|
QStringList res;
|
||||||
for (int i = 0; i<num_files(); ++i) {
|
for (int i = 0; i<num_files(); ++i) {
|
||||||
res << QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
|
res << fsutils::expandPathAbs(saveDir.absoluteFilePath(filepath_at(i)));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -390,7 +386,7 @@ QStringList QTorrentHandle::absolute_files_path_uneeded() const {
|
||||||
std::vector<int> fp = torrent_handle::file_priorities();
|
std::vector<int> fp = torrent_handle::file_priorities();
|
||||||
for (uint i = 0; i < fp.size(); ++i) {
|
for (uint i = 0; i < fp.size(); ++i) {
|
||||||
if (fp[i] == 0) {
|
if (fp[i] == 0) {
|
||||||
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
|
const QString file_path = fsutils::expandPathAbs(saveDir.absoluteFilePath(filepath_at(i)));
|
||||||
if (file_path.contains(".unwanted"))
|
if (file_path.contains(".unwanted"))
|
||||||
res << file_path;
|
res << file_path;
|
||||||
}
|
}
|
||||||
|
@ -462,10 +458,9 @@ bool QTorrentHandle::priv() const {
|
||||||
|
|
||||||
QString QTorrentHandle::firstFileSavePath() const {
|
QString QTorrentHandle::firstFileSavePath() const {
|
||||||
Q_ASSERT(has_metadata());
|
Q_ASSERT(has_metadata());
|
||||||
QString fsave_path = TorrentPersistentData::getSavePath(hash());
|
QString fsave_path = fsutils::fromNativePath(TorrentPersistentData::getSavePath(hash()));
|
||||||
if (fsave_path.isEmpty())
|
if (fsave_path.isEmpty())
|
||||||
fsave_path = save_path();
|
fsave_path = save_path();
|
||||||
fsave_path.replace("\\", "/");
|
|
||||||
if (!fsave_path.endsWith("/"))
|
if (!fsave_path.endsWith("/"))
|
||||||
fsave_path += "/";
|
fsave_path += "/";
|
||||||
fsave_path += filepath_at(0);
|
fsave_path += filepath_at(0);
|
||||||
|
@ -480,7 +475,7 @@ QString QTorrentHandle::root_path() const
|
||||||
if (num_files() < 2)
|
if (num_files() < 2)
|
||||||
return save_path();
|
return save_path();
|
||||||
QString first_filepath = filepath_at(0);
|
QString first_filepath = filepath_at(0);
|
||||||
const int slashIndex = first_filepath.indexOf(QRegExp("[/\\\\]"));
|
const int slashIndex = first_filepath.indexOf("/");
|
||||||
if (slashIndex >= 0)
|
if (slashIndex >= 0)
|
||||||
return QDir(save_path()).absoluteFilePath(first_filepath.left(slashIndex));
|
return QDir(save_path()).absoluteFilePath(first_filepath.left(slashIndex));
|
||||||
return save_path();
|
return save_path();
|
||||||
|
@ -576,7 +571,7 @@ void QTorrentHandle::move_storage(const QString& new_path) const {
|
||||||
// or move_storage() will fail...
|
// or move_storage() will fail...
|
||||||
QDir().mkpath(new_path);
|
QDir().mkpath(new_path);
|
||||||
// Actually move the storage
|
// Actually move the storage
|
||||||
torrent_handle::move_storage(new_path.toUtf8().constData());
|
torrent_handle::move_storage(fsutils::toNativePath(new_path).toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QTorrentHandle::save_torrent_file(const QString& path) const {
|
bool QTorrentHandle::save_torrent_file(const QString& path) const {
|
||||||
|
@ -651,7 +646,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
if (created) {
|
if (created) {
|
||||||
// Hide the folder on Windows
|
// Hide the folder on Windows
|
||||||
qDebug() << "Hiding folder (Windows)";
|
qDebug() << "Hiding folder (Windows)";
|
||||||
wstring win_path = unwanted_abspath.replace("/","\\").toStdWString();
|
wstring win_path = fsutils::toNativePath(unwanted_abspath).toStdWString();
|
||||||
DWORD dwAttrs = GetFileAttributesW(win_path.c_str());
|
DWORD dwAttrs = GetFileAttributesW(win_path.c_str());
|
||||||
bool ret = SetFileAttributesW(win_path.c_str(), dwAttrs|FILE_ATTRIBUTE_HIDDEN);
|
bool ret = SetFileAttributesW(win_path.c_str(), dwAttrs|FILE_ATTRIBUTE_HIDDEN);
|
||||||
Q_ASSERT(ret != 0); Q_UNUSED(ret);
|
Q_ASSERT(ret != 0); Q_UNUSED(ret);
|
||||||
|
@ -676,8 +671,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
||||||
else
|
else
|
||||||
rename_file(i, QDir(new_relpath).filePath(old_name));
|
rename_file(i, QDir(new_relpath).filePath(old_name));
|
||||||
// Remove .unwanted directory if empty
|
// Remove .unwanted directory if empty
|
||||||
qDebug() << "Attempting to remove .unwanted folder at " << QDir(spath + QDir::separator() + new_relpath).absoluteFilePath(".unwanted");
|
qDebug() << "Attempting to remove .unwanted folder at " << QDir(spath + "/" + new_relpath).absoluteFilePath(".unwanted");
|
||||||
QDir(spath + QDir::separator() + new_relpath).rmdir(".unwanted");
|
QDir(spath + "/" + new_relpath).rmdir(".unwanted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -727,7 +722,7 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
|
||||||
|
|
||||||
void QTorrentHandle::rename_file(int index, const QString& name) const {
|
void QTorrentHandle::rename_file(int index, const QString& name) const {
|
||||||
qDebug() << Q_FUNC_INFO << index << name;
|
qDebug() << Q_FUNC_INFO << index << name;
|
||||||
torrent_handle::rename_file(index, std::string(name.toUtf8().constData()));
|
torrent_handle::rename_file(index, std::string(fsutils::toNativePath(name).toUtf8().constData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
class TorrentTempData {
|
class TorrentTempData {
|
||||||
|
// This class stores strings w/o modifying separators
|
||||||
public:
|
public:
|
||||||
static bool hasTempData(const QString &hash) {
|
static bool hasTempData(const QString &hash) {
|
||||||
return data.contains(hash);
|
return data.contains(hash);
|
||||||
|
@ -151,6 +152,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
class TorrentPersistentData {
|
class TorrentPersistentData {
|
||||||
|
// This class stores strings w/o modifying separators
|
||||||
public:
|
public:
|
||||||
enum RatioLimit {
|
enum RatioLimit {
|
||||||
USE_GLOBAL_RATIO = -2,
|
USE_GLOBAL_RATIO = -2,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue