Merge pull request #3497 from Chocobo1/ext_param_early

Fix "Run External Program Launches too Early" issue
This commit is contained in:
sledgehammer999 2015-07-30 11:28:08 +03:00
commit 1217d8d021
2 changed files with 33 additions and 14 deletions

View file

@ -190,6 +190,7 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle
, m_session(session)
, m_nativeHandle(nativeHandle)
, m_state(TorrentState::Unknown)
, m_renameCount(0)
, m_name(data.name)
, m_addedTime(data.resumed ? data.addedTime : QDateTime::currentDateTime())
, 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)
{
++m_renameCount;
qDebug() << Q_FUNC_INFO << index << 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);
}
if (!isMoveInProgress()) {
while (!m_moveStorageTriggers.isEmpty())
m_moveStorageTriggers.takeFirst()();
}
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
m_moveFinishedTriggers.takeFirst()();
}
void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_failed_alert *p)
@ -1361,10 +1361,8 @@ void TorrentHandle::handleStorageMovedFailedAlert(libtorrent::storage_moved_fail
m_queuedPath.clear();
}
if (!isMoveInProgress()) {
while (!m_moveStorageTriggers.isEmpty())
m_moveStorageTriggers.takeFirst()();
}
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
m_moveFinishedTriggers.takeFirst()();
}
void TorrentHandle::handleTrackerReplyAlert(libtorrent::tracker_reply_alert *p)
@ -1433,10 +1431,10 @@ void TorrentHandle::handleTorrentFinishedAlert(libtorrent::torrent_finished_aler
if (Preferences::instance()->recheckTorrentsOnCompletion())
forceRecheck();
if (!isMoveInProgress())
m_session->handleTorrentFinished(this);
if (isMoveInProgress() || m_renameCount > 0)
m_moveFinishedTriggers.append(boost::bind(&SessionPrivate::handleTorrentFinished, m_session, this));
else
m_moveStorageTriggers.append(boost::bind(&SessionPrivate::handleTorrentFinished, m_session, this));
m_session->handleTorrentFinished(this);
}
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
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)
@ -1625,6 +1636,9 @@ void TorrentHandle::handleAlert(libtorrent::alert *a)
case libt::file_renamed_alert::alert_type:
handleFileRenamedAlert(static_cast<libt::file_renamed_alert*>(a));
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:
handleFileCompletedAlert(static_cast<libt::file_completed_alert*>(a));
break;
@ -1700,7 +1714,7 @@ void TorrentHandle::adjustActualSavePath()
if (!isMoveInProgress())
adjustActualSavePath_impl();
else
m_moveStorageTriggers.append(boost::bind(&TorrentHandle::adjustActualSavePath_impl, this));
m_moveFinishedTriggers.append(boost::bind(&TorrentHandle::adjustActualSavePath_impl, this));
}
void TorrentHandle::adjustActualSavePath_impl()

View file

@ -61,6 +61,7 @@ namespace libtorrent
struct save_resume_data_alert;
struct save_resume_data_failed_alert;
struct file_renamed_alert;
struct file_rename_failed_alert;
struct storage_moved_alert;
struct storage_moved_failed_alert;
struct metadata_received_alert;
@ -299,7 +300,7 @@ namespace BitTorrent
libtorrent::torrent_handle nativeHandle() const;
private:
typedef boost::function<void ()> MoveStorageTrigger;
typedef boost::function<void ()> EventTrigger;
void initialize();
void updateStatus();
@ -326,6 +327,7 @@ namespace BitTorrent
void handleSaveResumeDataFailedAlert(libtorrent::save_resume_data_failed_alert *p);
void handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_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 handleMetadataReceivedAlert(libtorrent::metadata_received_alert *p);
void handleStatsAlert(libtorrent::stats_alert *p);
@ -358,7 +360,10 @@ namespace BitTorrent
// m_queuedPath is where files should be moved to,
// when current moving is completed
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
QString m_name;