Example #1
0
int CFileListXml::Onsave(const CString& strFileTemp)
{
	CString strFile = strFileTemp;
	if (strFile.IsEmpty())  //调用者未设置保存路径,选择上次加载的路径
	{
		strFile = m_strFileListXML;

		if (strFile.IsEmpty())  //还是空
		{
			return Error_File_List_Path_Is_NULL;
		}
	}	

	XML_PARSER parser;
	if (!parser.Load_XML_String("<?xml version=\"1.0\" encoding=\"utf-8\" ?><root version=\"2.0\"/>"))
	{
		return Error_File_List_Load_Xml_Declaration;
	}

	//项目名称
	parser.Add_LastChildElement(NODE_Project);
	SetAttribute(parser, ATTRIBUTE_Project_Name, m_strProjectName);
	parser.Go_to_Root();

	//X86节点及文件列表
	parser.Add_LastChildElement(NODE_X86);
	for (vector<FILE_ITEM>::const_iterator it=m_x86FileList.begin(); it!=m_x86FileList.end(); it++)
	{
		parser.Add_LastChildElement(NODE_ITEM);
		SetAttribute(parser, ATTRIBUTE_ITEM_Name, it->strName);
		SetAttribute(parser, ATTRIBUTE_ITEM_Source_Path, it->strSrcPath);
		SetAttribute(parser, ATTRIBUTE_ITEM_Dest_Path, it->strDestPath);
		parser.Go_to_Parent(NODE_X86);
	}
	parser.Go_to_Root();

	//X64节点及文件列表
	parser.Add_LastChildElement(NODE_X64);
	for (vector<FILE_ITEM>::const_iterator it=m_x64FileList.begin(); it!=m_x64FileList.end(); it++)
	{
		parser.Add_LastChildElement(NODE_ITEM);
		SetAttribute(parser, ATTRIBUTE_ITEM_Name, it->strName);
		SetAttribute(parser, ATTRIBUTE_ITEM_Source_Path, it->strSrcPath);
		SetAttribute(parser, ATTRIBUTE_ITEM_Dest_Path, it->strDestPath);
		parser.Go_to_Parent(NODE_X64);
	}
	parser.Go_to_Root();

	//保存到文件
	if (!parser.Save_XML_Document(strFile))
	{
		return Error_File_List_Unknown_Reason;
	}
	else
	{
		return Error_File_List_Success;
	}
}
Example #2
0
int CFileListXml::Onload(const void* param)
{
	m_strFileListXML = _T("");	//上一次加载的文件路径清空
	CString strFile = (LPCTSTR)param;
	if (!CPathUtilEx::IsFileExist(strFile))
	{
		return Error_File_List_File_Is_Not_Exist;
	}

	XML_PARSER parser;
	if (!parser.Load_XML_Document(strFile))
	{
		return Error_File_List_Xml_Format_Wrong;
	}

	//项目名称
	if (parser.Go_to_Child(NODE_Project))
	{
		m_strProjectName = GetAttribute(parser, ATTRIBUTE_Project_Name);
	}
	parser.Go_to_Root();

	//X86文件列表
	if (parser.Go_to_Child(NODE_X86) && parser.Go_to_Child(NODE_ITEM))
	{
		do 
		{
			FILE_ITEM item;
			item.strName = GetAttribute(parser, ATTRIBUTE_ITEM_Name);
			item.strSrcPath = GetAttribute(parser, ATTRIBUTE_ITEM_Source_Path);
			item.strDestPath =GetAttribute(parser, ATTRIBUTE_ITEM_Dest_Path);			
			m_x86FileList.push_back(item);

		} while (parser.Go_to_NextSibling(NODE_ITEM));
	}
	parser.Go_to_Root();

	//X64文件列表
	if (parser.Go_to_Child(NODE_X64) && parser.Go_to_Child(NODE_ITEM))
	{
		do 
		{
			FILE_ITEM item;
			item.strName = GetAttribute(parser, ATTRIBUTE_ITEM_Name);
			item.strSrcPath = GetAttribute(parser, ATTRIBUTE_ITEM_Source_Path);
			item.strDestPath = GetAttribute(parser, ATTRIBUTE_ITEM_Dest_Path);			
			m_x64FileList.push_back(item);

		} while (parser.Go_to_NextSibling(NODE_ITEM));
	}
	parser.Go_to_Root();

	m_strFileListXML = strFile;		//以便保存时无需设置路径
	return Error_File_List_Success;
}