예제 #1
0
//---------------------------------------------------------------------------
// 函数:	Load
// 功能:	加载一个Tab文件
// 参数:	FileName	文件名
// 返回:	TRUE		成功
//			FALSE		失败
//---------------------------------------------------------------------------
BOOL KTabFile::Load(LPSTR FileName)
{
	KPakFile	File;
	DWORD		dwSize;
	PVOID		Buffer;

	// check file name
	if (FileName[0] == 0)
		return FALSE;

	if (!File.Open(FileName))
	{
		g_DebugLog("Can't open tab file : %s", FileName);
		return FALSE;
	}

	dwSize = File.Size();

	Buffer = m_Memory.Alloc(dwSize);

	File.Read(Buffer, dwSize);

	CreateTabOffset();

	return TRUE;
}
예제 #2
0
//---------------------------------------------------------------------------
// 函数:	LoadPack
// 功能:	打开一个压缩的INI文件
// 参数:	FileName	文件名
// 返回:	TRUE		成功
//			FALSE		失败
//---------------------------------------------------------------------------
BOOL KIniFile::LoadPack(LPCSTR FileName)
{
	KPakFile	File;
	PVOID		PackBuf;
	PVOID		DataBuf;

	TPackHead	Header;

	// check file name
	if (FileName[0] == 0)
		return FALSE;

	// close open file
	if (m_Header.pNextNode)
		Clear();

	// open the pack ini file
	if (!File.Open((char*)FileName))
		return FALSE;

	// read pack file header
	File.Read(&Header, sizeof(Header));

	// if not a pack file read directly
	if (Header.Id != 0x4b434150) // "PACK"
		return FALSE;

	// allocate buffer for pack data
	PackBuf = m_MemStack.Push(Header.PackLen);

	// allocate bufer for real data
	DataBuf = m_MemStack.Push(Header.DataLen + 2);

	// read pack data for file
	File.Read(PackBuf, Header.PackLen);

	// check data length

	// create ini link in memory
	CreateIniLink(DataBuf, Header.DataLen);

	return TRUE;
}
예제 #3
0
//---------------------------------------------------------------------------
// 函数:	Load
// 功能:	加载一个INI文件
// 参数:	FileName	文件名
// 返回:	TRUE		成功
//			FALSE		失败
//---------------------------------------------------------------------------
BOOL KIniFile::Load(LPCSTR FileName)
{
	KPakFile	File;
	DWORD		dwSize;
	PVOID		Buffer;
	TPackHead*	pHeader;

	// check file name
	if (FileName[0] == 0)
		return FALSE;

	if (m_Header.pNextNode)
		Clear();

	if (!File.Open((char*)FileName))
	{
		g_DebugLog("Can't open ini file : %s", FileName);
		return FALSE;
	}
#pragma message("KIniFile 当前不支持 KeyName 为中文! by Romandou")

	dwSize = File.Size();

	Buffer = m_MemStack.Push(dwSize + 4);

	File.Read(Buffer, dwSize);

	pHeader = (TPackHead*)Buffer;
	if (pHeader->Id == 0x4b434150) // "PACK"
	{
		File.Close();
		return LoadPack(FileName);
	}

	CreateIniLink(Buffer, dwSize);

	return TRUE;
}
예제 #4
0
파일: ChatFilter.cpp 프로젝트: viticm/pap2
BOOL CChatFilter::Initialize()
{
	Error_SetErrorString("CChatFilter::Initialize()");
	if (m_pTextFilter)
	{
		return TRUE;
	}

	KPakFile	FileChatFlt;

	if (FileChatFlt.Open((char*)file_chatflt) == FALSE)
	{
		Error_SetErrorCode(ERR_T_FILE_NO_FOUND);
		Error_SetErrorString(file_chatflt);
		return FALSE;
	}

	if (SUCCEEDED(g_libFilterText.CreateTextFilter(&m_pTextFilter)))
	{
		char* pBuffer = NULL;
		int nSize = FileChatFlt.Size();
		if (nSize)
			pBuffer = (char*)_alloca(nSize + 1);
		if (pBuffer)
		{
			int nFinalSize = FileChatFlt.Read(pBuffer, nSize);
			if (nFinalSize >= nSize)
				pBuffer[nSize] = 0;
			else
				memset(pBuffer + nFinalSize, 0, nSize - nFinalSize + 1);

			char* pLineHeader = pBuffer;

			do
			{
				char* pLineEnd = strchr(pLineHeader, 0x0a);
				int nLineLen;
				if (pLineEnd)
				{
					*pLineEnd = 0;
					nLineLen = pLineEnd - pLineHeader;
				}
				else
				{
					nLineLen = nFinalSize - (pLineHeader - pBuffer);
				}

				if (pLineHeader[0] && nLineLen > 0)
				{
					if (pLineHeader[nLineLen - 1] == 0x0d)
						pLineHeader[--nLineLen] = 0;
					if (nLineLen)
					{
						EDOneTimePad_Decipher(pLineHeader, nLineLen);
						m_pTextFilter->AddExpression(pLineHeader);
					}
				}

				pLineHeader = pLineEnd ? pLineEnd + 1: NULL;
			}while(pLineHeader);
		}
	}

	FileChatFlt.Close();

	if(m_pTextFilter)
	{
		return TRUE;
	}
	else
	{
		Error_SetErrorCode(ERR_T_MODULE_INIT_FAILED);
		return FALSE;
	}
}