MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty(
	const MojObject& key, const MojObject& response, const MojObject& op,
	const MojObject& val, MatchMode mode) const
{
	if (key.type() == MojObject::TypeString) {
		MojString keyStr;
		MojErr err = key.stringValue(keyStr);
		if (err) {
			throw std::runtime_error("Failed to convert property lookup key "
				"to string");
		}

		MojObject propVal;
		bool found = response.get(keyStr.data(), propVal);
		if (!found) {
			return NoProperty;
		}

		return CheckMatch(propVal, op, val);

	} else if (key.type() == MojObject::TypeArray) {
		return CheckProperty(key, key.arrayBegin(), response, op, val, mode);
	} else {
		throw std::runtime_error("Key specified was neither a string or "
			"array of strings");
	}
}
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty(
	const MojObject& keyArray, MojObject::ConstArrayIterator keyIter,
	const MojObject& response, const MojObject& op, const MojObject& val,
	MatchMode mode) const
{
	MojObject onion = response;
	for (; keyIter != keyArray.arrayEnd(); ++keyIter) {
		if (onion.type() == MojObject::TypeArray) {
			return CheckProperty(keyArray, keyIter, onion, onion.arrayBegin(),
				op, val, mode);
		} else if (onion.type() == MojObject::TypeObject) {
			MojString keyStr;
			MojErr err = (*keyIter).stringValue(keyStr);
			if (err) {
				throw std::runtime_error("Failed to convert property lookup "
					"key to string");
			}

			MojObject next;
			if (!onion.get(keyStr.data(), next)) {
				return NoProperty;
			}

			onion = next;
		} else {
			return NoProperty;
		}
	}

	return CheckMatch(onion, op, val);

}
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty(
	const MojObject& keyArray, MojObject::ConstArrayIterator keyIter,
	const MojObject& responseArray, MojObject::ConstArrayIterator responseIter,
	const MojObject& op, const MojObject& val, MatchMode mode) const
{
	/* Yes, this will iterate into arrays of arrays of arrays */
	for (; responseIter != responseArray.arrayEnd(); ++responseIter) {
		MatchResult result = CheckProperty(keyArray, keyIter, *responseIter,
			op, val, mode);

		if (mode == AndMode) {
			if (result != Matched) {
				return NotMatched;
			}
		} else {
			if (result == Matched) {
				return Matched;
			}
		}
	}

	if (mode == AndMode) {
		return Matched;
	} else {
		return NotMatched;
	}
}
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckClause(
	const MojObject& clause, const MojObject& response, MatchMode mode) const
{
	LOG_AM_TRACE("Entering function %s", __FUNCTION__);

	if (clause.type() == MojObject::TypeArray) {
		return CheckClauses(clause, response, mode);
	} else if (clause.type() != MojObject::TypeObject) {
		throw std::runtime_error("Clauses must be either an object or array "
			"of objects");
	}

	LOG_AM_DEBUG("Checking clause '%s' against response '%s' (%s)",
		MojoObjectJson(clause).c_str(), MojoObjectJson(response).c_str(),
		(mode == AndMode) ? "and" : "or");

	if (clause.contains(_T("and"))) {
		MojObject andClause;
		clause.get(_T("and"), andClause);

		return CheckClause(andClause, response, AndMode);
	} else if (clause.contains(_T("or"))) {
		MojObject orClause;
		clause.get(_T("or"), orClause);

		return CheckClause(orClause, response, OrMode);
	}

	MojObject prop;
	bool found = clause.get(_T("prop"), prop);
	if (!found) {
		throw std::runtime_error("Clauses must contain \"and\", \"or\", "
			"or a comparison to make");
	}

	MojObject op;
	found = clause.get(_T("op"), op);
	if (!found) {
		throw std::runtime_error("Clauses must specify a comparison operation "
			"to perform");
	}

	MojObject val;
	found = clause.get(_T("val"), val);
	if (!found) {
		throw std::runtime_error("Clauses must specify a value to compare "
			"against");
	}

	MatchResult result = CheckProperty(prop, response, op, val, mode);

	LOG_AM_DEBUG("Where Trigger: Clause %s %s",
		MojoObjectJson(clause).c_str(), (result == Matched) ? "matched" :
	    "did not match");

	return result;
}
예제 #5
0
/****************将文件夹内文件计入数组***************************/
void FileCheck(char *dir,FileType ft)
{
    FRESULT result;
	FATFS fs;
	DIR DirInf;  
	FILINFO FileInf;
	uint32_t cnt = 0;
	u16 i;

#if _USE_LFN
    static char lfname[_MAX_LFN + 1];
    FileInf.lfname =&lfname[0];
    FileInf.lfsize = sizeof(lfname);
#endif

	/* 挂载文件系统 */
	result = f_mount(0, &fs);			/* Mount a logical drive */
	if (result != FR_OK)return ;
	
	/* 打开根文件夹 */
	result = f_opendir(&DirInf, dir); /* 如果不带参数,则从当前目录开始 */
	if (result != FR_OK)return	;

	
	/* 读取当前文件夹下的文件和目录 */
	for (cnt = 0,i=0;cnt<MAX_FILENUM ;cnt++) 
	{
		result = f_readdir(&DirInf,&FileInf); 		/* 读取目录项,索引会自动下移 */

		if (result != FR_OK || FileInf.fname[0] == 0)  	break;	//结束
		
		if (FileInf.fname[0] == '.') continue;					//隐藏文件

		if (FileInf.fattrib != AM_DIR)
		{
			if(FileInf.lfname[0] == 0)strcpy(FileInf.lfname,FileInf.fname);	//短文件名复制到长文件名,便于处理
			if(ft==CheckProperty(FileInf.lfname))			 //统计该类型文件,不是该类型,不计入
			{
				switch(ft)
				{
				case MP3:
					strcpy(musicFile[++i],FileInf.lfname);
					break;
				case BMP:
					strcpy(photoFile[++i],FileInf.lfname);
					break;
				case TXT:
					strcpy(bookFile[++i],FileInf.lfname);
					break;
				}
			}
		} 
	}
	switch(ft)
	{
	case MP3:
		musicFileNum=i;
		break;
	case BMP:
		photoFileNum=i;
		break;
	case TXT:
		bookFileNum=i;
		break;
	}

	/* 卸载文件系统 */
	f_mount(0, NULL);
}
예제 #6
0
//------------------------------------------------------------------------------
bool WxMainApp::OnInit()
{
	//get base dir
    wxString strDir;
	wxSplitPath(wxGetFullModuleName(), &strDir, NULL, NULL);
	m_strBaseDir = strDir.char_str(wxConvUTF8).data();
	m_strBaseDir += "\\";

	///////////////////////////////////////////////////////////////////////////////////////////////////
	//initialize guiex system
	try
	{
		CGUIFrameworkEditor::ms_pFramework = new CGUIFrameworkEditor( );
		CGUIFrameworkEditor::ms_pFramework->Initialize( CGUIIntSize(1024,768), "" );

		GSystem->SetDrawExtraInfo( false );
		GSystem->SetPlayingAs( false );
		GSystem->SetEditorMode( true );
	}
	catch (CGUIBaseException& rError)
	{
		wxMessageBox( Gui2wxString(rError.what()), _T("error") );

		if( CGUIFrameworkEditor::ms_pFramework )
		{
			CGUIFrameworkEditor::ms_pFramework->Release();
			delete CGUIFrameworkEditor::ms_pFramework;
			CGUIFrameworkEditor::ms_pFramework = NULL;
		}
	}

	//load scintilla dll
	m_hSciDll = LoadLibrary(_T("SciLexer.DLL"));
	if (m_hSciDll==NULL)
	{
		wxMessageBox(_T("The Scintilla DLL could not be loaded."),
			_T("Error loading Scintilla"), wxOK|wxCENTER|wxICON_ERROR,NULL);
		return false;
	}

	//load localization config file
	if( 0 != CPropertyConfigMgr::Instance()->ReadLocalizationConfig(GetBaseDir() + "../editorconfig/localization_config.xml"))
	{
		wxMessageBox(_T("failed to read config file localization_config.xml!"), _T("error"));
		return false;
	}

	//load base config file
	std::vector<wxFileName> vecBaseConfigFile;
	vecBaseConfigFile.push_back( Gui2wxString(GetBaseDir() + "../editorconfig/libguiex_editor_config.xml"));
	vecBaseConfigFile.push_back( Gui2wxString(GetBaseDir() + "../editorconfig/libguiex_editor_config_box2d.xml"));
	vecBaseConfigFile.push_back( Gui2wxString(GetBaseDir() + "../editorconfig/libguiex_editor_config_game.xml"));

	for( uint32 i=0; i<vecBaseConfigFile.size(); ++i )
	{
		if( 0 != CPropertyConfigMgr::Instance()->ReadPropertyConfig( vecBaseConfigFile[i].GetFullPath()))
		{
			wxMessageBox( wxString::Format( _T("failed to read property config file: %s"), vecBaseConfigFile[i].GetFullPath() ), _T("error"));
			return false;
		}
	}

	//load extend config file
	if( wxMessageBox( _T("Do you want to load extend widget config file?"), _T("Questing"), wxYES_NO | wxICON_QUESTION) == wxYES )
	{
		wxFileDialog aDlg(NULL, _T("Choose widget config files"), Gui2wxString(GetBaseDir() + "../editorconfig/"), wxEmptyString, _T("widget config files (*.xml)|*.xml"), wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST );
		if( wxID_OK == aDlg.ShowModal())
		{
			//try load
			wxArrayString arrayFiles;
			aDlg.GetPaths( arrayFiles );
			for( uint32 i=0; i<arrayFiles.size(); ++i )
			{
				if( std::find(vecBaseConfigFile.begin(), vecBaseConfigFile.end(), arrayFiles[i]) != vecBaseConfigFile.end() )
				{
					//base config file, ignore it
					continue;
				}

				if( 0 != CPropertyConfigMgr::Instance()->ReadPropertyConfig( arrayFiles[i]))
				{
					wxMessageBox( wxString::Format( _T("failed to read property config file: %s"), arrayFiles[i] ), _T("error"));
					return false;
				}
			}
		}
	}

	//check default property
	if( false == CheckProperty() )
	{
		wxMessageBox(_T("check default property!"), _T("error"));
		return false;
	}

	//create frame
	wxFrame* frame = new WxMainFrame(NULL,
		wxID_ANY,
		wxT("libguiex editor"),
		wxDefaultPosition,
		wxSize(1024, 768));
	SetTopWindow(frame);
	frame->Show();

	wxToolTip::Enable(true);
	wxToolTip::SetDelay(1000);

	return true;
}