From 04c19886656652ae7d12e2fd12708945c7e9dbf2 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 25 Feb 2022 12:46:22 +0300 Subject: [PATCH 1/2] Correctly handle changing of global save path --- src/base/bittorrent/session.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 2a9d76cc9..ad2e62f41 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2525,18 +2525,27 @@ void Session::setSavePath(const Path &path) if (newPath == m_savePath) return; - m_savePath = newPath; - if (isDisableAutoTMMWhenDefaultSavePathChanged()) { + QSet affectedCatogories {{}}; // includes default (unnamed) category + for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it) + { + const QString &categoryName = it.key(); + const CategoryOptions &categoryOptions = it.value(); + if (categoryOptions.savePath.isRelative()) + affectedCatogories.insert(categoryName); + } + for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->setAutoTMMEnabled(false); - } - else - { - for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->handleCategoryOptionsChanged(); + { + if (affectedCatogories.contains(torrent->category())) + torrent->setAutoTMMEnabled(false); + } } + + m_savePath = newPath; + for (TorrentImpl *const torrent : asConst(m_torrents)) + torrent->handleCategoryOptionsChanged(); } void Session::setDownloadPath(const Path &path) From c5ff9b353c4179a2b335740f66425e621f346016 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Mon, 28 Feb 2022 09:41:44 +0300 Subject: [PATCH 2/2] Allow to disable Automatic mode when "temp" path changed --- src/base/bittorrent/session.cpp | 27 +++++++++++++++++++++++---- src/base/bittorrent/torrentimpl.cpp | 5 ----- src/base/bittorrent/torrentimpl.h | 1 - src/gui/optionsdialog.ui | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index ad2e62f41..6e9b6e933 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -611,7 +611,7 @@ void Session::setDownloadPathEnabled(const bool enabled) { m_isDownloadPathEnabled = enabled; for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->handleDownloadPathChanged(); + torrent->handleCategoryOptionsChanged(); } } @@ -2551,13 +2551,32 @@ void Session::setSavePath(const Path &path) void Session::setDownloadPath(const Path &path) { const Path newPath = (path.isAbsolute() ? path : (savePath() / Path("temp") / path)); - if (newPath != m_downloadPath) + if (newPath == m_downloadPath) + return; + + if (isDisableAutoTMMWhenDefaultSavePathChanged()) { - m_downloadPath = newPath; + QSet affectedCatogories {{}}; // includes default (unnamed) category + for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it) + { + const QString &categoryName = it.key(); + const CategoryOptions &categoryOptions = it.value(); + const CategoryOptions::DownloadPathOption downloadPathOption = + categoryOptions.downloadPath.value_or(CategoryOptions::DownloadPathOption {isDownloadPathEnabled(), downloadPath()}); + if (downloadPathOption.enabled && downloadPathOption.path.isRelative()) + affectedCatogories.insert(categoryName); + } for (TorrentImpl *const torrent : asConst(m_torrents)) - torrent->handleDownloadPathChanged(); + { + if (affectedCatogories.contains(torrent->category())) + torrent->setAutoTMMEnabled(false); + } } + + m_downloadPath = newPath; + for (TorrentImpl *const torrent : asConst(m_torrents)) + torrent->handleCategoryOptionsChanged(); } #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index c53af8777..030c87f21 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1644,11 +1644,6 @@ void TorrentImpl::handleStateUpdate(const lt::torrent_status &nativeStatus) updateStatus(nativeStatus); } -void TorrentImpl::handleDownloadPathChanged() -{ - adjustStorageLocation(); -} - void TorrentImpl::handleMoveStorageJobFinished(const bool hasOutstandingJob) { m_session->handleTorrentNeedSaveResumeData(this); diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index 4de0724dc..a83e144e3 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -233,7 +233,6 @@ namespace BitTorrent void handleAlert(const lt::alert *a); void handleStateUpdate(const lt::torrent_status &nativeStatus); - void handleDownloadPathChanged(); void handleCategoryOptionsChanged(); void handleAppendExtensionToggled(); void saveResumeData(); diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index 091a80926..6851b77bc 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -1015,7 +1015,7 @@ Manual: Various torrent properties (e.g. save path) must be assigned manually - When Default Save Path changed: + When Default Save/Incomplete Path changed: