예제 #1
0
void HGTController::decompressDiff(uint64 size, UTIL::FS::FileHandle &fhSrc, UTIL::FS::FileHandle &fhDest)
{
	uint64 done = 0;

	uint32 buffSize = 10*1024;
	char buff[10*1024] = {0};

	UTIL::MISC::BZ2Worker worker(UTIL::MISC::BZ2_DECOMPRESS);

	fhSrc.read(done, [&worker, &fhDest](const unsigned char* buff, uint32 size) -> bool
	{
		UTIL::FS::FileHandle* pFile = &fhDest;

		worker.write((const char*)buff, size, [pFile](const unsigned char* tbuff, uint32 tsize) -> bool
		{
			pFile->write((const char*)tbuff, tsize);
			return false;
		});

		return false;
	});

	worker.end([&fhDest](const unsigned char* tbuff, uint32 tsize) -> bool
	{
		fhDest.write((const char*)tbuff, tsize);
		return false;
	});
}
예제 #2
0
void MCF::parseMCF()
{
	gcTrace("");

	if (m_bStopped)
		return;

	UTIL::FS::FileHandle hFile;
	getReadHandle(hFile);

	m_pFileList.clear();

	MCFCore::MCFHeader tempHeader;
	tempHeader.readFromFile(hFile);
	setHeader(&tempHeader);

	hFile.seek(tempHeader.getXmlStart());

	uint32 xmlBuffLen = tempHeader.getXmlSize()+1;
	UTIL::MISC::Buffer xmlBuff(xmlBuffLen, true);

	hFile.read(xmlBuff, tempHeader.getXmlSize());


	if (getHeader()->getFlags() & MCFCore::MCFHeaderI::FLAG_NOTCOMPRESSED)
	{
		parseXml(xmlBuff, xmlBuffLen);
	}
	else
	{
		UTIL::MISC::BZ2Worker worker(UTIL::MISC::BZ2_DECOMPRESS);

		worker.write(xmlBuff, xmlBuffLen, true);
		worker.doWork();

		if (worker.getLastStatus() != BZ_STREAM_END)
			throw gcException(ERR_BZ2, worker.getLastStatus(), "Failed to decompress mcf header xml");

		size_t bz2BuffLen = worker.getReadSize();

		if (bz2BuffLen == 0)
			throw gcException(ERR_BZ2, worker.getLastStatus(), "Failed to decompress mcf header xml (zero size)");

		UTIL::MISC::Buffer bz2Buff(bz2BuffLen);

		worker.read(bz2Buff, bz2BuffLen);
		parseXml(bz2Buff, bz2BuffLen);
	}
}
예제 #3
0
void SMTController::postProcessing()
{
	if (m_uiNumber == 1)
		return;

	UTIL::FS::FileHandle fhSource;
	UTIL::FS::FileHandle fhSink;

	UTIL::FS::Path path(m_szFile, "", true);

	uint64 sinkSize = UTIL::FS::getFileSize(path);

	try
	{
		fhSink.open(path, UTIL::FS::FILE_APPEND);
	}
	catch (gcException &)
	{
		return;
	}

	char buff[BLOCKSIZE];

	for (size_t x=1; x<m_vWorkerList.size(); x++)
	{
		SMTWorkerInfo *worker = m_vWorkerList[x];

		uint64 fileSize = UTIL::FS::getFileSize(UTIL::FS::PathWithFile(worker->file));
		uint64 done = 0;

		uint32 readSize = BLOCKSIZE;

		try
		{
			fhSource.open(worker->file.c_str(), UTIL::FS::FILE_READ);
			while (fileSize > done)
			{
				if ((fileSize-done) < (uint64)readSize)
					readSize = (uint32)(fileSize-done);

				fhSource.read(buff, readSize);
				fhSink.write(buff, readSize);

				done += readSize;
			}
			fhSource.close();
		}
		catch (gcException &)
		{
		}

		for (size_t y=0; y<worker->vFileList.size(); y++)
		{
			uint32 index = worker->vFileList[y];
			MCFCore::MCFFile *temp = m_rvFileList[index];

			if (!temp)
				continue;

			temp->setOffSet( temp->getOffSet() + sinkSize );
		}

		sinkSize += fileSize;
		UTIL::FS::delFile(UTIL::FS::PathWithFile(worker->file));
	}

	if (m_bCreateDiff == false)
		return;
}