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.
This commit is contained in:
lojack5
2014-04-12 14:13:17 -06:00
parent bfd864efce
commit b734532b18
3 changed files with 18 additions and 9 deletions

View File

@@ -1032,7 +1032,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
}
// 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;
Preferences pref;
@@ -1166,9 +1166,9 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
// Remember label
TorrentTempData::setLabel(hash, savePath_label.second);
} 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.");
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
p.save_path = torrent_tmp_path.toUtf8().constData();
@@ -2668,14 +2668,14 @@ session_status QBtSession::getSessionStatus() const {
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;
if (TorrentTempData::hasTempData(hash)) {
savePath = TorrentTempData::getSavePath(hash);
if (savePath.isEmpty()) {
savePath = defaultSavePath;
}
if (appendLabelToSavePath) {
if (!imported && appendLabelToSavePath) {
qDebug("appendLabelToSavePath is true");
const QString label = TorrentTempData::getLabel(hash);
if (!label.isEmpty()) {