/** * @brief Converts one file. * * @param file the file's name * @param size the size of the file (in byte) */ void Converter::convertOneFile(const QString& file, qint64 size) { QString node("img_trans.pl"); log(file + " " + sizeToString(size)); QString script(findScript(node)); if (script.isEmpty()) error("Script nicht gefunden: " + node); else { QStringList args; args << script << m_args << file << m_targetDir.absolutePath(); m_script->start("/usr/bin/perl", args); QByteArray output; while (m_script->waitForReadyRead()){ output = m_script->readAll(); QList<QByteArray> lines = output.split('\n'); QList<QByteArray>::iterator it; for (it = lines.begin(); it != lines.end(); it++){ log(*it); } } output = m_script->readAllStandardError(); if (!output.isEmpty()) error(output); m_script->close(); } }
bool cLua::RunScript(const char *pFname) { std::string strFilename = findScript(pFname); const char *pFilename = strFilename.c_str(); if (0 != luaL_loadfile(m_pScriptContext, pFilename)) { if(m_pErrorHandler) { char buf[256]; sprintf(buf, "Lua Error - Script Load\nScript Name:%s\nError Message:%s\n", pFilename, luaL_checkstring(m_pScriptContext, -1)); m_pErrorHandler(buf); } return false; } if (0 != lua_pcall(m_pScriptContext, 0, LUA_MULTRET, 0)) { if(m_pErrorHandler) { char buf[256]; sprintf(buf, "Lua Error - Script Run\nScript Name:%s\nError Message:%s\n", pFilename, luaL_checkstring(m_pScriptContext, -1)); m_pErrorHandler(buf); } return false; } return true; }
bool Agent::queueScript(unsigned short event, AgentRef from, caosVar p0, caosVar p1) { // Queue a script for execution on the VM of this agent. if (dying) return false; // only bother firing the event if either it exists, or it's one with engine code attached // TODO: why don't we do the engine checks/etc here? switch (event) { default: if (!findScript(event)) return false; case 0: case 1: case 2: case 3: case 4: case 5: case 12: case 13: case 14: case 92: world.queueScript(event, this, from, p0, p1); } return true; }
bool Utils::loadJSForDebug(const QString& jsFilePath, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript) { QString scriptPath = findScript(jsFilePath, libraryPath); QString scriptBody = jsFromScriptFile(scriptPath, jsFileEnc); QFile wrapper(":/debug_wrapper.js"); if (!wrapper.open(QIODevice::ReadOnly)) return false; // We got big issues QString jsWrapper = QString::fromUtf8(wrapper.readAll()); jsWrapper = jsWrapper.arg(scriptBody); m_tempWrapper = new QTemporaryFile(QDir::tempPath() + "/debugwrapper_XXXXXX.js"); m_tempWrapper->open(); m_tempWrapper->write(jsWrapper.toUtf8()); m_tempWrapper->close(); QFile f(":/debug_harness.html"); if (!f.open(QIODevice::ReadOnly)) return false; QString html = QString::fromUtf8(f.readAll()); html = html.arg(m_tempWrapper->fileName()); m_tempHarness = new QTemporaryFile(QDir::tempPath() + "/debugharness_XXXXXX.html"); m_tempHarness->open(); m_tempHarness->write(html.toLocal8Bit()); m_tempHarness->close(); targetFrame->load(QUrl::fromLocalFile(m_tempHarness->fileName())); return true; }
bool Utils::loadJSForDebug(const QString& jsFilePath, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript) { // Don't do anything if an empty string is passed QFile jsFile(findScript(jsFilePath, libraryPath)); if (!jsFile.exists()) { if (startingScript) { Terminal::instance()->cerr(QString("Can't open '%1'").arg(jsFilePath)); } else { qWarning("Can't open '%s'", qPrintable(jsFilePath)); } return false; } QFile f( ":/debug_harness.html" ); if (!f.open( QIODevice::ReadOnly)) return false; // We got big issues QString html = QString::fromUtf8( f.readAll() ); const QFileInfo fileInfo(jsFile); html = html.arg(fileInfo.absoluteFilePath()); m_tempFile = new QTemporaryFile( QDir::tempPath() + QDir::separator() + "debugharness_XXXXXX.html" ); m_tempFile->open(); m_tempFile->write( html.toLocal8Bit() ); m_tempFile->close(); targetFrame->load( QUrl::fromLocalFile( m_tempFile->fileName() ) ); return true; }
boost::shared_ptr<Script> Server::getScript(Request *request) { std::pair<std::string, bool> name = findScript(request->getScriptFilename()); if (!name.second) { return boost::shared_ptr<Script>(); } return ScriptFactory::createScript(name.first); }
LEReferenceTo<LangSysTable> ScriptListTable::findLanguage(const LETableReference &base, LETag scriptTag, LETag languageTag, LEErrorCode &success, le_bool exactMatch) const { const LEReferenceTo<ScriptTable> scriptTable = findScript(base, scriptTag, success); if (scriptTable.isEmpty()) { return LEReferenceTo<LangSysTable>(); } return scriptTable->findLanguage(scriptTable, languageTag, success, exactMatch).reparent(base); }
const LangSysTable *ScriptListTable::findLanguage(LETag scriptTag, LETag languageTag, le_bool exactMatch) const { const ScriptTable *scriptTable = findScript(scriptTag); if (scriptTable == 0) { return NULL; } return scriptTable->findLanguage(languageTag, exactMatch); }
bool loadJSForDebug(const QString& jsFilePath, const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun) { QString scriptPath = findScript(jsFilePath, libraryPath); QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc); scriptBody = QString("function __run() {\n%1\n}").arg(scriptBody); targetFrame->evaluateJavaScript(scriptBody); if (autorun) { targetFrame->evaluateJavaScript("__run()", QString()); } return true; }
bool Utils::loadJSForDebug(const QString& jsFilePath, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun) { QString scriptPath = findScript(jsFilePath, libraryPath); QString scriptBody = jsFromScriptFile(scriptPath, jsFileEnc); QString remoteDebuggerHarnessSrc = Utils::readResourceFileUtf8(":/remote_debugger_harness.html"); remoteDebuggerHarnessSrc = remoteDebuggerHarnessSrc.arg(scriptBody); targetFrame->setHtml(remoteDebuggerHarnessSrc); if (autorun) { targetFrame->evaluateJavaScript("__run()", QString()); } return true; }
bool injectJsInFrame(const QString& jsFilePath, const QString& jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool startingScript) { // Don't do anything if an empty string is passed QString scriptPath = findScript(jsFilePath, libraryPath); QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc); if (scriptBody.isEmpty()) { if (startingScript) { Terminal::instance()->cerr(QString("Can't open '%1'").arg(jsFilePath)); } else { qWarning("Can't open '%s'", qPrintable(jsFilePath)); } return false; } // Execute JS code in the context of the document targetFrame->evaluateJavaScript(scriptBody, jsFilePath); return true; }
bool Utils::injectJsInFrame(const QString &jsFilePath, const Encoding &jsFileEnc, const QString &libraryPath, QWebFrame *targetFrame, const bool startingScript) { // Don't do anything if an empty string is passed QFile jsFile(findScript(jsFilePath, libraryPath)); if (jsFile.exists() && jsFile.open(QFile::ReadOnly)) { QString scriptBody = jsFileEnc.decode(jsFile.readAll()); // Remove CLI script heading if (scriptBody.startsWith("#!") && !jsFile.fileName().endsWith(COFFEE_SCRIPT_EXTENSION)) { scriptBody.prepend("//"); } if (jsFile.fileName().endsWith(COFFEE_SCRIPT_EXTENSION)) { QVariant result = Utils::coffee2js(scriptBody); if (result.toStringList().at(0) == "false") { if (startingScript) { Terminal::instance()->cerr(result.toStringList().at(1)); exit(1); } else { qWarning() << qPrintable(result.toStringList().at(1)); scriptBody = QString(); } } else { scriptBody = result.toStringList().at(1); } } // Execute JS code in the context of the document targetFrame->evaluateJavaScript(scriptBody); jsFile.close(); return true; } else { if (startingScript) { Terminal::instance()->cerr(QString("Can't open '%1'").arg(jsFilePath)); } else { qWarning("Can't open '%s'", qPrintable(jsFilePath)); } } return false; }
void Agent::finishInit() { // lc2e, at least, seems to position agents centered on (-9876,-9876) to begin with // TODO: where should we place agents in other games? is this code right at all anyway? // (bear in mind that there are no parts present for some C1/C2 agents when finishInit is called, atm) if (engine.version > 2 && !engine.bmprenderer) { // TODO: need to think about bmp-specific code some more x = -9876.0f + (getWidth() / 2.0f); y = -9876.0f + (getHeight() / 2.0f); } // shared_from_this() can only be used if these is at least one extant // shared_ptr which owns this world.agents.push_front(boost::shared_ptr<Agent>(this)); agents_iter = world.agents.begin(); if (engine.version > 2 && findScript(10)) queueScript(10); // constructor if (!voice && engine.version == 3) { setVoice("DefaultVoice"); } initialized = true; }
static os::String find_command(void) { return findScript("leaks.py"); }
static os::String find_command(void) { return findScript("snapdiff.py"); }
bool Agent::fireScript(unsigned short event, Agent *from, caosVar one, caosVar two) { // Start running the specified script on the VM of this agent, with FROM set to the provided agent. if (dying) return false; CreatureAgent *c = 0; if (event <= 3 || event == 4 || event == 12 || event == 13 || event == 14) c = dynamic_cast<CreatureAgent *>(from); switch (event) { case 0: // deactivate if (c && !cr_can_stop) return false; // TODO: not sure if this is the right place to do this. actv.setInt(event); break; case 1: // activate 1 if (c && !cr_can_push) return false; // TODO: not sure if this is the right place to do this. actv.setInt(event); break; case 2: // activate 2 if (c && !cr_can_pull) return false; // TODO: not sure if this is the right place to do this. actv.setInt(event); break; case 3: // hit if (c && !cr_can_hit) return false; break; case 4: // pickup if (c && !cr_can_pickup) return false; if (!from) return false; if (from == world.hand()) { if (!mouseable()) return false; } else if (!c) { // TODO: valid check for vehicles? if (!carryable()) return false; } from->addCarried(this); // TODO: correct behaviour? break; case 5: // drop if (!from) return false; // TODO: this check isn't very good for vehicles ;p // if (from != carriedby) return false; from->dropCarried(this); // TODO: correct? break; case 12: // eat if (c && !cr_can_eat) return false; break; case 13: // hold hands with pointer if (c) { // TODO } break; case 14: // stop holding hands with pointer if (c) { // TODO } break; case 92: // TODO: hack for 'UI Mouse Down' event - we need a real event system! std::cout << "faking event 92 on " << identify() << std::endl; CompoundPart *p = world.partAt(world.hand()->pointerX(), world.hand()->pointerY()); if (!p || p->getParent() != this) // if something is horridly broken here, return return false; // was caos_assert(p && p->getParent() == this); p->handleClick(world.hand()->pointerX() - p->x - p->getParent()->x, world.hand()->pointerY() - p->y - p->getParent()->y); // TODO: we're [obviously] missing firing the pointer script here, but it's a hack for now break; } bool ranscript = false; shared_ptr<script> s = findScript(event); if (s) { bool madevm = false; if (!vm) { madevm = true; vm = world.getVM(this); } if (vm->fireScript(s, event == 9, from)) { lastScript = event; zotstack(); vm->setVariables(one, two); // TODO: we should set _it_ in a more sensible way CreatureAgent *a = dynamic_cast<CreatureAgent *>(this); if (a) { Creature *c = a->getCreature(); assert(c); vm->_it_ = c->getAttentionFocus(); } vmTick(); ranscript = true; } else if (madevm) { world.freeVM(vm); vm = 0; } } switch (event) { case 5: if (invehicle) break; if (engine.version > 1) break; // Creatures 1 drop snapping // TODO: this probably doesn't belong here, but it has to be run after the // drop script starts (see for instance C1 carrots, which change pose) MetaRoom* m = world.map.metaRoomAt(x, y); if (!m) break; shared_ptr<Room> r = m->nextFloorFromPoint(x, y); if (!r) break; moveTo(x, r->bot.pointAtX(x).y - getHeight()); break; } return ranscript; }
void RunScript(const char *pFname) { std::string strFilename = findScript(pFname); cLua *lua = CGUIManager::GetInstance()->GetLuaContext(); lua->RunScript(strFilename.c_str()); }