Пример #1
0
void CIni::GetSectionNames(CStringArray *pArray) const
{
	if (pArray != NULL)
		pArray->RemoveAll();

	const DWORD LEN = GetSectionNames(NULL, 0);
	if (LEN == 0)
		return;

	LPTSTR psz = new TCHAR[LEN + 1];
	GetSectionNames(psz, LEN);
	ParseDNTString(psz, __SubStrAdd, pArray);
	delete [] psz;
}
Пример #2
0
BOOL CIni::IsSectionExist(LPCTSTR lpSection) const
{
	if (lpSection == NULL)
		return FALSE;

	// first get the section name list, then check if lpSection exists
	// in the list.
	const DWORD LEN = GetSectionNames(NULL, 0);
	if (LEN == 0)
		return FALSE;

	LPTSTR psz = new TCHAR[LEN + 1];
	GetSectionNames(psz, LEN);
	BOOL RES = !ParseDNTString(psz, __SubStrCompare, (LPVOID)lpSection);
	delete [] psz;
	return RES;
}
Пример #3
0
UINT CIniFile::GetAllSections(std::vector<std::wstring> &vSections)
{
	// 清空vector
	vSections.erase(vSections.begin(), vSections.end());

	const DWORD dwMaxSize(MAX_PATH*5);
	wchar_t wchAllSections[dwMaxSize];
	wchar_t wchSection[dwMaxSize];
	wmemset(wchAllSections, L'\0', _countof(wchAllSections));
	wmemset(wchSection, L'\0', _countof(wchSection));

	DWORD dwReturn = GetSectionNames(wchAllSections, dwMaxSize);

	if (L'\0' == wchAllSections[0])
	{
		// 第一个等于L'\0'
		// 无Section
	}
	else
	{
		// 第一个不等于L'\0'
		// 有Section

		// 分离出有用信息
		// 因为Section在数组中的存放形式为“Section1”,“\0”,“Section2”,“\0”,“\0”。
		// 所以如果检测到连续两个0,则break
		int i(0);
		for (i=0; i<dwMaxSize; ++i)
		{
			if (L'\0' == wchAllSections[i])
			{
				if (wchAllSections[i] == wchAllSections[i+1])
				{
					break;
				}
			}
		}
		++i;

		// 将有用信息进行分解
		const int nActualSize(i);
		int j(0);
		int nPos(0);
		for(j=0; j<nActualSize; ++j)
		{
			wchSection[nPos++] = wchAllSections[j];
			if (L'\0' == wchAllSections[j])
			{
				vSections.push_back(wchSection);
				wmemset(wchSection, L'\0', _countof(wchSection));
				nPos = 0;
			}
		}
	}

	return vSections.size();
}
Пример #4
0
BOOL Language::GetAllValueMap(VALUE_MAP &valueMap) const
{
	STRING_LIST nameList;
	if(GetSectionNames(nameList))
	{
		for(STRING_LIST::iterator ite=nameList.begin();ite!=nameList.end();ite++)
		{
			CString strSection = *ite;
			VALUE_MAP tmpMap;
			if(GetSectionValueMap(strSection, tmpMap))
			{
				VALUE_MAP::iterator itor_b = tmpMap.begin();
				VALUE_MAP::iterator itor_e = tmpMap.end();
				for (; itor_b != itor_e; itor_b++)
				{
					(void)valueMap.insert(std::make_pair(itor_b->first, itor_b->second));
				}
			}
		}
	}
	return TRUE;
}