Пример #1
0
void TIniFile::WriteString(const wxString &Section, const wxString &Ident,
  const wxString &Value)
{
	int I;

	I = GetSectionIndex(Section);
	// Section exists
	if (I != -1)
	{
		++I;
		while ((I < FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)) &&
		  (GetName(FFileBuffer->Item(I)) != Ident))
			++I;
		// End of File or Ident doesn't exists in the Section
		if ((I >= FFileBuffer->Count()) || IsSection(FFileBuffer->Item(I)))
		{
			if (Ident != EmptyStr)
				FFileBuffer->Insert(I, Ident + IniSeparator + Value);
		}
		// Ident does exists in the section
		else if (Ident != EmptyStr)
			FFileBuffer->Item(I) = Ident + IniSeparator + Value;
	}
	// Section doesn't exists, so add new [Section] with Ident=Value
	else
	{
		FFileBuffer->Add(EmptyStr);
		FFileBuffer->Add(IniBrackets[0] + Section + IniBrackets[1]);
		if (Ident != EmptyStr)
			FFileBuffer->Add(Ident + IniSeparator + Value);
	}
	SaveToFile();
}
Пример #2
0
//设置配置项的值(字符串)
void CIniFile::SetString(const char* sSectionName, const char* sKeyName, const char* sKeyValue)
{
	int i = GetSectionIndex(0,sSectionName);
	int j;
	if(i < 0)
		i = AddSection(sSectionName);
	if(i >= 0)
		j = GetKeyIndex(i, sKeyName);
	else 
		return;
	
	struct LINE_ITEM *pItem;
	if(j >= 0)
	{
		pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(j);
		pItem->sValue = sKeyValue;
	}
	else
	{
		pItem = new struct LINE_ITEM;
		pItem->nType = LINE_TYPE_KEY;
		pItem->sName = sKeyName;
		pItem->sValue = sKeyValue;
		m_arrayOfLine.InsertAt(i + 1, pItem);
		j = i+1;
	}
	if(j >= 0)
		m_bModified = true;
	if(m_bAutoFlush)
		FlushToFile();
}
Пример #3
0
//删除一个区域
void CIniFile::DelSection(const char* sSectionName)
{
	int i = GetSectionIndex(0,sSectionName);
	struct LINE_ITEM *pItem;
	if(i >= 0) 
	{
		pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i);
		m_arrayOfLine.RemoveAt(i);
		if(pItem)
			delete pItem;
		
		for(; i < m_arrayOfLine.GetSize(); i)
		{
			pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i);
			if(pItem && pItem->nType == LINE_TYPE_SECTION )
					break;
			else
			{
				if(pItem)
					delete pItem;
				m_arrayOfLine.RemoveAt(i);
			}
		}

		m_bModified = true;
		if(m_bAutoFlush)
			FlushToFile();
	}
}
Пример #4
0
void TIniFile::ReadSectionNames(const wxString &Section, TStringList &Strings)
{
	wxString N;
	wxString V;
	int I;

	// Assert( !! Strings , SStringsUnassignedError );
	Strings.BeginUpdate();
	try
	{
		Strings.Clear();
		if (FFileBuffer->Count() > 0)
		{
			I = GetSectionIndex(Section);
			if (I != -1)
			{
				++I;
				while ((I < FFileBuffer->Count()) && !IsSection
				  (FFileBuffer->Item(I)))
				{
					N = GetName(FFileBuffer->Item(I));
					if (N != EmptyStr)
					{
						Strings.Add(N);
					}
					++I;
				}
			}
		}
	} /* ? *//* FINALLY */
	catch (...)
	{
		Strings.EndUpdate();
	}
}
Пример #5
0
wxString TIniFile::ReadString(const wxString &Section, const wxString &Ident,
  const wxString &Default)
{
	wxString result;
	int I;
	wxString V;

	result = Default;
	if (FFileBuffer->Count() > 0)
	{
		I = GetSectionIndex(Section);
		if (I != -1)
		{
			++I;
			while ((I < FFileBuffer->Count()) && !IsSection
			  (FFileBuffer->Item(I)))
			{
				wxString vName = GetName(FFileBuffer->Item(I));
				if (vName.CmpNoCase(Ident) == 0)
				{
					V = GetValue(FFileBuffer->Item(I), Ident);
					if (V != EmptyStr)
						result = V;
					return result;
				}
				++I;
			}
		}
	}
	return result;
}
Пример #6
0
//配置项值操作方法
//取得配置项的值(字符串)
CString CIniFile::GetString(const char* sSectionName, const char* sKeyName)
{
	int i = GetSectionIndex(0,sSectionName);
	if(i >= 0)
		i = GetKeyIndex(i, sKeyName);
	if(i >= 0)
	{
		struct LINE_ITEM *pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i);
		if(pItem)
			return pItem->sValue;
	}

	return "";
}
Пример #7
0
void TIniFile::EraseSection(const wxString &Section)
{
	long I;

	I = GetSectionIndex(Section);
	if (I != -1)
	{
		// Delete Section-Header
		FFileBuffer->Delete(I);
		// Delete Section-Items
		while ((I < FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)))
			FFileBuffer->Delete(I);
		if (I > 0)
			FFileBuffer->Insert(I, EmptyStr);
		SaveToFile();
	}
}
Пример #8
0
//增加一个区域,返回索引值,失败返回小于0的值
int CIniFile::AddSection(const char* sSectionName)
{
	int i = GetSectionIndex(0,sSectionName);
	if(i >= 0)
		return i;
	else
	{
		struct LINE_ITEM *pItem  = new struct LINE_ITEM;
		pItem->nType = LINE_TYPE_SECTION;
		pItem->sName = sSectionName;
		i = m_arrayOfLine.Add(pItem);

		m_bModified = true;
		if(m_bAutoFlush)
			FlushToFile();

		return i;
	}
}
Пример #9
0
//取得指定区域中总配置项数
int CIniFile::GetKeyCount(const char* sSectionName)
{
	struct LINE_ITEM *pItem;
	int i = GetSectionIndex(0, sSectionName);
	int nTotalKey = 0;
	if(i >= 0) for(i ++; i < m_arrayOfLine.GetSize(); i ++)
	{
		pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i);
		if(pItem )
		{
			if(pItem->nType == LINE_TYPE_SECTION )
				break;
			if(pItem->nType == LINE_TYPE_KEY)
				nTotalKey ++;
		}
	}

	return nTotalKey;
}
Пример #10
0
void TIniFile::DeleteKey(const wxString &Section, const wxString &Ident)
{
	long I;

	I = GetSectionIndex(Section);
	if (I != -1)
	{
		++I;
		while ((I < FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)) &&
		  (GetName(FFileBuffer->Item(I)) != Ident))
			++I;
		// Ident does exists
		if (!(I >= FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)))
		{
			FFileBuffer->Delete(I);
			SaveToFile();
		}
	}
}
Пример #11
0
int32 UAnimMontage::AddAnimCompositeSection(FName InSectionName, float StartTime)
{
	FCompositeSection NewSection;

	// make sure same name doesn't exists
	if ( InSectionName != NAME_None )
	{
		NewSection.SectionName = InSectionName;
	}
	else
	{
		// just give default name
		NewSection.SectionName = FName(*FString::Printf(TEXT("Section%d"), CompositeSections.Num()+1));
	}

	// we already have that name
	if ( GetSectionIndex(InSectionName)!=INDEX_NONE )
	{
		UE_LOG(LogAnimation, Warning, TEXT("AnimCompositeSection : %s(%s) already exists. Choose different name."), 
			*NewSection.SectionName.ToString(), *InSectionName.ToString());
		return INDEX_NONE;
	}

	NewSection.StartTime = StartTime;

	// we'd like to sort them in the order of time
	int32 NewSectionIndex = CompositeSections.Add(NewSection);

	// when first added, just make sure to link previous one to add me as next if previous one doesn't have any link
	// it's confusing first time when you add this data
	int32 PrevSectionIndex = NewSectionIndex-1;
	if ( CompositeSections.IsValidIndex(PrevSectionIndex) )
	{
		if (CompositeSections[PrevSectionIndex].NextSectionName == NAME_None)
		{
			CompositeSections[PrevSectionIndex].NextSectionName = InSectionName;
		}
	}

	return NewSectionIndex;
}
Пример #12
0
//取得配置项名称
CString CIniFile::GetKeyName(const char* sSectionName, int nIndex)
{
	struct LINE_ITEM *pItem;
	int i = GetSectionIndex(0, sSectionName);
	if(i >= 0) for(i++; i < m_arrayOfLine.GetSize(); i ++)
	{
		pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(i);
		if(pItem )
		{
			if(pItem->nType == LINE_TYPE_SECTION )
				break;
			if(pItem->nType == LINE_TYPE_KEY)
				if(nIndex == 0)
					return pItem->sName;
				else
					nIndex --;
		}
	}

	return "";
}
Пример #13
0
/* Read all Names of one Section */
void TIniFile::ReadSection(const wxString &Section, TStringList &Strings)
{
	int I;
	wxString N;
	Strings.BeginUpdate();
	Strings.Clear();
	if (FFileBuffer->Count() > 0)
	{
		I = GetSectionIndex(Section);
		if (I != -1)
		{
			++I;
			while ((I < FFileBuffer->Count()) && !IsSection
			  (FFileBuffer->Item(I)))
			{
				N = GetName(FFileBuffer->Item(I));
				if (N != EmptyStr)
					Strings.Add(N);
				++I;
			}
		}
	}
}
Пример #14
0
//删除一个配置项
int CIniFile::DelKey(const char* sSectionName, const char* sKeyName)
{
	int nSectionIndex = GetSectionIndex(-1, sSectionName);
	if(nSectionIndex >= 0)
	{
		int nKeyIndex = this->GetKeyIndex(nSectionIndex, sKeyName);
		if(nKeyIndex >= 0)
		{
			struct LINE_ITEM *pItem;
			pItem = (struct LINE_ITEM *)m_arrayOfLine.GetAt(nKeyIndex);
			m_arrayOfLine.RemoveAt(nKeyIndex);
			if(pItem)
				delete pItem;

			m_bModified = true;
			if(m_bAutoFlush)
				FlushToFile();
		}

		return nKeyIndex;
	}

	return -1;
}
Пример #15
0
bool UAnimMontage::IsValidSectionName(FName InSectionName) const
{
	return GetSectionIndex(InSectionName) != INDEX_NONE;
}