From 2c45a20ca73c5105cd0a9418df8aefd82cf73299 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Wed, 10 Dec 2008 22:04:06 +0000 Subject: [PATCH] cleaning up of download queue (option ) and deletion of source nzb-file (option ) after par-repair now works also if par-repair was cancelled (option ); since required par-files were already downloaded the repair in an external tool is possible --- DiskState.cpp | 17 ++++++++++++----- DownloadInfo.cpp | 1 - DownloadInfo.h | 3 --- PrePostProcessor.cpp | 27 +++++++++++++++++++-------- PrePostProcessor.h | 2 +- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/DiskState.cpp b/DiskState.cpp index c8f21e39..9d551c34 100644 --- a/DiskState.cpp +++ b/DiskState.cpp @@ -48,6 +48,7 @@ static const char* FORMATVERSION_SIGNATURE_V3 = "nzbget diskstate file version 3 static const char* FORMATVERSION_SIGNATURE_V4 = "nzbget diskstate file version 4\n"; static const char* FORMATVERSION_SIGNATURE_V5 = "nzbget diskstate file version 5\n"; static const char* FORMATVERSION_SIGNATURE_V6 = "nzbget diskstate file version 6\n"; +static const char* FORMATVERSION_SIGNATURE_V7 = "nzbget diskstate file version 7\n"; /* Parse signature and return format version number */ @@ -69,6 +70,10 @@ int DiskState::ParseFormatVersion(const char* szFormatSignature) { return 6; } + else if (!strcmp(szFormatSignature, FORMATVERSION_SIGNATURE_V7)) + { + return 7; + } else { return 0; @@ -477,7 +482,7 @@ bool DiskState::SavePostQueue(PostQueue* pPostQueue, bool bCompleted) return false; } - fprintf(outfile, FORMATVERSION_SIGNATURE_V6); + fprintf(outfile, FORMATVERSION_SIGNATURE_V7); fprintf(outfile, "%i\n", pPostQueue->size()); for (PostQueue::iterator it = pPostQueue->begin(); it != pPostQueue->end(); it++) @@ -491,7 +496,6 @@ bool DiskState::SavePostQueue(PostQueue* pPostQueue, bool bCompleted) fprintf(outfile, "%s\n", pPostInfo->GetQueuedFilename()); fprintf(outfile, "%i\n", (int)pPostInfo->GetParCheck()); fprintf(outfile, "%i\n", (int)pPostInfo->GetParStatus()); - fprintf(outfile, "%i\n", (int)pPostInfo->GetParFailed()); fprintf(outfile, "%i\n", (int)pPostInfo->GetStage()); fprintf(outfile, "%i\n", pPostInfo->GetParameters()->size()); @@ -530,7 +534,7 @@ bool DiskState::LoadPostQueue(PostQueue* pPostQueue, bool bCompleted) char FileSignatur[128]; fgets(FileSignatur, sizeof(FileSignatur), infile); int iFormatVersion = ParseFormatVersion(FileSignatur); - if (iFormatVersion < 3 || iFormatVersion > 6) + if (iFormatVersion < 3 || iFormatVersion > 7) { error("Could not load diskstate due file version mismatch"); fclose(infile); @@ -591,8 +595,11 @@ bool DiskState::LoadPostQueue(PostQueue* pPostQueue, bool bCompleted) if (fscanf(infile, "%i\n", &iIntValue) != 1) goto error; pPostInfo->SetParStatus(iIntValue); - if (fscanf(infile, "%i\n", &iIntValue) != 1) goto error; - pPostInfo->SetParFailed(iIntValue); + if (iFormatVersion < 7) + { + // skip old field ParFailed, not used anymore + if (fscanf(infile, "%i\n", &iIntValue) != 1) goto error; + } if (fscanf(infile, "%i\n", &iIntValue) != 1) goto error; pPostInfo->SetStage((PostInfo::EStage)iIntValue); diff --git a/DownloadInfo.cpp b/DownloadInfo.cpp index 1dde7398..cd72d264 100644 --- a/DownloadInfo.cpp +++ b/DownloadInfo.cpp @@ -547,7 +547,6 @@ PostInfo::PostInfo() m_bWorking = false; m_bParCheck = false; m_iParStatus = 0; - m_bParFailed = false; m_eRequestParCheck = rpNone; m_szProgressLabel = strdup(""); m_iFileProgress = 0; diff --git a/DownloadInfo.h b/DownloadInfo.h index 78e617bf..0ce6d0e7 100644 --- a/DownloadInfo.h +++ b/DownloadInfo.h @@ -261,7 +261,6 @@ private: bool m_bWorking; bool m_bParCheck; int m_iParStatus; - bool m_bParFailed; ERequestParCheck m_eRequestParCheck; EStage m_eStage; char* m_szProgressLabel; @@ -310,8 +309,6 @@ public: void SetParCheck(bool bParCheck) { m_bParCheck = bParCheck; } int GetParStatus() { return m_iParStatus; } void SetParStatus(int iParStatus) { m_iParStatus = iParStatus; } - bool GetParFailed() { return m_bParFailed; } - void SetParFailed(bool bParFailed) { m_bParFailed = bParFailed; } ERequestParCheck GetRequestParCheck() { return m_eRequestParCheck; } void SetRequestParCheck(ERequestParCheck eRequestParCheck) { m_eRequestParCheck = eRequestParCheck; } void AppendMessage(Message::EKind eKind, const char* szText); diff --git a/PrePostProcessor.cpp b/PrePostProcessor.cpp index 5091735e..88e24187 100644 --- a/PrePostProcessor.cpp +++ b/PrePostProcessor.cpp @@ -593,7 +593,7 @@ void PrePostProcessor::CheckPostQueue() IsNZBFileCompleted(pDownloadQueue, pPostInfo->GetNZBFilename(), true, true, true, false) && pPostInfo->GetParStatus() != PARSTATUS_NOT_CHECKED && pPostInfo->GetParStatus() != PARSTATUS_FAILED && - !HasFailedParJobs(pPostInfo->GetNZBFilename())) + !HasFailedParJobs(pPostInfo->GetNZBFilename(), true)) { if (g_pOptions->GetParCleanupQueue()) { @@ -704,7 +704,9 @@ void PrePostProcessor::StartScriptJob(DownloadQueue* pDownloadQueue, PostInfo* p bool bNZBFileCompleted = IsNZBFileCompleted(pDownloadQueue, pPostInfo->GetNZBFilename(), true, true, true, false); #ifndef DISABLE_PARCHECK - bool bHasFailedParJobs = HasFailedParJobs(pPostInfo->GetNZBFilename()) || pPostInfo->GetParFailed(); + bool bHasFailedParJobs = HasFailedParJobs(pPostInfo->GetNZBFilename(), false) || + pPostInfo->GetParStatus() == PARSTATUS_FAILED || + pPostInfo->GetParStatus() == PARSTATUS_REPAIR_POSSIBLE; #else bool bHasFailedParJobs = false; #endif @@ -1161,7 +1163,14 @@ void PrePostProcessor::ParCheckerUpdate(Subject* Caller, void* Aspect) { if (m_ParChecker.GetStatus() == ParChecker::psFailed) { - fprintf(file, "Repair failed for %s: %s\n", m_ParChecker.GetInfoName(), m_ParChecker.GetErrMsg() ? m_ParChecker.GetErrMsg() : ""); + if (m_ParChecker.GetCancelled()) + { + fprintf(file, "Repair cancelled for %s\n", m_ParChecker.GetInfoName()); + } + else + { + fprintf(file, "Repair failed for %s: %s\n", m_ParChecker.GetInfoName(), m_ParChecker.GetErrMsg() ? m_ParChecker.GetErrMsg() : ""); + } } else if (m_ParChecker.GetRepairNotNeeded()) { @@ -1190,15 +1199,15 @@ void PrePostProcessor::ParCheckerUpdate(Subject* Caller, void* Aspect) m_mutexQueue.Lock(); PostInfo* pPostInfo = m_PostQueue.front(); - pPostInfo->SetParFailed(m_ParChecker.GetStatus() == ParChecker::psFailed); pPostInfo->SetWorking(false); pPostInfo->SetStage(PostInfo::ptQueued); - if (m_ParChecker.GetStatus() == ParChecker::psFailed) + if (m_ParChecker.GetStatus() == ParChecker::psFailed && !m_ParChecker.GetCancelled()) { pPostInfo->SetParStatus(PARSTATUS_FAILED); } - else if (g_pOptions->GetParRepair() || m_ParChecker.GetRepairNotNeeded()) + else if (m_ParChecker.GetStatus() == ParChecker::psFinished && + (g_pOptions->GetParRepair() || m_ParChecker.GetRepairNotNeeded())) { pPostInfo->SetParStatus(PARSTATUS_REPAIRED); } @@ -1254,14 +1263,16 @@ FileInfo* PrePostProcessor::GetParCleanupQueueGroup(DownloadQueue* pDownloadQueu * * Mutex "m_mutexQueue" must be locked prior to call of this function. */ -bool PrePostProcessor::HasFailedParJobs(const char* szNZBFilename) +bool PrePostProcessor::HasFailedParJobs(const char* szNZBFilename, bool bIgnoreRepairPossible) { bool bHasFailedJobs = false; for (PostQueue::iterator it = m_CompletedJobs.begin(); it != m_CompletedJobs.end(); it++) { PostInfo* pPostInfo = *it; - if (pPostInfo->GetParCheck() && pPostInfo->GetParFailed() && + if (pPostInfo->GetParCheck() && + (pPostInfo->GetParStatus() == PARSTATUS_FAILED || + (!bIgnoreRepairPossible && pPostInfo->GetParStatus() == PARSTATUS_REPAIR_POSSIBLE)) && !strcmp(pPostInfo->GetNZBFilename(), szNZBFilename)) { bHasFailedJobs = true; diff --git a/PrePostProcessor.h b/PrePostProcessor.h index ce5bb5b9..673a1829 100644 --- a/PrePostProcessor.h +++ b/PrePostProcessor.h @@ -126,7 +126,7 @@ private: void ParCheckerUpdate(Subject* Caller, void* Aspect); bool AddPar(FileInfo* pFileInfo, bool bDeleted); FileInfo* GetParCleanupQueueGroup(DownloadQueue* pDownloadQueue, const char* szNZBFilename); - bool HasFailedParJobs(const char* szNZBFilename); + bool HasFailedParJobs(const char* szNZBFilename, bool bIgnoreRepairPossible); bool RequestMorePars(const char* szNZBFilename, const char* szParFilename, int iBlockNeeded, int* pBlockFound); void FindPars(DownloadQueue* pDownloadQueue, const char* szNZBFilename, const char* szParFilename, Blocks* pBlocks, bool bStrictParName, bool bExactParName, int* pBlockFound);