Ejemplo n.º 1
0
void ToolManager::unloadJSEngine(bool forced)
{
	m_ScriptLock.lock();

	time_t now = time(NULL);

	if (forced || (m_uiInstanceCount == 0 && now > m_tJSEngineExpireTime))
	{
		if (m_pFactory)
		{
			ScriptCoreSetupI* setup = (ScriptCoreSetupI*)m_pFactory(SCRIPT_CORE_SETUP);

			if (setup)
				setup->cleanUp();
		}

		m_pFactory = NULL;
		m_ScriptCore.unload();
		m_ScriptCore = SharedObjectLoader();

		m_uiInstanceCount = 0;
	}

	m_ScriptLock.unlock();
}
Ejemplo n.º 2
0
	bool loadDll()
	{
#ifndef DEBUG
	#ifdef WIN32
			char message[255] = {0};
			if (UTIL::WIN::validateCert(L".\\bin\\scriptcore.dll", message, 255) != ERROR_SUCCESS)
			{
				Warning(gcString("Cert validation failed on scriptcore.dll: {0}\n", message));
				return false;
			}
	#endif
#endif

#ifdef WIN32
	#ifdef DEBUG
			if (!m_ScriptCore.load("scriptcore-d.dll"))
				return false;
	#else
			if (!m_ScriptCore.load("scriptcore.dll"))
				return false;
	#endif
#else
		if (!m_ScriptCore.load("libscriptcore.so"))
			return false;
#endif

		m_pFactory = m_ScriptCore.getFunction<FactoryFn>("FactoryBuilderScriptCore");

		if (!m_pFactory)
		{
			unloadDll();
			return false;
		}

#ifndef IGNORE_DESURA_LOGGING
		RegLogFn regLog = m_ScriptCore.getFunction<RegLogFn>("RegDLLCB_SCRIPT");

		if (regLog)
			InitLogging(regLog);
		else
			Warning("Failed to setup logging for scriptcore\n");
#endif

		m_pSetup = (ScriptCoreSetupI*)m_pFactory(SCRIPT_CORE_SETUP);

		if (!m_pSetup)
		{
			unloadDll();
			return false;
		}

		m_pSetup->useInternalTaskRunner();

		return m_pSetup->addItemExtender(&m_Extender);
	}
Ejemplo n.º 3
0
  /** \brief Check wheter a token at a given position is an undefined variable. 

      \param a_Tok [out] If a variable tom_pParser->m_vStringBufken has been found it will be placed here.
	    \return true if a variable token has been found.
      \throw nothrow
  */
  bool ParserTokenReader::IsUndefVarTok(token_type &a_Tok)
  {
    string_type strTok;
    int iEnd( ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos) );
    if ( iEnd==m_iPos )
      return false;

    if (m_iSynFlags & noVAR)
    {
      // <ibg/> 20061021 added token string strTok instead of a_Tok.GetAsString() as the 
      //                 token identifier. 
      // related bug report:
      // http://sourceforge.net/tracker/index.php?func=detail&aid=1578779&group_id=137191&atid=737979
      Error(ecUNEXPECTED_VAR, m_iPos - (int)a_Tok.GetAsString().length(), strTok);
    }

    // If a factory is available implicitely create new variables
    if (m_pFactory)
    {
      value_type *fVar = m_pFactory(strTok.c_str(), m_pFactoryData);
      a_Tok.SetVar(fVar, strTok );

      // Do not use m_pParser->DefineVar( strTok, fVar );
      // in order to define the new variable, it will clear the
      // m_UsedVar array which will kill previousely defined variables
      // from the list
      // This is safe because the new variable can never override an existing one
      // because they are checked first!
      (*m_pVarDef)[strTok] = fVar;
      m_UsedVar[strTok] = fVar;  // Add variable to used-var-list
    }
    else
    {
      a_Tok.SetVar((value_type*)&m_fZero, strTok);
      m_UsedVar[strTok] = 0;  // Add variable to used-var-list
    }

    m_iPos = iEnd;

    // Call the variable factory in order to let it define a new parser variable
    m_iSynFlags = noVAL | noVAR | noFUN | noBO | noPOSTOP | noINFIXOP | noSTR;
    return true;
  }
Ejemplo n.º 4
0
bool ToolManager::loadJSEngine()
{
#ifdef WIN32
#ifdef DEBUG
	if (!m_ScriptCore.load("scriptcore-d.dll"))
		return false;
#else
	if (!m_ScriptCore.load("scriptcore.dll"))
		return false;
#endif
#else
	if (!m_ScriptCore.load("libscriptcore.so"))
		return false;
#endif

	m_pFactory = m_ScriptCore.getFunction<FactoryFn>("FactoryBuilderScriptCore");

	if (!m_pFactory)
		return false;

	RegLogFn regLog = m_ScriptCore.getFunction<RegLogFn>("RegDLLCB_SCRIPT");

	if (regLog)
		regLog(g_pLogCallback);
	else
#ifdef WIN32
		Warning("Failed to setup logging for scriptcore.dll\n");
#else
		Warning("Failed to setup logging for scriptcore.so\n");
#endif

	ScriptCoreSetupI* setup = (ScriptCoreSetupI*)m_pFactory(SCRIPT_CORE_SETUP);

	if (!setup)
		return false;

	m_tJSEngineExpireTime = time(NULL) + 60*15;
	setup->useInternalTaskRunner();

	return setup->addItemExtender(&g_ItemExtender);
}
Ejemplo n.º 5
0
    CourgetteI* newInstance()
    {
        bool loaded = false;

        m_ScriptLock.lock();

        if (m_uiInstanceCount == 0)
            loaded = loadDll();
        else
            loaded = true;

        bool didLoad = (loaded && m_pFactory);

        if (didLoad)
            m_uiInstanceCount++;
        m_ScriptLock.unlock();

        if (didLoad == false)
            throw gcException(ERR_LIBRARY_LOADFAILED, "Failed to load courgette");

        return (CourgetteI*)m_pFactory(COURGETTE);
    }
Ejemplo n.º 6
0
	ScriptCoreI* newInstance()
	{
		bool loaded = false;

		m_ScriptLock.lock();

		if (m_uiInstanceCount == 0)
			loaded = loadDll();
		else
			loaded = true;

		bool didLoad = (loaded && m_pFactory);

		if (didLoad)
			m_uiInstanceCount++;
		m_ScriptLock.unlock();

		if (didLoad == false)
			throw gcException(ERR_LIBRARY_LOADFAILED, "Failed to load script engine");

		return (ScriptCoreI*)m_pFactory(SCRIPT_CORE);
	}
Ejemplo n.º 7
0
void ToolManager::findJSTools(UserCore::Item::ItemInfo* item)
{
	bool validPath = false;

	for (size_t x=0; x<item->getBranchCount(); x++)
	{
		gcString path = item->getBranch(x)->getInstallScriptPath();

		if (UTIL::FS::isValidFile(path))
			validPath = true;
	}

	if (!validPath)
		return;

	m_ScriptLock.lock();
	
	if (!m_pFactory)
	{
		Warning("Failed to load scriptcore for find JS Tools\n");
		m_ScriptLock.unlock();
		return;
	}

	m_uiInstanceCount++;
	m_ScriptLock.unlock();

	for (size_t x=0; x<item->getBranchCount(); x++)
	{
		gcString path = item->getBranch(x)->getInstallScriptPath();

		if (!UTIL::FS::isValidFile(path))
			continue;

		ScriptCoreI* instance = (ScriptCoreI*)m_pFactory(SCRIPT_CORE);

		UserItem* userItem = new UserItem();
		userItem->m_pItem = item;
		userItem->m_pBranch = item->getBranch(x);
		userItem->m_pToolManager = this;

		try
		{
			instance->setItem(userItem);
			instance->executeScript(path.c_str());
			instance->executeString("ToolSetup();");
		}
		catch (gcException &e)
		{
			gcString errMsg(e.getErrMsg());

			if (errMsg.find("ToolSetup is not defined") == std::string::npos)
				Warning(gcString("Failed to execute toolsetup: {0}\n", e));
		}

		instance->destory();
	}

	m_ScriptLock.lock();
	m_uiInstanceCount--;
	m_ScriptLock.unlock();

	if (m_uiInstanceCount == 0)
		unloadJSEngine();
}