Ejemplo n.º 1
0
/// \brief	The Initialization for the Object
/// \param	IManager* pManager: Parent Manager
void  CVertexShader::Init()
{
	StdString infile = GetName()->GetString();
	GetStringFromFile( infile, m_Code );

	ReleaseShader();

	LoadVariant( NULL, true );
}
Ejemplo n.º 2
0
void CIniFileBase::GetKeyValueData ( LPCTSTR lpSectionName, KeyValueData & List )
{
	CGuard Guard(m_CS);
	if (!m_File.IsOpen())
	{
		return;
	}

	std::string strSection;

	if (lpSectionName == NULL || _tcslen(lpSectionName) == 0)
	{
		strSection = "default";
	}
	else
	{
		strSection = lpSectionName;
	}

	if (!MoveToSectionNameData(strSection.c_str(),false)) { return; }

	int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
	char *Input = NULL, *Data = NULL;
	do {
		result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
		if (result <= 1) { continue; }
		if (strlen(CleanLine(Input)) <= 1) { continue; }
		if (Input[0] == '[') { break; }
		char * Pos = strchr(Input,'=');
		if (Pos == NULL) { continue; }
		Pos[0] = 0;

		List.insert(KeyValueData::value_type(Input,&Pos[1]));
	} while (result >= 0);
	if (Data) {  delete [] Data;  Data = NULL; }
}
Ejemplo n.º 3
0
bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurrentSection )
{
	if (strcmp(lpSectionName,m_CurrentSection.c_str()) == 0) 
	{
		return true;
	}
	if (ChangeCurrentSection)
	{
		SaveCurrentSection();
		m_CurrentSection = "";
	}
	
	char *Input = NULL, *Data = NULL;
	int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;

	FILELOC_ITR iter = m_SectionsPos.find(std::string(lpSectionName));
	bool bFoundSection = false;
	if (iter != m_SectionsPos.end())
	{
		if (ChangeCurrentSection)
		{
			m_CurrentSection = iter->first;
			m_CurrentSectionFilePos = iter->second;
		}
		m_File.Seek(iter->second,CFileBase::begin);
		bFoundSection = true;
	}
	else
	{
		m_File.Seek(m_lastSectionSearch, CFileBase::begin);

		//long Fpos;
		BYTE pUTF8[3];
		pUTF8[0] = 0xef;
		pUTF8[1] = 0xbb;
		pUTF8[2] = 0xbf;

		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1) { continue; }

			//We Only care about sections
			char * CurrentSection = Input;

			if (m_lastSectionSearch == 0 && !memcmp(CurrentSection, pUTF8, 3))
			{
				CurrentSection += 3;
			}

			if (CurrentSection[0] != '[') { continue; }
			int lineEndPos = (int)strlen(CurrentSection) - 1;  
			if (CurrentSection[lineEndPos] != ']') { continue; }
			//take off the ']' from the end of the string
			CurrentSection[lineEndPos] = 0;
			CurrentSection += 1;
			m_lastSectionSearch = (m_File.GetPosition() - DataSize) + ReadPos;
			m_SectionsPos.insert(FILELOC::value_type(CurrentSection,m_lastSectionSearch));

			if (_stricmp(lpSectionName,CurrentSection) != 0)
			{
				continue;
			}

			if (ChangeCurrentSection)
			{
				m_CurrentSection = lpSectionName;
				m_CurrentSectionFilePos = m_lastSectionSearch;
			}
			else
			{
				m_File.Seek(m_lastSectionSearch,CFileBase::begin);
			}
			bFoundSection = true;
			break;
		} while (result >= 0);
	}

	if (bFoundSection && ChangeCurrentSection)
	{
		m_CurrentSectionData.clear();
		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1) { continue; }
			if (Input[0] == '[') { break; }
			char * Pos = strchr(Input,'=');
			if (Pos == NULL) { continue; }
			char * Value = &Pos[1];

			char * Pos1 = Pos-1;
			while (((*Pos1 == ' ') || (*Pos1 == '\t')) && (Pos1 > Input))
			{
				Pos1--;
			}
			Pos1[1] = 0;

			m_CurrentSectionData.insert(KeyValueList::value_type(Input,Value));
		} while (result >= 0);
	}

	if (Data) {  delete [] Data;  Data = NULL; }
	return bFoundSection;
}
Ejemplo n.º 4
0
void CIniFileBase::SaveCurrentSection ( void )
{
	if (!m_CurrentSectionDirty)
	{
		return;
	}
	m_CurrentSectionDirty = false;
	if (m_CurrentSection.length() == 0)
	{
		m_CurrentSection = "default";
	}

	int lineFeedLen = (int)strlen(m_LineFeed);

	if (m_CurrentSectionFilePos == -1)
	{
		//Section has not been added yet
		m_File.Seek(0,CFileBase::end);

		int len = (int)m_CurrentSection.length() + (lineFeedLen * 2) + 5;
		AUTO_PTR<char> SectionName(new char[len]);
		if (m_File.GetLength() < (int)strlen(m_LineFeed))
		{
			sprintf(SectionName.get(),"[%s]%s",m_CurrentSection.c_str(),m_LineFeed);
		}
		else
		{
			sprintf(SectionName.get(),"%s[%s]%s",m_LineFeed,m_CurrentSection.c_str(),m_LineFeed);
		}
		m_File.Write(SectionName.get(),(int)strlen(SectionName.get()));
		m_CurrentSectionFilePos = m_File.GetPosition();
		m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection,m_CurrentSectionFilePos));
	}
	else
	{
		//increase/decrease space needed
		int NeededBufferLen = 0;
		{
			AUTO_PTR<char> LineData(NULL);
			int len = 0;

			for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
			{
				int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
				if (newLen > len)
				{
					LineData.reset(new char[newLen]);
					len = newLen;
				}
				sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
				NeededBufferLen += (int)strlen(LineData.get());
			}
		}
		int currentLen = 0;

		m_File.Seek(m_CurrentSectionFilePos, CFileBase::begin);

		int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
		char *Input = NULL, *Data = NULL;
	
		//Skip first line as it is the section name
		int StartPos = m_CurrentSectionFilePos;
		int EndPos = StartPos;
		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
			{
				EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);

				continue; 
			}
			if (Input[0] == '[')
			{
				NeededBufferLen += lineFeedLen;
			}
			break;
		} while (result >= 0);
		currentLen = EndPos - StartPos;

		if (Data) {  delete [] Data;  Data = NULL; }

		if (NeededBufferLen != currentLen)
		{
			fInsertSpaces(StartPos,NeededBufferLen - currentLen);
			m_File.Flush();
			ClearSectionPosList(StartPos);
		}
		//set pointer to beginning of the start pos
		m_File.Seek(StartPos, CFileBase::begin);
	}


	{
		AUTO_PTR<char> LineData(NULL);
		int len = 0;
		
		for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
		{
			int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
			if (newLen > len)
			{
				LineData.reset(new char[newLen]);
				len = newLen;
			}
			sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
			m_File.Write(LineData.get(),(int)strlen(LineData.get()));
		}
	}
	m_File.Flush();
}
CString* CLocalizationEngine::GetString(const char* aId)
{
	CString* lLocalizedString = new CString(aId); //if String can't be found, use the indentifier for the String
	CString* lStringId = new CString(aId);
	CString* lFileName;
	CString* lCategoryName;
	CString* lStringName;
	TInt lStartIndex = 0;
	TInt lDotIndex = 0;

	//Find FileName
	lDotIndex = lStringId->FindString(lStartIndex,"."); //find location of seperator
	if(lDotIndex == -1)
	{
		lLocalizedString->Replace("ID FILENAME ERROR!");

		//clean up
		delete lStringId;

		return lLocalizedString;
	}
	else
	{
		lFileName = lStringId->GetSubString(lStartIndex,lDotIndex);
		lStartIndex = lDotIndex + 1; //skip dot
	}

	//Find CategoryName
	lDotIndex = lStringId->FindString(lStartIndex,"."); //find location of seperator
	if(lDotIndex == -1)
	{
		lLocalizedString->Replace("ID CATEGORYNAME ERROR!");

		//clean up
		delete lStringId;
		delete lFileName;

		return lLocalizedString;
	}
	else
	{
		lCategoryName = lStringId->GetSubString(lStartIndex,lDotIndex - lStartIndex);
		lStartIndex = lDotIndex + 1; //skip dot
	}

	//get StringName
	lStringName = lStringId->GetSubString(lStartIndex, lStringId->GetLength() - lStartIndex); //cut the last part of the String that remains
	if(lStringName == NULL)
	{
		lLocalizedString->Replace("ID STRINGNAME ERROR!");

		//clean up
		delete lStringId;
		delete lFileName;
		delete lCategoryName;

		return lLocalizedString;
	}

	//call method to handle the actual lookup
	GetStringFromFile(lFileName, lCategoryName, lStringName, lLocalizedString);

	//clean up
	delete lStringId;
	delete lFileName;
	delete lCategoryName;
	delete lStringName;

	return lLocalizedString;
}