void TestNzb(std::string TestFilename) { INFO(std::string("Filename: ") + TestFilename); std::string NzbFilename(TestUtil::TestDataDir() + "/nzbfile/"+ TestFilename + ".nzb"); std::string InfoFilename(TestUtil::TestDataDir() + "/nzbfile/"+ TestFilename + ".txt"); NZBFile* pNZBFile = new NZBFile(NzbFilename.c_str(), ""); bool bParsedOK = pNZBFile->Parse(); REQUIRE(bParsedOK == true); FILE* infofile = fopen(InfoFilename.c_str(), FOPEN_RB); REQUIRE(infofile != NULL); char buffer[1024]; while (fgets(buffer, sizeof(buffer), infofile) && *buffer == '#') ; REQUIRE(*buffer); int iFileCount = atoi(buffer); REQUIRE(pNZBFile->GetNZBInfo()->GetFileCount() == iFileCount); for (int i = 0; i < iFileCount; i++) { while (fgets(buffer, sizeof(buffer), infofile) && *buffer == '#') ; REQUIRE(*buffer); FileInfo* pFileInfo = pNZBFile->GetNZBInfo()->GetFileList()->at(i); REQUIRE(pFileInfo != NULL); Util::TrimRight(buffer); REQUIRE(std::string(pFileInfo->GetFilename()) == std::string(buffer)); } fclose(infofile); delete pNZBFile; }
void HistoryCoordinator::HistoryRedownload(DownloadQueue* pDownloadQueue, HistoryList::iterator itHistory, HistoryInfo* pHistoryInfo, bool bRestorePauseState) { if (pHistoryInfo->GetKind() == HistoryInfo::hkUrl) { HistoryReturn(pDownloadQueue, itHistory, pHistoryInfo, false); return; } if (pHistoryInfo->GetKind() != HistoryInfo::hkNzb) { char szNiceName[1024]; pHistoryInfo->GetName(szNiceName, 1024); error("Could not return %s from history back to queue: history item has wrong type", szNiceName); return; } NZBInfo* pNZBInfo = pHistoryInfo->GetNZBInfo(); bool bPaused = bRestorePauseState && pNZBInfo->GetDeletePaused(); if (!Util::FileExists(pNZBInfo->GetQueuedFilename())) { error("Could not return %s from history back to queue: could not find source nzb-file %s", pNZBInfo->GetName(), pNZBInfo->GetQueuedFilename()); return; } NZBFile* pNZBFile = new NZBFile(pNZBInfo->GetQueuedFilename(), ""); if (!pNZBFile->Parse()) { error("Could not return %s from history back to queue: could not parse nzb-file", pNZBInfo->GetName()); delete pNZBFile; return; } info("Returning %s from history back to queue", pNZBInfo->GetName()); for (FileList::iterator it = pNZBFile->GetNZBInfo()->GetFileList()->begin(); it != pNZBFile->GetNZBInfo()->GetFileList()->end(); it++) { FileInfo* pFileInfo = *it; pFileInfo->SetPaused(bPaused); } if (Util::DirectoryExists(pNZBInfo->GetDestDir())) { detail("Deleting %s", pNZBInfo->GetDestDir()); char szErrBuf[256]; if (!Util::DeleteDirectoryWithContent(pNZBInfo->GetDestDir(), szErrBuf, sizeof(szErrBuf))) { error("Could not delete directory %s: %s", pNZBInfo->GetDestDir(), szErrBuf); } } pNZBInfo->BuildDestDirName(); if (Util::DirectoryExists(pNZBInfo->GetDestDir())) { detail("Deleting %s", pNZBInfo->GetDestDir()); char szErrBuf[256]; if (!Util::DeleteDirectoryWithContent(pNZBInfo->GetDestDir(), szErrBuf, sizeof(szErrBuf))) { error("Could not delete directory %s: %s", pNZBInfo->GetDestDir(), szErrBuf); } } g_pDiskState->DiscardFiles(pNZBInfo); // reset status fields (which are not reset by "HistoryReturn") pNZBInfo->SetMoveStatus(NZBInfo::msNone); pNZBInfo->SetUnpackCleanedUpDisk(false); pNZBInfo->SetParStatus(NZBInfo::psNone); pNZBInfo->SetRenameStatus(NZBInfo::rsNone); pNZBInfo->SetDownloadedSize(0); pNZBInfo->SetDownloadSec(0); pNZBInfo->SetPostTotalSec(0); pNZBInfo->SetParSec(0); pNZBInfo->SetRepairSec(0); pNZBInfo->SetUnpackSec(0); pNZBInfo->SetExtraParBlocks(0); pNZBInfo->ClearCompletedFiles(); pNZBInfo->GetServerStats()->Clear(); pNZBInfo->GetCurrentServerStats()->Clear(); pNZBInfo->CopyFileList(pNZBFile->GetNZBInfo()); g_pQueueCoordinator->CheckDupeFileInfos(pNZBInfo); delete pNZBFile; HistoryReturn(pDownloadQueue, itHistory, pHistoryInfo, false); g_pPrePostProcessor->NZBAdded(pDownloadQueue, pNZBInfo); }