示例#1
0
CXmlConfig::CXmlConfig(CString strConfigFile):m_strLanguageCode(_T("0x0409")),m_bKnownLanguage(TRUE)
{
	if(!FindFirstFileExists((LPCTSTR)strConfigFile,FALSE))
	{
		HANDLE hFile = NULL;
		hFile = CreateFile(strConfigFile, READ_CONTROL, 0, NULL,
			CREATE_ALWAYS, 0, NULL);
		if (hFile != INVALID_HANDLE_VALUE)
		{
			CloseHandle(hFile);
		}
	}
	QueryDefaultLanguage();
	m_strConfigFile = strConfigFile;
	try
	{
		SetLanguage();	
		std::wifstream configFile(m_strConfigFile,ios_base::binary,_SH_SECURE);//以安全权限方式打开
		if(configFile)
		{
			//configFile.imbue(std::locale("CHS")); 
			file<TCHAR> fdoc(configFile);
			TCHAR* pConfigData = m_xmlDoc.allocate_string(fdoc.data());        // 分配字符串并将Config数据复制进去
			m_xmlDoc.parse<0>(pConfigData); 
			locale::global(locale("C"));//还原全局区域设定
			m_xmlRoot = m_xmlDoc.first_node();	
			if(0 == m_xmlRoot)
			{
				m_xmlDoc.append_node(m_xmlDoc.allocate_node(rapidxml::node_pi,m_xmlDoc.allocate_string(_T("xml version='1.0' encoding='utf-8'"))));
				m_xmlRoot =   m_xmlDoc.allocate_node(node_element,_T("config"),_T(""));  
				m_xmlDoc.append_node(m_xmlRoot);
			}
			configFile.close();
		}
		else
		{
			locale::global(locale("C"));//还原全局区域设定
			//LOGEX_FATAL(_T("cannot open file: ") + m_strConfigFile);
			throw runtime_error(string("cannot open file ")/* + filename*/);
		}
	}
	catch(...)
	{
		locale::global(locale("C"));//还原全局区域设定
		//LOGEX_FATAL(_T("error reading stream. "));
		throw runtime_error("error reading stream.");
	}


   locale::global(locale(""));
   //LOG_INFO(_T("ANSI CodePage: %d"), GetACP());
  // LOG_INFO(_T("SystemDefaultLangID: 0x%04x"), GetSystemDefaultLangID());
}
示例#2
0
BOOL FolderExists(LPCTSTR lpPath)
{
	return FindFirstFileExists(lpPath, FILE_ATTRIBUTE_DIRECTORY);
}
示例#3
0
BOOL FilePathExists(LPCTSTR lpPath)
{
	return FindFirstFileExists(lpPath, FALSE);
}