From ca088ef2e6921dcd797dae5c77153bc6880decd1 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Sun, 13 Mar 2016 19:42:05 +0100 Subject: [PATCH] #163: also saving messages for nzbs in history MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If an nzb was already removed from queue (put into history), the messages were not added to it’s log. Fixed. --- daemon/extension/QueueScript.cpp | 28 ++++++++++++++-------------- daemon/extension/QueueScript.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/daemon/extension/QueueScript.cpp b/daemon/extension/QueueScript.cpp index e760e3c9..ad7efc44 100644 --- a/daemon/extension/QueueScript.cpp +++ b/daemon/extension/QueueScript.cpp @@ -174,7 +174,7 @@ void QueueScriptController::AddMessage(Message::EKind kind, const char* text) { *value = '\0'; DownloadQueue* downloadQueue = DownloadQueue::Lock(); - NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(m_id); + NzbInfo* nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id); if (nzbInfo) { nzbInfo->GetParameters()->SetParameter(param, value + 1); @@ -190,7 +190,7 @@ void QueueScriptController::AddMessage(Message::EKind kind, const char* text) m_event == QueueScriptCoordinator::qeNzbDownloaded) { DownloadQueue* downloadQueue = DownloadQueue::Lock(); - NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(m_id); + NzbInfo* nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id); if (nzbInfo) { nzbInfo->SetFinalDir(msgText + 6 + 10); @@ -201,7 +201,7 @@ void QueueScriptController::AddMessage(Message::EKind kind, const char* text) { m_markBad = true; DownloadQueue* downloadQueue = DownloadQueue::Lock(); - NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(m_id); + NzbInfo* nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id); if (nzbInfo) { SetLogPrefix(nullptr); @@ -219,7 +219,7 @@ void QueueScriptController::AddMessage(Message::EKind kind, const char* text) else { DownloadQueue* downloadQueue = DownloadQueue::Lock(); - NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(m_id); + NzbInfo* nzbInfo = QueueScriptCoordinator::FindNzbInfo(downloadQueue, m_id); if (nzbInfo) { nzbInfo->AddMessage(kind, text); @@ -394,18 +394,18 @@ bool QueueScriptCoordinator::UsableScript(ScriptConfig::Script& script, NzbInfo* NzbInfo* QueueScriptCoordinator::FindNzbInfo(DownloadQueue* downloadQueue, int nzbId) { NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(nzbId); - if (!nzbInfo) + if (nzbInfo) { - for (HistoryInfo* historyInfo : downloadQueue->GetHistory()) - { - if (historyInfo->GetNzbInfo() && historyInfo->GetNzbInfo()->GetId() == nzbId) - { - nzbInfo = historyInfo->GetNzbInfo(); - break; - } - } + return nzbInfo; } - return nzbInfo; + + HistoryInfo* historyInfo = downloadQueue->GetHistory()->Find(nzbId); + if (historyInfo) + { + return historyInfo->GetNzbInfo(); + } + + return nullptr; } void QueueScriptCoordinator::CheckQueue() diff --git a/daemon/extension/QueueScript.h b/daemon/extension/QueueScript.h index 2801eb50..9ab3b0d1 100644 --- a/daemon/extension/QueueScript.h +++ b/daemon/extension/QueueScript.h @@ -42,6 +42,7 @@ public: void CheckQueue(); bool HasJob(int nzbId, bool* active); int GetQueueSize(); + static NzbInfo* FindNzbInfo(DownloadQueue* downloadQueue, int nzbId); private: class QueueItem @@ -66,7 +67,6 @@ private: bool m_hasQueueScripts = false; bool m_stopped = false; - NzbInfo* FindNzbInfo(DownloadQueue* downloadQueue, int nzbId); bool UsableScript(ScriptConfig::Script& script, NzbInfo* nzbInfo, EEvent event); };