mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-05 11:24:15 +00:00
fix import torrent with "Keep incomplete torrents in:" ticked
* also had to account for "Append the label of the torrent to the save path", but again, this was only an issue when "Keep incomplete torrents in:" is selected * A multi-file torrent with only one file (ie: a single file within a folder), was being treated as a single-file torrent, making it impossible to import. Multi-file torrent detection code was copied from libtorrent. The information is available in libtorrent (under torrent_info::m_multifile), however it's a private member and I chose to go with copying the code that determines it, rather than modifying a library qBittorrent depends on. Conflicts: src/torrentimportdlg.cpp
This commit is contained in:
parent
59379942ac
commit
ac3efb664a
@ -1016,7 +1016,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a torrent to the Bittorrent session
|
// Add a torrent to the Bittorrent session
|
||||||
QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) {
|
QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed, bool imported) {
|
||||||
QTorrentHandle h;
|
QTorrentHandle h;
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
|
|
||||||
@ -1134,9 +1134,9 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
|
|||||||
// Remember label
|
// Remember label
|
||||||
TorrentTempData::setLabel(hash, savePath_label.second);
|
TorrentTempData::setLabel(hash, savePath_label.second);
|
||||||
} else {
|
} else {
|
||||||
savePath = getSavePath(hash, fromScanDir, path);
|
savePath = getSavePath(hash, fromScanDir, path, imported);
|
||||||
}
|
}
|
||||||
if (!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash)) {
|
if (!imported && !defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash)) {
|
||||||
qDebug("addTorrent::Temp folder is enabled.");
|
qDebug("addTorrent::Temp folder is enabled.");
|
||||||
QString torrent_tmp_path = defaultTempPath;
|
QString torrent_tmp_path = defaultTempPath;
|
||||||
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
|
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
|
||||||
@ -2776,14 +2776,14 @@ session_status QBtSession::getSessionStatus() const {
|
|||||||
return s->status();
|
return s->status();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString filePath) {
|
QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString filePath, bool imported) {
|
||||||
QString savePath;
|
QString savePath;
|
||||||
if (TorrentTempData::hasTempData(hash)) {
|
if (TorrentTempData::hasTempData(hash)) {
|
||||||
savePath = fsutils::fromNativePath(TorrentTempData::getSavePath(hash));
|
savePath = fsutils::fromNativePath(TorrentTempData::getSavePath(hash));
|
||||||
if (savePath.isEmpty()) {
|
if (savePath.isEmpty()) {
|
||||||
savePath = defaultSavePath;
|
savePath = defaultSavePath;
|
||||||
}
|
}
|
||||||
if (appendLabelToSavePath) {
|
if (!imported && appendLabelToSavePath) {
|
||||||
qDebug("appendLabelToSavePath is true");
|
qDebug("appendLabelToSavePath is true");
|
||||||
const QString label = TorrentTempData::getLabel(hash);
|
const QString label = TorrentTempData::getLabel(hash);
|
||||||
if (!label.isEmpty()) {
|
if (!label.isEmpty()) {
|
||||||
|
@ -116,7 +116,7 @@ public:
|
|||||||
void postTorrentUpdate();
|
void postTorrentUpdate();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false, bool imported = false);
|
||||||
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false, bool fromScanDir=false, const QString &filePath=QString());
|
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false, bool fromScanDir=false, const QString &filePath=QString());
|
||||||
void loadSessionState();
|
void loadSessionState();
|
||||||
void saveSessionState();
|
void saveSessionState();
|
||||||
@ -183,7 +183,7 @@ public slots:
|
|||||||
void unhideMagnet(const QString &hash);
|
void unhideMagnet(const QString &hash);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getSavePath(const QString &hash, bool fromScanDir = false, QString filePath = QString::null);
|
QString getSavePath(const QString &hash, bool fromScanDir = false, QString filePath = QString::null, bool imported = false);
|
||||||
bool loadFastResumeData(const QString &hash, std::vector<char> &buf);
|
bool loadFastResumeData(const QString &hash, std::vector<char> &buf);
|
||||||
void loadTorrentSettings(QTorrentHandle &h);
|
void loadTorrentSettings(QTorrentHandle &h);
|
||||||
void loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet);
|
void loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet);
|
||||||
|
@ -75,7 +75,16 @@ void TorrentImportDlg::on_browseTorrentBtn_clicked()
|
|||||||
void TorrentImportDlg::on_browseContentBtn_clicked()
|
void TorrentImportDlg::on_browseContentBtn_clicked()
|
||||||
{
|
{
|
||||||
const QString default_dir = Preferences::instance()->getTorImportLastContentDir();
|
const QString default_dir = Preferences::instance()->getTorImportLastContentDir();
|
||||||
if (t->num_files() == 1) {
|
// Test for multi-file taken from libtorrent/create_torrent.hpp -> create_torrent::create_torrent
|
||||||
|
bool multifile = t->num_files() > 1;
|
||||||
|
#if LIBTORRENT_VERSION_NUM >= 1600
|
||||||
|
if (!multifile && has_parent_path(t->files().file_path(*(t->files().begin()))))
|
||||||
|
multifile = true;
|
||||||
|
#else
|
||||||
|
if (!multifile && t->file_at(0).path.has_parent_path())
|
||||||
|
multifile = true;
|
||||||
|
#endif
|
||||||
|
if (!multifile) {
|
||||||
// Single file torrent
|
// Single file torrent
|
||||||
const QString file_name = fsutils::fileName(misc::toQStringU(t->file_at(0).path));
|
const QString file_name = fsutils::fileName(misc::toQStringU(t->file_at(0).path));
|
||||||
qDebug("Torrent has only one file: %s", qPrintable(file_name));
|
qDebug("Torrent has only one file: %s", qPrintable(file_name));
|
||||||
@ -193,7 +202,7 @@ void TorrentImportDlg::importTorrent()
|
|||||||
TorrentTempData::setSavePath(hash, content_path);
|
TorrentTempData::setSavePath(hash, content_path);
|
||||||
TorrentTempData::setSeedingMode(hash, dlg.skipFileChecking());
|
TorrentTempData::setSeedingMode(hash, dlg.skipFileChecking());
|
||||||
qDebug("Adding the torrent to the session...");
|
qDebug("Adding the torrent to the session...");
|
||||||
QBtSession::instance()->addTorrent(torrent_path);
|
QBtSession::instance()->addTorrent(torrent_path, false, QString(), false, true);
|
||||||
// Remember the last opened folder
|
// Remember the last opened folder
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
pref->setMainLastDir(fsutils::fromNativePath(torrent_path));
|
pref->setMainLastDir(fsutils::fromNativePath(torrent_path));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user