예제 #1
0
/*
 * Creates new nzb-item out of existing files from other nzb-items.
 * If any of file-items is being downloaded the command fail.
 * For each file-item an event "eaFileDeleted" is fired.
 */
bool QueueCoordinator::SplitQueueEntries(DownloadQueue* pDownloadQueue, FileList* pFileList, const char* szName, NZBInfo** pNewNZBInfo)
{
    if (pFileList->empty())
    {
        return false;
    }

    NZBInfo* pSrcNZBInfo = NULL;

    for (FileList::iterator it = pFileList->begin(); it != pFileList->end(); it++)
    {
        FileInfo* pFileInfo = *it;
        if (pFileInfo->GetActiveDownloads() > 0 || pFileInfo->GetCompletedArticles() > 0)
        {
            error("Could not split %s. File is already (partially) downloaded", pFileInfo->GetFilename());
            return false;
        }
        if (pFileInfo->GetNZBInfo()->GetPostInfo())
        {
            error("Could not split %s. File in post-process-stage", pFileInfo->GetFilename());
            return false;
        }
        if (!pSrcNZBInfo)
        {
            pSrcNZBInfo = pFileInfo->GetNZBInfo();
        }
    }

    NZBInfo* pNZBInfo = new NZBInfo();
    pDownloadQueue->GetQueue()->push_back(pNZBInfo);

    pNZBInfo->SetFilename(pSrcNZBInfo->GetFilename());
    pNZBInfo->SetName(szName);
    pNZBInfo->SetCategory(pSrcNZBInfo->GetCategory());
    pNZBInfo->SetFullContentHash(0);
    pNZBInfo->SetFilteredContentHash(0);
    pNZBInfo->SetPriority(pSrcNZBInfo->GetPriority());
    pNZBInfo->BuildDestDirName();
    pNZBInfo->SetQueuedFilename(pSrcNZBInfo->GetQueuedFilename());
    pNZBInfo->GetParameters()->CopyFrom(pSrcNZBInfo->GetParameters());

    pSrcNZBInfo->SetFullContentHash(0);
    pSrcNZBInfo->SetFilteredContentHash(0);

    for (FileList::iterator it = pFileList->begin(); it != pFileList->end(); it++)
    {
        FileInfo* pFileInfo = *it;

        DownloadQueue::Aspect aspect = { DownloadQueue::eaFileDeleted, pDownloadQueue, pFileInfo->GetNZBInfo(), pFileInfo };
        pDownloadQueue->Notify(&aspect);

        pFileInfo->SetNZBInfo(pNZBInfo);
        pNZBInfo->GetFileList()->push_back(pFileInfo);
        pSrcNZBInfo->GetFileList()->Remove(pFileInfo);

        pSrcNZBInfo->SetFileCount(pSrcNZBInfo->GetFileCount() - 1);
        pSrcNZBInfo->SetSize(pSrcNZBInfo->GetSize() - pFileInfo->GetSize());
        pSrcNZBInfo->SetRemainingSize(pSrcNZBInfo->GetRemainingSize() - pFileInfo->GetRemainingSize());
        pSrcNZBInfo->SetCurrentSuccessSize(pSrcNZBInfo->GetCurrentSuccessSize() - pFileInfo->GetSuccessSize());
        pSrcNZBInfo->SetCurrentFailedSize(pSrcNZBInfo->GetCurrentFailedSize() - pFileInfo->GetFailedSize() - pFileInfo->GetMissedSize());
        pSrcNZBInfo->SetTotalArticles(pSrcNZBInfo->GetTotalArticles() - pFileInfo->GetTotalArticles());
        pSrcNZBInfo->SetCurrentSuccessArticles(pSrcNZBInfo->GetCurrentSuccessArticles() - pFileInfo->GetSuccessArticles());
        pSrcNZBInfo->SetCurrentFailedArticles(pSrcNZBInfo->GetCurrentFailedArticles() - pFileInfo->GetFailedArticles());
        pSrcNZBInfo->GetCurrentServerStats()->ListOp(pFileInfo->GetServerStats(), ServerStatList::soSubtract);

        pNZBInfo->SetFileCount(pNZBInfo->GetFileCount() + 1);
        pNZBInfo->SetSize(pNZBInfo->GetSize() + pFileInfo->GetSize());
        pNZBInfo->SetRemainingSize(pNZBInfo->GetRemainingSize() + pFileInfo->GetRemainingSize());
        pNZBInfo->SetCurrentSuccessSize(pNZBInfo->GetCurrentSuccessSize() + pFileInfo->GetSuccessSize());
        pNZBInfo->SetCurrentFailedSize(pNZBInfo->GetCurrentFailedSize() + pFileInfo->GetFailedSize() + pFileInfo->GetMissedSize());
        pNZBInfo->SetTotalArticles(pNZBInfo->GetTotalArticles() + pFileInfo->GetTotalArticles());
        pNZBInfo->SetCurrentSuccessArticles(pNZBInfo->GetCurrentSuccessArticles() + pFileInfo->GetSuccessArticles());
        pNZBInfo->SetCurrentFailedArticles(pNZBInfo->GetCurrentFailedArticles() + pFileInfo->GetFailedArticles());
        pNZBInfo->GetCurrentServerStats()->ListOp(pFileInfo->GetServerStats(), ServerStatList::soAdd);

        if (pFileInfo->GetParFile())
        {
            pSrcNZBInfo->SetParSize(pSrcNZBInfo->GetParSize() - pFileInfo->GetSize());
            pSrcNZBInfo->SetParCurrentSuccessSize(pSrcNZBInfo->GetParCurrentSuccessSize() - pFileInfo->GetSuccessSize());
            pSrcNZBInfo->SetParCurrentFailedSize(pSrcNZBInfo->GetParCurrentFailedSize() - pFileInfo->GetFailedSize() - pFileInfo->GetMissedSize());
            pSrcNZBInfo->SetRemainingParCount(pSrcNZBInfo->GetRemainingParCount() - 1);

            pNZBInfo->SetParSize(pNZBInfo->GetParSize() + pFileInfo->GetSize());
            pNZBInfo->SetParCurrentSuccessSize(pNZBInfo->GetParCurrentSuccessSize() + pFileInfo->GetSuccessSize());
            pNZBInfo->SetParCurrentFailedSize(pNZBInfo->GetParCurrentFailedSize() + pFileInfo->GetFailedSize() + pFileInfo->GetMissedSize());
            pNZBInfo->SetRemainingParCount(pNZBInfo->GetRemainingParCount() + 1);
        }

        if (pFileInfo->GetPaused())
        {
            pSrcNZBInfo->SetPausedFileCount(pSrcNZBInfo->GetPausedFileCount() - 1);
            pSrcNZBInfo->SetPausedSize(pSrcNZBInfo->GetPausedSize() - pFileInfo->GetRemainingSize());

            pNZBInfo->SetPausedFileCount(pSrcNZBInfo->GetPausedFileCount() + 1);
            pNZBInfo->SetPausedSize(pNZBInfo->GetPausedSize() + pFileInfo->GetRemainingSize());
        }
    }

    pNZBInfo->UpdateMinMaxTime();
    if (pSrcNZBInfo->GetCompletedFiles()->empty())
    {
        pSrcNZBInfo->UpdateMinMaxTime();
    }

    if (pSrcNZBInfo->GetFileList()->empty())
    {
        pDownloadQueue->GetQueue()->Remove(pSrcNZBInfo);
        g_pDiskState->DiscardFiles(pSrcNZBInfo);
        delete pSrcNZBInfo;
    }

    *pNewNZBInfo = pNZBInfo;
    return true;
}
예제 #2
0
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);
}
예제 #3
0
파일: Scanner.cpp 프로젝트: pepijntb/nzbget
bool Scanner::AddFileToQueue(const char* szFilename, const char* szNZBName, const char* szCategory,
	int iPriority, const char* szDupeKey, int iDupeScore, EDupeMode eDupeMode,
	NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, int* pNZBID)
{
	const char* szBasename = Util::BaseFileName(szFilename);

	info("Adding collection %s to queue", szBasename);

	NZBFile* pNZBFile = NZBFile::Create(szFilename, szCategory);
	bool bOK = pNZBFile != NULL;
	if (!bOK)
	{
		error("Could not add collection %s to queue", szBasename);
	}

	char bakname2[1024];
	if (!Util::RenameBak(szFilename, pNZBFile ? "queued" : "error", false, bakname2, 1024))
	{
		bOK = false;
		char szSysErrStr[256];
		error("Could not rename file %s to %s: %s", szFilename, bakname2, Util::GetLastErrorMessage(szSysErrStr, sizeof(szSysErrStr)));
	}

	if (bOK)
	{
		NZBInfo* pNZBInfo = pNZBFile->GetNZBInfo();
		pNZBInfo->SetQueuedFilename(bakname2);

		if (szNZBName && strlen(szNZBName) > 0)
		{
			pNZBInfo->SetName(NULL);
#ifdef WIN32
			char* szAnsiFilename = strdup(szNZBName);
			WebUtil::Utf8ToAnsi(szAnsiFilename, strlen(szAnsiFilename) + 1);
			pNZBInfo->SetFilename(szAnsiFilename);
			free(szAnsiFilename);
#else
			pNZBInfo->SetFilename(szNZBName);
#endif
			pNZBInfo->BuildDestDirName();
		}

		pNZBInfo->SetDupeKey(szDupeKey);
		pNZBInfo->SetDupeScore(iDupeScore);
		pNZBInfo->SetDupeMode(eDupeMode);
		pNZBInfo->SetPriority(iPriority);
		if (pUrlInfo)
		{
			pNZBInfo->SetURL(pUrlInfo->GetURL());
			pNZBInfo->SetUrlStatus(pUrlInfo->GetUrlStatus());
		}

		if (pNZBFile->GetPassword())
		{
			pNZBInfo->GetParameters()->SetParameter("*Unpack:Password", pNZBFile->GetPassword());
		}

		pNZBInfo->GetParameters()->CopyFrom(pParameters);

		for (::FileList::iterator it = pNZBInfo->GetFileList()->begin(); it != pNZBInfo->GetFileList()->end(); it++)
		{
			FileInfo* pFileInfo = *it;
			pFileInfo->SetPaused(bAddPaused);
		}

		g_pQueueCoordinator->AddNZBFileToQueue(pNZBFile, pUrlInfo, bAddTop);

		if (pNZBID)
		{
			*pNZBID = pNZBInfo->GetID();
		}
	}

	delete pNZBFile;

	return bOK;
}