void RheiaConfigurationManager::Delete() { if( m_root == NULL || m_doc == NULL ) return; RheiaConfigurationPattern * builder = RheiaConfigurationPattern::Get(); wxString group = RheiaC2U( (const char*) m_root->name ); xmlNode* docRoot = xmlDocGetRootElement(m_doc); xmlNode* child = docRoot->children; while( child != NULL ) { wxString cname = RheiaC2U( (const char*) child->name ); if( cname.IsSameAs( group ) ) { xmlReplaceNode( child , NULL ); return; } child = child->next; } wxCriticalSectionLocker(builder->m_criticalSection); RheiaConfigurationManagerMap::iterator it = builder->m_groups.find(group); if(it != builder->m_groups.end()) builder->m_groups.erase(it); delete this; }
void RheiaConfigurationManager::ReadPerspective( const wxString& path, wxAuiManager *LayoutManager, const wxString& pName ) { /* First get the node in which to write the plugin */ wxString key(path + wxT("/perspectives")); xmlNode* node; node = RheiaXmlManager::Get()->AssertPath(key,m_root); xmlNode* e = RheiaXmlManager::Get()->GetUniqElement( node , key ); xmlNode *child = e->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char*) child->name ); if ( ChildName.IsSameAs( ConfigManagerPaths::Perspective ) ) { wxString pname = RheiaC2U( (const char*) xmlGetProp( child , rxU2C(ConfigManagerPaths::LayoutAttributes::LayoutName) ) ) ; if ( pname.IsSameAs( pName ) ) { wxString perspective = LayoutManager->SavePerspective(); wxString path = wxT("/perspective_string"); perspective = RheiaXmlManager::Get()->Read( path , child, perspective ); LayoutManager->LoadPerspective( perspective ); return; } } child = child->next; } }
xmlNode* RheiaConfigurationManager::AddRootChildren( const wxString& path, const wxString& property, const wxString& propertyValue ) { xmlNode *ret; xmlNode* child = m_root->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char*) child->name ); if ( ChildName.IsSameAs( path ) ) { xmlAttr *prop = xmlHasProp( child , rxU2C( property ) ); if ( prop ) { wxString propVal = RheiaXmlManager::RheiaNodeGetContent( prop->children ); if ( propVal.IsSameAs( propertyValue) ) return child; } } child = child->next; } ret = xmlNewNode( NULL , rxU2C( path ) ); xmlNewProp( ret , rxU2C( property ), rxU2C( propertyValue ) ); ret = xmlAddChild( m_root , ret ); return ret; }
void RheiaConfigurationManager::Write(const wxString& path, const RheiaStringStringMap& as) { wxString key(path); xmlNode* node; node = RheiaXmlManager::Get()->AssertPath(key,m_root); xmlNode* e = RheiaXmlManager::Get()->GetUniqElement( node , key ); /* First check if the node exist */ xmlNode *child = e->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char *) child->name ); xmlNode* sub = child->next; if ( ChildName.IsSameAs( wxT("variable") ) ) { xmlReplaceNode( child , NULL ); child = NULL; } child = sub; } RheiaStringStringMap::const_iterator it = as.begin(); for( ; it != as.end() ; ++it ) { child = xmlNewNode( NULL , (const xmlChar*) "variable" ); xmlNewChild(child , NULL , (const xmlChar*) "name" , rxU2C(it->first) ); xmlNewChild(child , NULL , (const xmlChar*) "value" , rxU2C(it->second) ); xmlAddChild( e , child ); } }
bool RheiaPackageInstallInfo::DoWriteToNode( xmlNode* parent ) { xmlNode* child = parent->children; while( child != NULL ) { wxString cname = RheiaC2U( (const char*) child->name ); xmlNode* sub = child->next; if( cname.IsSameAs( wxT("Files") ) || cname.IsSameAs( wxT("Libs") ) ) { xmlReplaceNode(child,NULL); } child = sub; } if( m_files != NULL ) { child = xmlNewNode(NULL,(const xmlChar*) "Files" ); m_files->DoWriteToNode(child); xmlAddChild(parent,child); } if( m_libs != NULL ) { child = xmlNewNode(NULL,(const xmlChar*) "Libs" ); m_libs->DoWriteToNode(child); xmlAddChild(parent,child); } return true; }
bool RheiaPackageManagedFile::DoWriteToNode( xmlNode* parent ) { xmlNode* child = parent->children; while( child != NULL ) { wxString cname = RheiaC2U( (const char*) child->name ); xmlNode* sub = child->next; if( cname.IsSameAs( wxT("name") ) || cname.IsSameAs( wxT("path") ) || cname.IsSameAs( wxT("remove") ) ) { xmlReplaceNode(child , NULL); } child = sub; } wxString rem = (m_remove ? wxT("true") : wxT("false")); xmlNewChild( parent , NULL , (const xmlChar*) "name" , rxU2C(m_name) ); xmlNewChild( parent , NULL , (const xmlChar*) "path" , rxU2C(m_path) ); xmlNewChild( parent , NULL , (const xmlChar*) "type" , rxU2C(m_type) ); xmlNewChild( parent , NULL , (const xmlChar*) "remove" , rxU2C(rem) ); return true; }
bool RheiaPackageManagedFile::DoReadFromNode( xmlNode* parent ) { xmlNode* child = parent->children; m_name = wxEmptyString; m_path = wxEmptyString; m_type = wxEmptyString; m_remove = false; while( child != NULL ) { wxString cname = RheiaC2U( (const char*) child->name ); if( cname.IsSameAs( wxT("name") ) ) { xmlChar* content = xmlNodeGetContent(child); m_name = RheiaC2U((const char*) content); xmlFree(content); } else if( cname.IsSameAs( wxT("path") ) ) { xmlChar* content = xmlNodeGetContent(child); m_path = RheiaC2U((const char*) content); xmlFree(content); } else if( cname.IsSameAs( wxT("type") ) ) { xmlChar* content = xmlNodeGetContent(child); m_type = RheiaC2U((const char*) content); xmlFree(content); } else if( cname.IsSameAs( wxT("remove") ) ) { xmlChar* content = xmlNodeGetContent(child); m_remove = RheiaC2U((const char*) content).IsSameAs(wxT("true")); xmlFree(content); } child = child->next; } if( m_name.IsEmpty() || m_path.IsEmpty() || m_type.IsEmpty() ) return false; return true; }
void RheiaConfigurationManager::WritePerspective( const wxString& path, const wxString& pName, const wxString& pValue, bool overwrite_existing ) { /* First get the node in which to write the plugin */ wxString key(path + wxT("/perspectives")); xmlNode* node; node = RheiaXmlManager::Get()->AssertPath(key,m_root); xmlNode* e = RheiaXmlManager::Get()->GetUniqElement( node , key ); xmlNode *child = e->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char*) child->name ); if ( ChildName.IsSameAs( ConfigManagerPaths::Perspective ) ) { wxString pname = RheiaC2U( (const char*) xmlGetProp( child , rxU2C(ConfigManagerPaths::LayoutAttributes::LayoutName) ) ) ; if ( pname.IsSameAs( pName ) ) { if ( overwrite_existing ) { xmlReplaceNode( child , NULL ); break; } else return; } } child = child->next; } child = xmlNewNode( NULL , rxU2C(ConfigManagerPaths::Perspective ) ); xmlNewProp( child , rxU2C(ConfigManagerPaths::LayoutAttributes::LayoutName ) , rxU2C(pName )); xmlAddChild( e , child ); wxString perspective = pValue; key = wxT("/perspective_string"); RheiaXmlManager::Get()->Write( key , perspective , child ); }
void RheiaConfigurationManager::DoRead(const wxString& path, RheiaStringStringMap* as) { wxString key(path); xmlNode* node; node = RheiaXmlManager::Get()->AssertPath(key,m_root); xmlNode* e = RheiaXmlManager::Get()->GetUniqElement( node , key ); /* First check if the node exist */ xmlNode *child = e->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char *) child->name ); if ( ChildName.IsSameAs( wxT("variable") ) ) { xmlNode* sub = child->children; wxString vname; wxString value; while( sub != NULL ) { wxString subname = RheiaC2U( (const char*) sub->name ); if( subname.IsSameAs( wxT("name"))) { xmlChar* content = xmlNodeGetContent( sub ); vname = RheiaC2U( (const char*) content ); xmlFree( content ); } else if( subname.IsSameAs( wxT("value"))) { xmlChar* content = xmlNodeGetContent( sub ); value = RheiaC2U( (const char*) content ); xmlFree( content ); } sub = sub->next; } if( !vname.IsEmpty() && !value.IsEmpty()) (*as)[vname] = value; } child = child->next; } }
wxArrayString RheiaConfigurationManager::ListRootChildrens() { wxArrayString ret; xmlNode* child = m_root->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char*) child->name ); ret.Add( ChildName ); child = child->next; } return ret; }
bool RheiaPackageInstallInfo::DoReadFromNode( xmlNode* parent ) { xmlNode* child = parent->children; if( m_files != NULL ) delete m_files; if( m_libs != NULL ) delete m_libs; m_files = NULL; m_libs = NULL; while( child != NULL ) { wxString cname = RheiaC2U( (const char*) child->name ); if( cname.IsSameAs( wxT("Files") ) ) { m_files = new RheiaPackageFiles(); bool ret = m_files->DoReadFromNode(child); if( !ret ) return false; } else if( cname.IsSameAs( wxT("Libs") ) ) { m_libs = new RheiaPackageLibs(); bool ret = m_libs->DoReadFromNode(child); if( !ret ) return false; } child = child->next; } if( m_files == NULL || m_libs == NULL ) return false; return true; }
wxArrayString RheiaConfigurationManager::ListRootChildrenNames(const wxString& path, const wxString& property) { wxArrayString ret; xmlNode* child = m_root->children; while ( child != NULL ) { wxString ChildName = RheiaC2U( (const char*) child->name ); if ( ChildName.IsSameAs( path ) ) { xmlAttr *prop = xmlHasProp( child , rxU2C( property ) ); if ( prop ) { wxString propValue = RheiaXmlManager::RheiaNodeGetContent( prop->children ); ret.Add( propValue ); } } child = child->next; } return ret; }
void RheiaConfigurationManager::Write(const wxString& path, const char* str) { RheiaXmlManager::Get()->Write(path, RheiaC2U(str), m_root, false); };
RheiaPluginManifest* RheiaPluginManager::ReadManifestFile( const wxString& pluginFilename ) { RheiaLoggerManager::sdLog( wxT("RheiaPluginManager::Reading plugin manifest file : ") + pluginFilename + wxT(" ...") , RheiaLogging::info ); wxString pluginFname = pluginFilename; // first check if the plugin can be found if (pluginFname.IsEmpty()) { RheiaLoggerManager::sdLog( wxT("RheiaPluginManager::Plugin manifest file : ") + pluginFilename + wxT(" is empty...") , RheiaLogging::error ); return NULL; } wxFileName fname(pluginFilename); fname.SetExt(wxT("zip")); wxString actual = fname.GetFullName(); // remove dynamic library prefix from plugin name (if any) if ( !FileExt::DYNAMIC_LIBRARY_PREFIX.IsEmpty() && !platform::windows && actual.StartsWith(FileExt::DYNAMIC_LIBRARY_PREFIX)) actual.Remove(0, FileExt::DYNAMIC_LIBRARY_PREFIX.Length()); actual = RheiaFileFinder::FindFile( actual, rspfPluginsUser | rspfDataUser | rspfPluginsGlobal | rspfDataGlobal ); // check if the plugin resource exists if (actual.IsEmpty()) { RheiaLoggerManager::sdLog( wxT("RheiaPluginManager::Plugin manifest file : ") + pluginFilename + wxT(" not found...") , RheiaLogging::error ); return false; } // load XML from ZIP wxString contents; wxFileSystem* fs = new wxFileSystem; wxFSFile* f = fs->OpenFile(actual + _T("#zip:manifest.xml") ); if (f) { wxInputStream* is = f->GetStream(); char tmp[1024] = {}; while (!is->Eof() && is->CanRead()) { memset(tmp, 0, sizeof(tmp)); is->Read(tmp, sizeof(tmp) - 1); contents << RheiaC2U(tmp); } delete f; } else { RheiaLoggerManager::sdLog( wxT("RheiaPluginManager::Cannot extract plugin manifest file : ") + actual + wxT("#zip:manifest.xml...") , RheiaLogging::error ); delete fs; return false; } delete fs; xmlDoc* doc = xmlParseMemory( rcU2C(contents) , contents.size() ); if (!doc) { RheiaLoggerManager::sdLog( wxT("RheiaPluginManager::Cannot load xml document from memory : ") + actual + wxT("#zip:manifest.xml...") , RheiaLogging::error ); return NULL; } xmlNode* root = xmlDocGetRootElement( doc ); wxString rname = RheiaC2U( (const char*) root->name ); if( !rname.IsSameAs( wxT("RheiaPluginManifest") ) ) { RheiaLoggerManager::sdLog( wxT("RheiaPluginManager::Root node for xml document : ") + actual + wxT("#zip:manifest.xml is not RheiaPluginManifest...") + rname , RheiaLogging::error ); xmlFreeDoc( doc ); return NULL; } RheiaPluginManifest* manifest = new RheiaPluginManifest; xmlNode* child = root->children; while( child != NULL ) { wxString cname = RheiaC2U( (const char*) child->name ); if( cname.IsSameAs(wxT("Plugin")) ) { if( !manifest->DoReadFromNode(child) ) { RheiaLoggerManager::sdLog( wxT("RheiaPluginManager::Problem reading the xml document content from memory (manifest->DoReadFromNode(root) returns false) : ") + actual + wxT("#zip:manifest.xml is not RheiaPluginManifest...") , RheiaLogging::error ); delete manifest; xmlFreeDoc( doc ); return NULL; } break; } child = child->next; } xmlFreeDoc( doc ); return manifest; }