mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 05:48:47 +03:00
Merge pull request #3497 from Chocobo1/ext_param_early
Fix "Run External Program Launches too Early" issue
This commit is contained in:
commit
1217d8d021
2 changed files with 33 additions and 14 deletions
|
@ -190,6 +190,7 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle
|
||||||
, m_session(session)
|
, m_session(session)
|
||||||
, m_nativeHandle(nativeHandle)
|
, m_nativeHandle(nativeHandle)
|
||||||
, m_state(TorrentState::Unknown)
|
, m_state(TorrentState::Unknown)
|
||||||
|
, m_renameCount(0)
|
||||||
, m_name(data.name)
|
, m_name(data.name)
|
||||||
, m_addedTime(data.resumed ? data.addedTime : QDateTime::currentDateTime())
|
, m_addedTime(data.resumed ? data.addedTime : QDateTime::currentDateTime())
|
||||||
, m_savePath(Utils::Fs::toNativePath(data.savePath))
|
, m_savePath(Utils::Fs::toNativePath(data.savePath))
|
||||||
|
@ -1269,6 +1270,7 @@ void TorrentHandle::setTrackerLogin(const QString &username, const QString &pass
|
||||||
|
|
||||||
void TorrentHandle::renameFile(int index, const QString &name)
|
void TorrentHandle::renameFile(int index, const QString &name)
|
||||||
{
|
{
|
||||||
|
++m_renameCount;
|
||||||
qDebug() << Q_FUNC_INFO << index << name;
|
qDebug() << Q_FUNC_INFO << index << name;
|
||||||
SAFE_CALL(rename_file, index, Utils::String::toStdString(Utils::Fs::toNativePath(name)));
|
SAFE_CALL(rename_file, index, Utils::String::toStdString(Utils::Fs::toNativePath(name)));
|
||||||
}
|
}
|
||||||
|
@ -1339,10 +1341,8 @@ void TorrentHandle::handleStorageMovedAlert(libtorrent::storage_moved_alert *p)
|
||||||
QDir().rmpath(m_oldPath);
|
QDir().rmpath(m_oldPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMoveInProgress()) {
|
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
|
||||||
while (!m_moveStorageTriggers.isEmpty())
|
m_moveFinishedTriggers.takeFirst()();
|
||||||
m_moveStorageTriggers.takeFirst()();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_failed_alert *p)
|
void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_failed_alert *p)
|
||||||
|
@ -1361,10 +1361,8 @@ void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_fail
|
||||||
m_queuedPath.clear();
|
m_queuedPath.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMoveInProgress()) {
|
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
|
||||||
while (!m_moveStorageTriggers.isEmpty())
|
m_moveFinishedTriggers.takeFirst()();
|
||||||
m_moveStorageTriggers.takeFirst()();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::handleTrackerReplyAlert(libtorrent::tracker_reply_alert *p)
|
void TorrentHandle::handleTrackerReplyAlert(libtorrent::tracker_reply_alert *p)
|
||||||
|
@ -1433,10 +1431,10 @@ void TorrentHandle::handleTorrentFinishedAlert(libtorrent::torrent_finished_aler
|
||||||
if (Preferences::instance()->recheckTorrentsOnCompletion())
|
if (Preferences::instance()->recheckTorrentsOnCompletion())
|
||||||
forceRecheck();
|
forceRecheck();
|
||||||
|
|
||||||
if (!isMoveInProgress())
|
if (isMoveInProgress() || m_renameCount > 0)
|
||||||
m_session->handleTorrentFinished(this);
|
m_moveFinishedTriggers.append(boost::bind(&SessionPrivate::handleTorrentFinished, m_session, this));
|
||||||
else
|
else
|
||||||
m_moveStorageTriggers.append(boost::bind(&SessionPrivate::handleTorrentFinished, m_session, this));
|
m_session->handleTorrentFinished(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::handleTorrentPausedAlert(libtorrent::torrent_paused_alert *p)
|
void TorrentHandle::handleTorrentPausedAlert(libtorrent::torrent_paused_alert *p)
|
||||||
|
@ -1532,6 +1530,19 @@ void TorrentHandle::handleFileRenamedAlert(libtorrent::file_renamed_alert *p)
|
||||||
// Renaming a file corresponds to changing the save path
|
// Renaming a file corresponds to changing the save path
|
||||||
m_session->handleTorrentSavePathChanged(this);
|
m_session->handleTorrentSavePathChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--m_renameCount;
|
||||||
|
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
|
||||||
|
m_moveFinishedTriggers.takeFirst()();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentHandle::handleFileRenameFailedAlert(libtorrent::file_rename_failed_alert *p)
|
||||||
|
{
|
||||||
|
Q_UNUSED(p);
|
||||||
|
|
||||||
|
--m_renameCount;
|
||||||
|
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
|
||||||
|
m_moveFinishedTriggers.takeFirst()();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::handleFileCompletedAlert(libtorrent::file_completed_alert *p)
|
void TorrentHandle::handleFileCompletedAlert(libtorrent::file_completed_alert *p)
|
||||||
|
@ -1625,6 +1636,9 @@ void TorrentHandle::handleAlert(libtorrent::alert *a)
|
||||||
case libt::file_renamed_alert::alert_type:
|
case libt::file_renamed_alert::alert_type:
|
||||||
handleFileRenamedAlert(static_cast<libt::file_renamed_alert*>(a));
|
handleFileRenamedAlert(static_cast<libt::file_renamed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
|
case libt::file_rename_failed_alert::alert_type:
|
||||||
|
handleFileRenameFailedAlert(static_cast<libt::file_rename_failed_alert*>(a));
|
||||||
|
break;
|
||||||
case libt::file_completed_alert::alert_type:
|
case libt::file_completed_alert::alert_type:
|
||||||
handleFileCompletedAlert(static_cast<libt::file_completed_alert*>(a));
|
handleFileCompletedAlert(static_cast<libt::file_completed_alert*>(a));
|
||||||
break;
|
break;
|
||||||
|
@ -1700,7 +1714,7 @@ void TorrentHandle::adjustActualSavePath()
|
||||||
if (!isMoveInProgress())
|
if (!isMoveInProgress())
|
||||||
adjustActualSavePath_impl();
|
adjustActualSavePath_impl();
|
||||||
else
|
else
|
||||||
m_moveStorageTriggers.append(boost::bind(&TorrentHandle::adjustActualSavePath_impl, this));
|
m_moveFinishedTriggers.append(boost::bind(&TorrentHandle::adjustActualSavePath_impl, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::adjustActualSavePath_impl()
|
void TorrentHandle::adjustActualSavePath_impl()
|
||||||
|
|
|
@ -61,6 +61,7 @@ namespace libtorrent
|
||||||
struct save_resume_data_alert;
|
struct save_resume_data_alert;
|
||||||
struct save_resume_data_failed_alert;
|
struct save_resume_data_failed_alert;
|
||||||
struct file_renamed_alert;
|
struct file_renamed_alert;
|
||||||
|
struct file_rename_failed_alert;
|
||||||
struct storage_moved_alert;
|
struct storage_moved_alert;
|
||||||
struct storage_moved_failed_alert;
|
struct storage_moved_failed_alert;
|
||||||
struct metadata_received_alert;
|
struct metadata_received_alert;
|
||||||
|
@ -299,7 +300,7 @@ namespace BitTorrent
|
||||||
libtorrent::torrent_handle nativeHandle() const;
|
libtorrent::torrent_handle nativeHandle() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef boost::function<void ()> MoveStorageTrigger;
|
typedef boost::function<void ()> EventTrigger;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
|
@ -326,6 +327,7 @@ namespace BitTorrent
|
||||||
void handleSaveResumeDataFailedAlert(libtorrent::save_resume_data_failed_alert *p);
|
void handleSaveResumeDataFailedAlert(libtorrent::save_resume_data_failed_alert *p);
|
||||||
void handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_alert *p);
|
void handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_alert *p);
|
||||||
void handleFileRenamedAlert(libtorrent::file_renamed_alert *p);
|
void handleFileRenamedAlert(libtorrent::file_renamed_alert *p);
|
||||||
|
void handleFileRenameFailedAlert(libtorrent::file_rename_failed_alert *p);
|
||||||
void handleFileCompletedAlert(libtorrent::file_completed_alert *p);
|
void handleFileCompletedAlert(libtorrent::file_completed_alert *p);
|
||||||
void handleMetadataReceivedAlert(libtorrent::metadata_received_alert *p);
|
void handleMetadataReceivedAlert(libtorrent::metadata_received_alert *p);
|
||||||
void handleStatsAlert(libtorrent::stats_alert *p);
|
void handleStatsAlert(libtorrent::stats_alert *p);
|
||||||
|
@ -358,7 +360,10 @@ namespace BitTorrent
|
||||||
// m_queuedPath is where files should be moved to,
|
// m_queuedPath is where files should be moved to,
|
||||||
// when current moving is completed
|
// when current moving is completed
|
||||||
QString m_queuedPath;
|
QString m_queuedPath;
|
||||||
QQueue<MoveStorageTrigger> m_moveStorageTriggers;
|
// m_moveFinishedTriggers is activated only when the following conditions are met:
|
||||||
|
// all file rename jobs complete, all file move jobs complete
|
||||||
|
QQueue<EventTrigger> m_moveFinishedTriggers;
|
||||||
|
int m_renameCount;
|
||||||
|
|
||||||
// Persistent data
|
// Persistent data
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|
Loading…
Reference in a new issue