Example #1
0
void COptions::SetXmlValue(unsigned int nID, wxString value)
{
	if (!m_pXmlFile)
		return;

	// No checks are made about the validity of the value, that's done in SetOption

	char *utf8 = ConvUTF8(value);
	if (!utf8)
		return;

	TiXmlElement *settings = m_pXmlFile->GetElement()->FirstChildElement("Settings");
	if (!settings)
	{
		TiXmlNode *node = m_pXmlFile->GetElement()->LinkEndChild(new TiXmlElement("Settings"));
		if (!node)
		{
			delete [] utf8;
			return;
		}
		settings = node->ToElement();
		if (!settings)
		{
			delete [] utf8;
			return;
		}
	}
	else
	{
		TiXmlNode *node = 0;
		while ((node = settings->IterateChildren("Setting", node)))
		{
			TiXmlElement *setting = node->ToElement();
			if (!setting)
				continue;

			const char *attribute = setting->Attribute("name");
			if (!attribute)
				continue;
			if (strcmp(attribute, options[nID].name))
				continue;

			//setting->RemoveAttribute("type");
			setting->Clear();
			//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
			setting->LinkEndChild(new TiXmlText(utf8));

			delete [] utf8;
			return;
		}
	}
	wxASSERT(options[nID].name[0]);
	TiXmlElement *setting = new TiXmlElement("Setting");
	setting->SetAttribute("name", options[nID].name);
	//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
	setting->LinkEndChild(new TiXmlText(utf8));
	settings->LinkEndChild(setting);

	delete [] utf8;
}
Example #2
0
//路径|节点|子节点|属性
//C:\Documents and Settings\All Users\Application Data\Storm\config.xml
//localplayhist
//item
//url
//C:\Documents and Settings\Administrator\桌面\0812_195706.3gp
BOOL CSpecialApp::CleanStorm_Clean(int Itype,LPCTSTR lpcszAppPath)
{
	CString strPath = lpcszAppPath;
	g_regClean.ConvetPath(strPath);

	CSimpleArray<CString> vec_String;
	int iCount = SplitCString1(strPath,vec_String,'|');

	if(iCount<2)
	{
		return FALSE;
	}

	TiXmlDocument xmlDoc;


	//获得文件夹名称改变其属性
	iCount = vec_String[0].ReverseFind('\\');
	CString strTmp;
	if (iCount>0)
	{
		strTmp = vec_String[0].Mid(0,iCount);
	}

	DWORD dwErrCode=0;
	if(FALSE == SetFileAttributes(strTmp, FILE_ATTRIBUTE_NORMAL))
	{
		dwErrCode=GetLastError();
	}

	USES_CONVERSION;
	FILE* lpFile = _tfopen(vec_String[0], _T("a+b"));
	if ( lpFile != NULL )
	{
		xmlDoc.LoadFile(lpFile);

		fclose(lpFile);

		if ( xmlDoc.Error() == 0 )
		{
			OutputDebugString(_T("\n打开文件成功\n"));

			TiXmlElement* rootNode = xmlDoc.RootElement();
			if (rootNode !=NULL)
			{
				TiXmlElement* nodeGeneral = rootNode->FirstChildElement(W2A(vec_String[1]));
				if ( nodeGeneral != NULL )
				{
//					rootNode->RemoveChild(nodeGeneral);
                    nodeGeneral->Clear();
					xmlDoc.SaveFile(W2A(vec_String[0]));
				}
			}
		}
	}
	return TRUE;

}
bool wxsItemResData::RebuildXrcFile()
{
    // First - opening file
    TiXmlDocument Doc;
    TiXmlElement* Resources = nullptr;
    TiXmlElement* Object = nullptr;

    if ( TinyXML::LoadDocument(m_XrcFileName,&Doc) )
    {
        Resources = Doc.FirstChildElement("resource");
    }

    if ( !Resources )
    {
        Doc.Clear();
        Doc.InsertEndChild(TiXmlDeclaration("1.0","utf-8",""));
        Resources = Doc.InsertEndChild(TiXmlElement("resource"))->ToElement();
        Resources->SetAttribute("xmlns","http://www.wxwidgets.org/wxxrc");
    }

    // Searching for object representing this resource
    for ( Object = Resources->FirstChildElement("object"); Object; Object = Object->NextSiblingElement("object") )
    {
        if ( cbC2U(Object->Attribute("name")) == m_ClassName )
        {
            Object->Clear();
            while ( Object->FirstAttribute() )
            {
                Object->RemoveAttribute(Object->FirstAttribute()->Name());
            }
            break;
        }
    }

    if ( !Object )
    {
        Object = Resources->InsertEndChild(TiXmlElement("object"))->ToElement();
    }

    // The only things left are: to dump item into object ...
    m_RootItem->XmlWrite(Object,true,false);
    Object->SetAttribute("name",cbU2C(m_ClassName));
    for ( int i=0; i<GetToolsCount(); i++ )
    {
        TiXmlElement* ToolElement = Object->InsertEndChild(TiXmlElement("object"))->ToElement();
        m_Tools[i]->XmlWrite(ToolElement,true,false);
    }

    // ... and save back the file
    return TinyXML::SaveDocument(m_XrcFileName,&Doc);
}
Example #4
0
bool SData::SaveCache()
{
  XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__);

  std::string strCacheFile;
  bool bFailed(false);
  TiXmlDocument doc;
  TiXmlElement *pRootElement = NULL;
  TiXmlElement *pTokenElement = NULL;

  strCacheFile = Utils::GetFilePath("cache.xml");

  if ((bFailed = !doc.LoadFile(strCacheFile))) {
    XBMC->Log(LOG_ERROR, "%s: failed to load \"%s\"", __FUNCTION__, strCacheFile.c_str());
  } else {
    pRootElement = doc.RootElement();
    if (!pRootElement || strcmp(pRootElement->Value(), "cache") != 0) {
      XBMC->Log(LOG_ERROR, "%s: invalid xml doc. root element 'cache' not found", __FUNCTION__);
      bFailed = true;
    }
  }

  if (bFailed) {
    XBMC->Log(LOG_DEBUG, "%s: creating root element 'cache'", __FUNCTION__);

    pRootElement = new TiXmlElement("cache");
    doc.LinkEndChild(pRootElement);
  }

  pTokenElement = pRootElement->FirstChildElement("token");
  if (!pTokenElement) {
    pTokenElement = new TiXmlElement("token");
    pRootElement->LinkEndChild(pTokenElement);
  }
  pTokenElement->Clear();
  if (m_profile.store_auth_data_on_stb)
    pTokenElement->LinkEndChild(new TiXmlText(m_identity.token));

  if (!doc.SaveFile(strCacheFile)) {
    XBMC->Log(LOG_ERROR, "%s: failed to save \"%s\"", __FUNCTION__, strCacheFile.c_str());
    return false;
  }

  return true;
}
Example #5
0
void CRecentServerList::SetMostRecentServer(const CServer& server)
{
	CInterProcessMutex mutex(MUTEX_MOSTRECENTSERVERS);

	// Make sure list is initialized
	GetMostRecentServers(false);

	bool relocated = false;
	for (std::list<CServer>::iterator iter = m_mostRecentServers.begin(); iter != m_mostRecentServers.end(); iter++)
	{
		if (iter->EqualsNoPass(server))
		{
			m_mostRecentServers.erase(iter);
			m_mostRecentServers.push_front(server);
			relocated = true;
			break;
		}
	}
	if (!relocated)
	{
		m_mostRecentServers.push_front(server);
		if (m_mostRecentServers.size() > 10)
			m_mostRecentServers.pop_back();
	}

	TiXmlElement* pDocument = m_XmlFile.GetElement();
	if (!pDocument)
		return;
	
	TiXmlElement* pElement = pDocument->FirstChildElement("RecentServers");
	if (!pElement)
		pElement = pDocument->LinkEndChild(new TiXmlElement("RecentServers"))->ToElement();

	pElement->Clear();
	for (std::list<CServer>::const_iterator iter = m_mostRecentServers.begin(); iter != m_mostRecentServers.end(); iter++)
	{
		TiXmlElement* pServer = pElement->LinkEndChild(new TiXmlElement("Server"))->ToElement();
		SetServer(pServer, *iter);
	}

	wxString error;
	m_XmlFile.Save(&error);
}
void ProjectConfiguration::XmlWrite(TiXmlElement* Node,cbProject* Project)
{
    TiXmlElement* LibFinder = Node->FirstChildElement("lib_finder");
    if ( !LibFinder ) LibFinder = Node->InsertEndChild(TiXmlElement("lib_finder"))->ToElement();

    LibFinder->Clear();

    if ( m_DisableAuto )
    {
        LibFinder->SetAttribute("disable_auto","1");
    }

    for ( size_t i=0; i<m_GlobalUsedLibs.Count(); i++ )
    {
        LibFinder->InsertEndChild(TiXmlElement("lib"))->ToElement()->SetAttribute("name",cbU2C(m_GlobalUsedLibs[i]));
    }

    for ( wxMultiStringMap::iterator i=m_TargetsUsedLibs.begin();
            i!=m_TargetsUsedLibs.end();
            ++i )
    {
        if ( !Project->GetBuildTarget(i->first) ) continue;

        wxArrayString& Libs = i->second;
        if ( Libs.Count() )
        {
            TiXmlElement* TargetElem = LibFinder->InsertEndChild(TiXmlElement("target"))->ToElement();
            TargetElem->SetAttribute("name",cbU2C(i->first));
            for ( size_t i=0; i<Libs.Count(); i++ )
            {
                TargetElem->InsertEndChild(TiXmlElement("lib"))->ToElement()->SetAttribute("name",cbU2C(Libs[i]));
            }
        }
    }

    if ( !LibFinder->FirstAttribute() && !LibFinder->FirstChild() )
    {
        // LibFinder is empty, let's delete it so it doesn't trash here
        Node->RemoveChild(LibFinder);
    }
}