Пример #1
0
void GProfile::Load()
{
	if (m_bCached)
		return;

	// destroy the cached objects
	Destroy();

	char *szBuffer = 0;
	long dwSize = 0;



#ifdef _WIN32
	
		// open the file
		HANDLE hFile = CreateFile((const char *)m_strFile, 
								  GENERIC_READ, 0, 0, OPEN_EXISTING,
								  FILE_ATTRIBUTE_NORMAL, 0);

		dwSize = GetFileSize(hFile, NULL); 
 
		szBuffer = new char[dwSize + 1];

		// read the file
		long dwRead;
		if (!ReadFile(hFile, szBuffer, dwSize, (DWORD *)&dwRead, 0))
		{
			delete [] szBuffer;
			CloseHandle(hFile);
		}

		// close the file
		CloseHandle(hFile);


#else
	// open the file
	GString strTemp;
	int nResult = strTemp.FromFile((const char *)m_strFile, 0);

	szBuffer = new char[strTemp.Length() + 1];
	memcpy(szBuffer,(const char *)strTemp, strTemp.Length());
	dwSize = strTemp.Length();

#endif


	// terminate the buffer
	//szBuffer[dwSize] = 0;

	ProfileParse(szBuffer, dwSize);

	delete [] szBuffer;

}
Пример #2
0
int GStringList::FromFileAppend(const char *pzDelimiter, const char *pzPathAndFileName, int nItemCount/* = -1*/)
{
	GString strTemp;
	if (strTemp.FromFile(pzPathAndFileName,0))
	{
		DeSerializeAppend(pzDelimiter, strTemp, nItemCount);
		return 1;
	}
	return 0;
}
Пример #3
0
int GStringList::FromFile(const char *pzDelimiter, const char *pzPathAndFileName, int nItemCount /* = -1*/)
{
	GString strData;
	if (strData.FromFile(pzPathAndFileName,0))
	{
		DeSerialize(pzDelimiter, strData, nItemCount);
		return 1;
	}
	return 0;
}
Пример #4
0
void GProfile::Load()
{
	// if there is no external config file, there is nothing to load.
	if (m_strFile.IsEmpty() || m_strFile == "NONE")
		return;	

	if (m_bCached)
		return;

	// destroy the cached objects
	Destroy();

	if (m_bIsXML)
	{
		//FromXMLFile(m_strFile);
		m_objectContainer.FromXMLFile(m_strFile);
		m_bCached = true;
		return;
	}


	char *szBuffer = 0;
	long dwSize = 0;

#if defined(_WIN32) && !defined(__WINPHONE)
	try {
		// open the file
		HANDLE hFile = CreateFile(m_strFile, 
								  GENERIC_READ, 0, 0, OPEN_EXISTING,
								  FILE_ATTRIBUTE_NORMAL, 0);
		if (INVALID_HANDLE_VALUE == hFile)
			ThrowLastError(m_strFile);

		dwSize = GetFileSize(hFile, NULL); 
		if (dwSize == -1)
			ThrowLastError(m_strFile);
 
		szBuffer = new char[dwSize + 1];
		if (!szBuffer)
			throw -1;

		// read the file
		long dwRead;
		if (!ReadFile(hFile, szBuffer, dwSize, (DWORD *)&dwRead, 0))
		{
			delete [] szBuffer;
			CloseHandle(hFile);
			ThrowLastError(m_strFile);
		}

		// close the file
		CloseHandle(hFile);
	}
	catch(GException &)
	{
		GString strMessage("\nFailed to open a configuration file for this application.\n");
		throw GException(2, (const char *)strMessage);
	}

#else
	// open the file
	GString strTemp;
	int nResult = strTemp.FromFile((const char *)m_strFile, 0);
	if (nResult == 0)
	{
		GString strMessage("\nFailed to open a configuration file for this application.\n");

		throw GException(2, (const char *)strMessage);
	}
	szBuffer = new char[strTemp.Length() + 1];
	memcpy(szBuffer,(const char *)strTemp, strTemp.Length());
	dwSize = strTemp.Length();

#endif


	// terminate the buffer
	szBuffer[dwSize] = 0;
	ProfileParse(szBuffer, dwSize);
	delete [] szBuffer;
}