| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 | 
							- #include "stdafx.h"
 
- #include "ChaiScriptXml.h"
 
- #include "tinyxml\tinyxml.h"
 
- #include "Shared\TextConvert.h"
 
- #include "Misc.h"
 
- #include "ActionEnums.h"
 
- CChaiScriptXml::CChaiScriptXml()
 
- {
 
- 	m_assignedGuidOnLoad = false;
 
- }
 
- CChaiScriptXml::~CChaiScriptXml()
 
- {
 
- }
 
- CString CChaiScriptXml::GetScript(CString name, BOOL &active)
 
- {
 
- 	CString script;
 
- 	for (auto & listItem : m_list)
 
- 	{
 
- 		if (listItem.m_name == name)
 
- 		{
 
- 			active = listItem.m_active;
 
- 			script = listItem.m_name;
 
- 			break;
 
- 		}
 
- 	}
 
- 	return script;
 
- }
 
- void CChaiScriptXml::Load(CString values)
 
- {
 
- 	m_assignedGuidOnLoad = false;
 
- 	m_list.clear();
 
- 	
 
- 	TiXmlDocument doc;
 
- 	CStringA xmlA;
 
- 	CTextConvert::ConvertToUTF8(values, xmlA);
 
- 	doc.Parse(xmlA);
 
- 	TiXmlElement *ItemHeader = doc.FirstChildElement("ChaiScripts");
 
- 	if (ItemHeader != NULL)
 
- 	{
 
- 		TiXmlElement *ItemElement = ItemHeader->FirstChildElement();
 
- 		while (ItemElement)
 
- 		{
 
- 			CDittoChaiScriptXmlItem array_item;
 
- 			ItemElement->Attribute("active", &array_item.m_active);
 
- 			array_item.m_name = ItemElement->Attribute("name");
 
- 			array_item.m_description = ItemElement->Attribute("description");
 
- 			array_item.m_script = ItemElement->Attribute("script");
 
- 			array_item.m_guid = ItemElement->Attribute("guid");
 
- 			array_item.m_version = ItemElement->Attribute("vesion");
 
- 			if (array_item.m_guid == "")
 
- 			{
 
- 				array_item.m_guid = NewGuidString();
 
- 				m_assignedGuidOnLoad = true;
 
- 			}
 
- 			m_list.push_back(array_item);
 
- 			ItemElement = ItemElement->NextSiblingElement();
 
- 		}
 
- 	}
 
- }
 
- CString CChaiScriptXml::Save()
 
- {
 
- 	m_assignedGuidOnLoad = false;
 
- 	TiXmlDocument doc;
 
- 	TiXmlElement* friendOuter = new TiXmlElement("ChaiScripts");
 
- 	doc.LinkEndChild(friendOuter);
 
- 	for (auto & listItem : m_list)
 
- 	{
 
- 		TiXmlElement* friendElement = new TiXmlElement("ChaiScriptItem");
 
- 		friendElement->SetAttribute("active", listItem.m_active);
 
- 		CStringA name;
 
- 		CTextConvert::ConvertToUTF8(listItem.m_name, name);
 
- 		friendElement->SetAttribute("name", name);
 
- 		CStringA desc;
 
- 		CTextConvert::ConvertToUTF8(listItem.m_description, desc);
 
- 		friendElement->SetAttribute("description", desc);
 
- 		CStringA script;
 
- 		CTextConvert::ConvertToUTF8(listItem.m_script, script);
 
- 		friendElement->SetAttribute("script", script);
 
- 		CStringA guid;
 
- 		CTextConvert::ConvertToUTF8(listItem.m_guid, guid);
 
- 		friendElement->SetAttribute("guid", guid);
 
- 		CStringA version;
 
- 		CTextConvert::ConvertToUTF8(listItem.m_version, version);
 
- 		friendElement->SetAttribute("version", version);
 
- 		friendOuter->LinkEndChild(friendElement);
 
- 	}
 
- 	TiXmlPrinter printer;
 
- 	printer.SetLineBreak("");
 
- 	doc.Accept(&printer);
 
- 	CString cs = printer.CStr();
 
- 	return cs;
 
- }
 
- void CChaiScriptXml::AddToMenu(CMenu *pMenu, CAccels *actions)
 
- {
 
- 	if (m_list.size() > 0)
 
- 	{
 
- 		pMenu->AppendMenu(MF_SEPARATOR);
 
- 		bool addedItem = false;
 
- 		int id = 0;
 
- 		for (auto & element : m_list)
 
- 		{
 
- 			if (addedItem == false)
 
- 			{
 
- 				addedItem = true;
 
- 			}
 
- 			CString cs;
 
- 			if (element.m_description != _T(""))
 
- 			{
 
- 				cs.Format(_T("(%s) - %s"), element.m_name, element.m_description);
 
- 			}
 
- 			else
 
- 			{
 
- 				cs.Format(_T("%s"), element.m_name);
 
- 			}
 
- 			if (actions != NULL)
 
- 			{
 
- 				CString shortcutText = actions->GetCmdKeyText(ActionEnums::PASTE_SCRIPT, element.m_guid);
 
- 				if (shortcutText != _T(""))
 
- 				{
 
- 					cs += "\t";
 
- 					cs += shortcutText;
 
- 				}
 
- 			}
 
- 			pMenu->AppendMenuW(MF_STRING, (ChaiScriptMenuStartId + id), cs);
 
- 			id++;
 
- 			if (id > MaxChaiScripts)
 
- 			{
 
- 				break;
 
- 			}
 
- 		}
 
- 	}
 
- }
 
 
  |