Exemplo n.º 1
0
bool CAdvancedAnnotator::LoadXML( string strFileName )
{
	m_strXMLFileName = strFileName;
	string strName = m_strPathAbsolute+strFileName;
	LoadXmlDoc( strName );
	EnrollXmlRoot();
	m_pXMLSequence = EnrollXmlChild(m_pXMLRoot, "SequenceInfo");
	m_pXMLObjectType = EnrollXmlChild(m_pXMLRoot, "ObjectTypeInfo");
	m_pXMLFrameInfo = EnrollXmlChild(m_pXMLRoot, "FrameInfo");

	string strType = (m_eDBmode==DB_IMAGE ? "Image":"Video");
	m_pXMLSequence->SetAttribute("SeqType", strType.c_str());

	TiXmlElement* elemImgOrVid = EnrollXmlChild(m_pXMLSequence, strType);
	elemImgOrVid->SetAttribute("FileName", m_objDBSeq->GetFileName().c_str());
	elemImgOrVid->SetAttribute("TotalFrames", m_nTotalFrame);
	elemImgOrVid->SetAttribute("FrameWidth", m_sizeFrame.width);
	elemImgOrVid->SetAttribute("FrameHeight", m_sizeFrame.height);

	ReadOnceXmlObjectTypeInfo();

	ReadOnceXmlFrameInfo();

	GoToSpecificFrame(0);

	return true;
}
int LibraryDetectionManager::StoreNewSettingsFile( const wxString& shortcut, const std::vector< char >& content )
{
    // Try to parse file's content
    TiXmlDocument doc;
    if ( !doc.Parse( &content[0] ) ) return -1;

    // Ensure that this file contains required shortcut
    if ( !doc.RootElement() ) return -1;
    if ( !doc.RootElement()->Attribute("short_code") ) return -1;
    if ( strcmp( doc.RootElement()->Attribute("short_code"), cbU2C(shortcut) ) ) return -1;

    // Finally load new data - this will make sure that we have valid xml structure
    int AddedConfigs = LoadXmlDoc( doc );
    if ( !AddedConfigs ) return -1;

    // Search for not-yet existing file name
    int i=0;
    wxString BaseName = ConfigManager::GetFolder(sdDataUser) + wxFileName::GetPathSeparator() + _T("lib_finder") + wxFileName::GetPathSeparator();
    if ( !wxFileName::Mkdir( BaseName, 0777, wxPATH_MKDIR_FULL ) )
        return -2;

    wxString FileName = BaseName + shortcut + _T(".xml");
    while ( wxFileName::FileExists( FileName ) || wxFileName::DirExists( FileName ) )
        FileName = BaseName + shortcut + wxString::Format(_T("%d.xml"),i++);

    // Store data
    wxFile fl( FileName, wxFile::write_excl );
    if ( !fl.IsOpened() )
        return -2;

    const char* ptr = &content[0];
    size_t len = strlen(ptr);
    if ( fl.Write( ptr, len ) != len )
        return -2;

    return AddedConfigs;
}
int LibraryDetectionManager::LoadXmlFile(const wxString& Name)
{
    TiXmlDocument Doc;
    if ( !TinyXML::LoadDocument( Name, &Doc ) || Doc.Error() ) return 0;
    return LoadXmlDoc( Doc );
}