示例#1
0
static bool workingConfigInit(QString &init_working)
{
	if (init_working.size()) {
		if (-1 == nd_chdir(init_working.toStdString().c_str())) {
			return false;
		}
	}
	else {
		const char *pCurPath = nd_getcwd();
		if (ndstrstr(pCurPath, "editor")) {
			nd_chdir("..");
		}
	}


	if (!nd_existfile(__in_config)) {
		return false;
	}

	if (!apoEditorSetting::getInstant()->Init(__in_config, APO_QT_SRC_TEXT_ENCODE)) {
		return false;
	}

	return true;
}
示例#2
0
static bool initWorkingPath()
{
	if (__in_working_path && *__in_working_path) {
		char tmpbuf[ND_FILE_PATH_SIZE];
		
		if (!nd_absolute_filename(__in_working_path, tmpbuf, sizeof(tmpbuf))) {

			QMessageBox::critical(NULL, "Error", "Get wroking path error !");
			return false;
		}

		if (-1 == nd_chdir(tmpbuf)) {
			QMessageBox::critical(NULL, "Error", "Switch wroking path error !");
			return false;
		}

	}

	if (__in_config && *__in_config) {		
		if (!nd_existfile(__in_config)) {
			QMessageBox::critical(NULL, "Error", "can not found config file !");
			return false;
		}

		if (!apoEditorSetting::getInstant()->Init(__in_config, APO_QT_SRC_TEXT_ENCODE)) {
			QMessageBox::critical(NULL, "Error", "Set editor config error");
			return false;
		}
	}
	else {
		__in_config = "../cfg/config.xml"; //set default config file

		if (__in_working_path) {
			if (!apoEditorSetting::getInstant()->Init(__in_config, APO_QT_SRC_TEXT_ENCODE)) {
				QMessageBox::critical(NULL, "Error", "Set editor config error");
				return false;
			}
		}
		else {
			QString workingPath;
			while (!workingConfigInit(workingPath)) {
				if (trytoGetSetting(workingPath) && workingConfigInit(workingPath)) {
					break;
				}

				//GET working path
				if (!inputSetting(workingPath, NULL)) {
					exit(1);
				}
				QDir::setCurrent(workingPath);
			}
			return true;
		}

	}
	
	return true;
}
示例#3
0
bool startDialog::showScriptError(const char *scriptFile, const char *nodeDescript, const char *editorWorkingPath)
{
	nd_chdir(editorWorkingPath);

	EditorFrame *pMain = new EditorFrame();
	pMain->setHostWidget(this);
	pMain->setAttribute(Qt::WA_DeleteOnClose, true);
	
	if (pMain->myInit()) {
		this->setVisible(false);

		if (!pMain->showRuntimeError(scriptFile, nodeDescript)) {
			return false;
		}
		pMain->showMaximized();
	}
	else {
		delete pMain;
		return false;
	}
	return true;
}
示例#4
0
int runEditor(int argc,  char *argv[])
{
	QApplication a(argc, argv);
	//workingConfigInit();
	initWorkingPath() ;

	if (__in_proj_path) {
		nd_chdir(__in_proj_path);
	}
	//load dbl data
// 	const char *package_file = apoEditorSetting::getInstant()->getValueFromSetting("game_data_package_file");
// 	if (package_file) {
// 		DBLDatabase::get_Instant()->LoadBinStream(package_file);
// 	}

	EditorFrame mainFrame;
	if (!mainFrame.myInit()) {
		QMessageBox::critical(NULL, "Error", "init setting error!");
		exit(1);
	}
	mainFrame.showMaximized();
	return a.exec();

}
示例#5
0
int NDInstanceBase::Create(int argc,const char *argv[])
{
	int i ;
	const char *logfileName = NULL ;
	if (m_bCreated)	{
		return 0;
	}

    system_signals_init() ;
    
	nd_arg(argc, argv);	
	
	//get config file 	
	for (i=1; i<argc; i++){
		if(0 == strcmp(argv[i],"-f" ) && i< argc-1) {
			NDInstanceBase::config_file = argv[++i] ;
		}
		else if(0== strcmp(argv[i], "-c") && i< argc-1) {
			m_config_name = argv[++i] ;
		}
		else if(0==strcmp(argv[i],"-nodev")) {
			m_un_develop = 1;
		}
		
		else if(0==strcmp(argv[i],"-log") && i<argc -1) {
			logfileName = argv[++i];
		}
		else if(0==strcmp(argv[i],"-workdir") &&i<argc -1 ) {
			nd_chdir(argv[++i]) ;
		}
		else if(0==strcmp(argv[i],"-v") || 0==strcmp(argv[i],"--version") ) {
			fprintf(stdout, "version : %s \n" , __g_version_desc) ;
			exit(0) ;
		}
		else if(0==strcmp(argv[i],"-l") || 0==strcmp(argv[i],"--rlimit") ) {
			char buf[1024] ;
			fprintf(stdout, "rlimit: \n %s\n" , get_rlimit_info(buf, sizeof(buf)) ) ;
			exit(0) ;
		}

        else if(0==strcmp(argv[i],"-pid") && i<argc -1){
            FILE *pf = fopen(argv[i+1], "w") ;
            if (pf) {
                fprintf(pf, "%d", nd_processid()) ;
                fclose(pf) ;
            }
            else {
                fprintf(stderr,"write pid error %s file not exist\n", argv[i+1]) ;
                exit(1) ;
            }
        }
	}

	if(!config_file|| !m_config_name) {
		printf("usage: -f config-file -c config-name\n press ANY key to continue\n") ;
		//getch() ;
		exit(1) ;
		//return -1 ;
	}

	if(-1==ReadConfig(m_config_name) ) {
		printf("Read config %s file error \n press ANY key to continue\n", m_config_name) ;
		//getch() ;
		exit(1) ;
	}
	
	nd_set_exit_callback(applib_exit_callback) ;

	if (m_config.i_cfg.open_dump){
#ifndef ND_UNIX
		::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)nd_unhandler_except);
#else
		enable_core_dump() ;
#endif
	}
	size_t max_connector = m_config.l_cfg.max_connect ;
	if ( max_connector > get_maxopen_fd() ) {
		size_t new_fd_num = set_maxopen_fd(max_connector) ;
		nd_logmsg("set max connect %d real max connect =%d\n",m_config.l_cfg.max_connect, (int) new_fd_num);
	}
	
	if(logfileName && logfileName[0]) {
		strncpy(m_config.i_cfg.log_file, logfileName, sizeof(m_config.i_cfg.log_file)) ;
	}
	if (m_config.i_cfg.log_file[0]){
		set_log_file(m_config.i_cfg.log_file) ;
		if (m_config.i_cfg.log_file_size > 0) {
			nd_setlog_maxsize(m_config.i_cfg.log_file_size) ;
		}
		nd_setlog_func(nd_default_filelog) ;
	}

	if (m_config.i_cfg.callstack_file[0]){
		if(CALLSTACK_INIT(m_config.i_cfg.callstack_file)==-1) {
			nd_logfatal("create map file %s error!\n" AND m_config.i_cfg.callstack_file) ;
			return -1 ;
		}
	}

	nd_net_set_crypt((nd_netcrypt)nd_TEAencrypt, (nd_netcrypt)nd_TEAdecrypt, sizeof(tea_v)) ;
	
// 	if (g_base_inst==NULL){
// 		g_base_inst = this ;
// 	}

	OnCreate();

	m_bCreated = 1;
	return 0 ;

}
示例#6
0
bool startDialog::compileScript(const char *scriptFile, const char *editorWorkingPath)
{
	ndxml_root xmlScript;
	ndxml_initroot(&xmlScript);
	if (-1 == ndxml_load_ex(scriptFile, &xmlScript, apoEditorSetting::getInstant()->m_encodeName.c_str())) {
		return false;
	}
	const char*inFile = scriptFile;

	const char *outFile = getScriptSetting(&xmlScript, "out_file");
	if (!outFile){
		nd_logerror("compile %s error !!!\nMaybe file is destroyed\n", scriptFile);
		return false;
	}
	//get out file absolute path 
	std::string curPath = nd_getcwd();
	char outFilePath[ND_FILE_PATH_SIZE];

	if (!nd_getpath(scriptFile, outFilePath, sizeof(outFilePath))) {
		nd_logerror("get out file path error 1\n");
		return false;
	}
	if (-1 == nd_chdir(outFilePath)) {
		nd_logerror("get script file-path error 2\n");
		return false;
	}

	if (!nd_absolute_filename(outFile, outFilePath, sizeof(outFilePath))) {
		nd_logerror("get out file path error 3\n");
		nd_chdir(curPath.c_str());
		return false;
	}
	nd_chdir(curPath.c_str());
	outFile = outFilePath;
	// ---end get out file absolute path


	int outEncode = getScriptExpEncodeType(&xmlScript);
	bool withDebug = getScriptExpDebugInfo(&xmlScript);
	//std::string outPath = outFile;
	ndxml_destroy(&xmlScript);

	//outFile = outPath.c_str();

	int orderType = ND_L_ENDIAN;
	const char *orderName = apoEditorSetting::getInstant()->getValueFromSetting("bin_data_byte_order");
	if (orderName) {
		orderType = atoi(orderName);
	}

	LogicCompiler &lgcompile= *LogicCompiler::get_Instant();

	if (!lgcompile.compileXml(inFile, outFile, outEncode, withDebug, orderType)) {

		const char *pFunc = lgcompile.m_cur_function.c_str();
		const char *pStep = lgcompile.m_cur_step.c_str();
		char func_name[256];
		char step_name[256];
		if (outEncode == E_SRC_CODE_GBK) {
			pFunc = nd_gbk_to_utf8(pFunc, func_name, sizeof(func_name));
			pStep = nd_gbk_to_utf8(pStep, step_name, sizeof(step_name));
		}
		nd_logerror("compile error file %s, function %s, step %s , stepindex %d\n",
			lgcompile.m_cur_file.c_str(), pFunc, pStep, lgcompile.m_cur_node_index);

		return false;
	}

	nd_logmsg("!!!!!!!!!!COMPILE %s success !!!!!!!!!!!\n begining run script...\n", scriptFile);

	ClientMsgHandler::ApoConnectScriptOwner apoOwner;
	
	LogicEngineRoot *scriptRoot = LogicEngineRoot::get_Instant();
	nd_assert(scriptRoot);
	scriptRoot->setOutPutEncode(E_SRC_CODE_UTF_8);

	scriptRoot->setPrint(ND_LOG_WRAPPER_PRINT(startDialog), NULL);
	scriptRoot->getGlobalParser().setSimulate(true);
	//scriptRoot->getGlobalParser().setOwner(&apoOwner);

	if (0 != scriptRoot->LoadScript(outFile, &scriptRoot->getGlobalParser())){
		WriteLog("load script error n");
		LogicEngineRoot::destroy_Instant();
		return false;
	}

	WriteLog("start run script...\n");
	scriptRoot->setDftScriptModule(scriptRoot->getMainModuleName());
	if (0 != scriptRoot->test()){
		WriteLog("run script error\n");

		const char *curErrNode = scriptRoot->getGlobalParser().getLastErrorNode();
		if (curErrNode && *curErrNode) {
			showScriptError(scriptFile, curErrNode,editorWorkingPath);
		}

		LogicEngineRoot::destroy_Instant();
		return false;
	}

	LogicEngineRoot::destroy_Instant();
	nd_logmsg("!!!!!!!!!!!!!!!!!!!SCRIPT %s SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",scriptFile);
	return true;
}