Example #1
0
void CPatchFile::ExtractCompressed(Framework::CStream& outputStream, Framework::CStream& inputStream, uint32 compressedSize)
{
	z_stream zStream;
	zStream.zalloc = Z_NULL;
	zStream.zfree = Z_NULL;
	zStream.opaque = Z_NULL;
	zStream.avail_in = 0;
	zStream.next_in = Z_NULL;
	if(inflateInit(&zStream) != Z_OK)
	{
		throw std::runtime_error("zlib stream initialization error.");
	}

	const uint32 bufferSize = 0x4000;
	uint8 inBuffer[bufferSize];
	uint8 outBuffer[bufferSize];

	while(1)
	{
		if(zStream.avail_in == 0)
		{
			if(compressedSize == 0)
			{
				//EOF
				break;
			}
			uint32 toRead = std::min<uint32>(bufferSize, compressedSize);
			inputStream.Read(inBuffer, toRead);
			compressedSize -= toRead;
			zStream.avail_in = toRead;
			zStream.next_in = inBuffer;
		}

		zStream.avail_out = bufferSize;
		zStream.next_out = outBuffer;

		int ret = inflate(&zStream, Z_NO_FLUSH);
		if(ret < 0)
		{
			throw std::runtime_error("Error occured while inflating.");
			break;
		}

		int have = bufferSize - zStream.avail_out;
		outputStream.Write(outBuffer, have);
		if(ret == Z_STREAM_END)
		{
			break;
		}
	} 

	inflateEnd(&zStream);
}
Example #2
0
void CPatchFile::ExtractUncompressed(Framework::CStream& outputStream, Framework::CStream& inputStream, uint32 compressedSize)
{
	const uint32 bufferSize = 0x4000;
	uint8 buffer[bufferSize];
	while(compressedSize != 0)
	{
		uint32 toRead = std::min<uint32>(bufferSize, compressedSize);
		inputStream.Read(buffer, toRead);
		outputStream.Write(buffer, toRead);
		compressedSize -= toRead;
	}
}
Example #3
0
void CDialog::WriteDialogTemplate(DIALOGTEMPLATE& dialog, Framework::CStream& stream)
{
	stream.Write16(dialog.dlgVer);
	stream.Write16(dialog.signature);
	stream.Write32(dialog.helpID);
	stream.Write32(dialog.exStyle);
	stream.Write32(dialog.style);
	stream.Write16(dialog.cDlgItems);
	stream.Write16(dialog.x);
	stream.Write16(dialog.y);
	stream.Write16(dialog.cx);
	stream.Write16(dialog.cy);
	WriteSzOrOrd(dialog.menu, stream);
	WriteSzOrOrd(dialog.windowClass, stream);
	WriteString(dialog.title, stream);
	stream.Write16(dialog.pointsize);
	stream.Write16(dialog.weight);
	stream.Write8(dialog.italic);
	stream.Write8(dialog.charset);
	WriteString(dialog.typeface, stream);

	//Pad struct for alignment to DWORD boundary
	{
		auto currentBytePos = stream.Tell() & 0x3;
		if(currentBytePos != 0)
		{
			for(unsigned int i = 0; i < (4 - currentBytePos); i++)
			{
				stream.Write8(0);
			}
		}
		assert((stream.Tell() & 0x03) == 0);
	}

	if(!dialog.dialogItemData.empty())
	{
		stream.Write(dialog.dialogItemData.data(), dialog.dialogItemData.size());
	}
}
Example #4
0
uint32 CIoman::Write(uint32 handle, uint32 size, const void* buffer)
{
	CLog::GetInstance().Print(LOG_NAME, "Write(handle = %d, size = 0x%X, buffer = ptr);\r\n", handle, size);

	uint32 result = 0xFFFFFFFF;
	try
	{
		Framework::CStream* stream = GetFileStream(handle);
		result = static_cast<uint32>(stream->Write(buffer, size));
		if((handle == FID_STDOUT) || (handle == FID_STDERR))
		{
			//Force flusing stdout and stderr
			stream->Flush();
		}
	}
	catch(const std::exception& except)
	{
		if((handle != FID_STDOUT) && (handle != FID_STDERR))
		{
			CLog::GetInstance().Print(LOG_NAME, "%s: Error occured while trying to write file : %s\r\n", __FUNCTION__, except.what());
		}
	}
	return result;
}