From 6bfe1b0cfd7dbe55aecaa459c56426d0e69ec9fc Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Sat, 22 Aug 2009 12:05:25 +0000 Subject: [PATCH] added actions (return history item) and

(postprocess history item) for subcommand of command <-E/--edit>; added actions and for remote RPC-command --- MessageBase.h | 4 +- Options.cpp | 12 +++++- PrePostProcessor.cpp | 95 +++++++++++++++++++++++++++++++++++++++++--- PrePostProcessor.h | 9 +++-- XmlRpc.cpp | 2 + 5 files changed, 111 insertions(+), 11 deletions(-) diff --git a/MessageBase.h b/MessageBase.h index b26b78b1..e89d39e0 100644 --- a/MessageBase.h +++ b/MessageBase.h @@ -91,7 +91,9 @@ enum eRemoteEditAction eRemoteEditActionPostMoveTop, // move post-job to the top of post-queue eRemoteEditActionPostMoveBottom, // move post-job to the bottom of post-queue eRemoteEditActionPostDelete, // delete post-job - eRemoteEditActionHistoryDelete // delete history-item + eRemoteEditActionHistoryDelete, // delete history-item + eRemoteEditActionHistoryReturn, // move history-item back to download queue + eRemoteEditActionHistoryProcess // move history-item back to download queue and start postprocessing }; // Possible values for field "m_iAction" of struct "SNZBPauseUnpauseRequest": diff --git a/Options.cpp b/Options.cpp index 0da690f0..fc169764 100644 --- a/Options.cpp +++ b/Options.cpp @@ -947,6 +947,14 @@ void Options::InitCommandLine(int argc, char* argv[]) { m_iEditQueueAction = eRemoteEditActionHistoryDelete; } + else if (!strcasecmp(optarg, "R")) + { + m_iEditQueueAction = eRemoteEditActionHistoryReturn; + } + else if (!strcasecmp(optarg, "P")) + { + m_iEditQueueAction = eRemoteEditActionHistoryProcess; + } else { abort("FATAL ERROR: Could not parse value of option 'E'\n"); @@ -1143,9 +1151,11 @@ void Options::PrintUsage(char* com) " T Move file(s)/group(s)/post-job to top of queue\n" " B Move file(s)/group(s)/post-job to bottom of queue\n" " P Pause file(s)/group(s)\n" + " Postprocess history-item(s) again\n" " U Resume (unpause) file(s)/group(s)\n" " A Pause all pars (for groups)\n" - " R Pause extra pars (for groups)\n" + " R Pause extra pars (for groups)/\n" + " Return history-item(s) back to download queue\n" " D Delete file(s)/group(s)/post-job(s)/history-item(s)\n" " K Set category (for groups)\n" " M Merge (for groups)\n" diff --git a/PrePostProcessor.cpp b/PrePostProcessor.cpp index 1283c8d8..26f9744c 100644 --- a/PrePostProcessor.cpp +++ b/PrePostProcessor.cpp @@ -247,14 +247,14 @@ void PrePostProcessor::QueueCoordinatorUpdate(Subject * Caller, void * Aspect) if (pAspect->eAction == QueueCoordinator::eaFileCompleted) { info("Collection %s completely downloaded", szNZBNiceName); - NZBDownloaded(pAspect->pDownloadQueue, pAspect->pNZBInfo, pAspect->pFileInfo); + NZBDownloaded(pAspect->pDownloadQueue, pAspect->pNZBInfo); } else if (pAspect->pNZBInfo->GetDeleted() && !pAspect->pNZBInfo->GetParCleanup() && IsNZBFileCompleted(pAspect->pDownloadQueue, pAspect->pNZBInfo, false, false, false, true)) { info("Collection %s deleted from queue", szNZBNiceName); - NZBDeleted(pAspect->pDownloadQueue, pAspect->pNZBInfo, pAspect->pFileInfo); + NZBDeleted(pAspect->pDownloadQueue, pAspect->pNZBInfo); } } } @@ -273,7 +273,7 @@ void PrePostProcessor::NZBAdded(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo } } -void PrePostProcessor::NZBDownloaded(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo, FileInfo* pFileInfo) +void PrePostProcessor::NZBDownloaded(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo) { bool bPostProcessed = false; @@ -298,7 +298,7 @@ void PrePostProcessor::NZBDownloaded(DownloadQueue* pDownloadQueue, NZBInfo* pNZ } } -void PrePostProcessor::NZBDeleted(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo, FileInfo* pFileInfo) +void PrePostProcessor::NZBDeleted(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo) { if (g_pOptions->GetDeleteCleanupDisk() && pNZBInfo->GetCleanupDisk()) { @@ -333,7 +333,6 @@ void PrePostProcessor::NZBCompleted(DownloadQueue* pDownloadQueue, NZBInfo* pNZB char szNZBNiceName[1024]; pNZBInfo->GetNiceNZBName(szNZBNiceName, 1024); pNZBInfo->AddReference(); - //pNZBInfo->ClearCompletedFiles(); pNZBInfo->SetHistoryTime(time(NULL)); pDownloadQueue->GetHistoryList()->push_front(pNZBInfo); @@ -342,8 +341,9 @@ void PrePostProcessor::NZBCompleted(DownloadQueue* pDownloadQueue, NZBInfo* pNZB for (FileQueue::iterator it = pDownloadQueue->GetFileQueue()->begin(); it != pDownloadQueue->GetFileQueue()->end(); ) { FileInfo* pFileInfo = *it; - if (pFileInfo->GetNZBInfo() == pNZBInfo) + if (pFileInfo->GetNZBInfo() == pNZBInfo && !pFileInfo->GetDeleted()) { + detail("Park file %s", pFileInfo->GetFilename()); g_pQueueCoordinator->DiscardDiskFile(pFileInfo); pDownloadQueue->GetFileQueue()->erase(it); pDownloadQueue->GetParkedFiles()->push_back(pFileInfo); @@ -1398,6 +1398,10 @@ bool PrePostProcessor::QueueEditList(IDList* pIDList, EEditAction eAction, int i case eaHistoryDelete: return HistoryDelete(pIDList); + case eaHistoryReturn: + case eaHistoryProcess: + return HistoryReturn(pIDList, eAction == eaHistoryProcess); + default: return false; } @@ -1593,3 +1597,82 @@ bool PrePostProcessor::HistoryDelete(IDList* pIDList) return bOK; } + +bool PrePostProcessor::HistoryReturn(IDList* pIDList, bool bReprocess) +{ + bool bOK = false; + + DownloadQueue* pDownloadQueue = g_pQueueCoordinator->LockQueue(); + + for (IDList::iterator itID = pIDList->begin(); itID != pIDList->end(); itID++) + { + int iID = *itID; + for (HistoryList::iterator itHistory = pDownloadQueue->GetHistoryList()->begin(); itHistory != pDownloadQueue->GetHistoryList()->end(); itHistory++) + { + NZBInfo* pNZBInfo = *itHistory; + if (pNZBInfo->GetID() == iID) + { + char szNZBNiceName[1024]; + pNZBInfo->GetNiceNZBName(szNZBNiceName, 1024); + debug("Returning %s from history back to download queue", szNZBNiceName); + bool bUnparked = false; + + // unpark files + int index = 0; + for (FileQueue::reverse_iterator it = pDownloadQueue->GetParkedFiles()->rbegin(); it != pDownloadQueue->GetParkedFiles()->rend(); ) + { + FileInfo* pFileInfo = *it; + if (pFileInfo->GetNZBInfo() == pNZBInfo) + { + detail("Unpark file %s", pFileInfo->GetFilename()); + pDownloadQueue->GetParkedFiles()->erase(pDownloadQueue->GetParkedFiles()->end() - 1 - index); + pDownloadQueue->GetFileQueue()->push_front(pFileInfo); + bUnparked = true; + it = pDownloadQueue->GetParkedFiles()->rbegin() + index; + } + else + { + it++; + index++; + } + } + + // reset postprocessing status variables + pNZBInfo->SetPostProcess(false); + pNZBInfo->SetParStatus(NZBInfo::prNone); + pNZBInfo->SetParCleanup(false); + pNZBInfo->SetHistoryTime(0); + + if (bUnparked || bReprocess) + { + pDownloadQueue->GetHistoryList()->erase(itHistory); + pNZBInfo->Release(); + info("%s returned from history back to download queue", szNZBNiceName); + bOK = true; + } + else + { + warn("Could not return %s back from history to download queue: history item does not have any files left for download", szNZBNiceName); + } + + if (bReprocess) + { + // start postprocessing + debug("Restarting postprocessing for %s", szNZBNiceName); + NZBDownloaded(pDownloadQueue, pNZBInfo); + } + + break; + } + } + } + + if (bOK) + { + SaveQueue(pDownloadQueue); + } + + g_pQueueCoordinator->UnlockQueue(); + + return bOK; +} diff --git a/PrePostProcessor.h b/PrePostProcessor.h index f5f17b47..101442d9 100644 --- a/PrePostProcessor.h +++ b/PrePostProcessor.h @@ -46,7 +46,9 @@ public: eaPostMoveTop, eaPostMoveBottom, eaPostDelete, - eaHistoryDelete + eaHistoryDelete, + eaHistoryReturn, + eaHistoryProcess }; private: @@ -112,8 +114,8 @@ private: bool PauseDownload(); bool UnpauseDownload(); void NZBAdded(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo); - void NZBDownloaded(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo, FileInfo* pFileInfo); - void NZBDeleted(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo, FileInfo* pFileInfo); + void NZBDownloaded(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo); + void NZBDeleted(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo); void NZBCompleted(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo, bool bSaveQueue); bool FindMainPars(const char* szPath, FileList* pFileList); bool ParseParFilename(const char* szParFilename, int* iBaseNameLen, int* iBlocks); @@ -125,6 +127,7 @@ private: bool PostQueueMove(IDList* pIDList, EEditAction eAction, int iOffset); bool PostQueueDelete(IDList* pIDList); bool HistoryDelete(IDList* pIDList); + bool HistoryReturn(IDList* pIDList, bool bReprocess); void Cleanup(); FileInfo* GetQueueGroup(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo); void CheckHistory(); diff --git a/XmlRpc.cpp b/XmlRpc.cpp index 4ea003aa..10869483 100644 --- a/XmlRpc.cpp +++ b/XmlRpc.cpp @@ -1238,6 +1238,8 @@ EditCommandEntry EditCommandNameMap[] = { { PrePostProcessor::eaPostMoveBottom, "PostMoveBottom" }, { PrePostProcessor::eaPostDelete, "PostDelete" }, { PrePostProcessor::eaHistoryDelete, "HistoryDelete" }, + { PrePostProcessor::eaHistoryDelete, "HistoryReturn" }, + { PrePostProcessor::eaHistoryDelete, "HistoryProcess" }, { 0, NULL } };