Esempio n. 1
0
bool SMTController::makeThreads()
{
	for (uint32 x=0; x<m_uiNumber; x++)
	{
		gcString file("{0}", m_szFile);

		UTIL::FS::FileHandle* fh = new UTIL::FS::FileHandle();

		if (x != 0)
			file += gcString(".part_{0}", x);

		try
		{
			fh->open(file.c_str(), UTIL::FS::FILE_WRITE);

			//due to the first thread being the proper MCF we have to allow for the header.
			if (x == 0)
				fh->seek(MCFCore::MCFHeader::getSizeS());
		}
		catch (gcException &except)
		{
			safe_delete(fh);
			onErrorEvent(except);
			return false;
		}

		SMTWorkerInfo* temp = new SMTWorkerInfo(this, x, fh, file.c_str());
		m_vWorkerList.push_back(temp);
		temp->workThread->start();

		m_iRunningWorkers++;
	}

	return true;
}
Esempio n. 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);
	}
}