void Database::createDatabase() { qDebug() << "Creating new database:" << path(); try { if (not scriptPath().isEmpty()) runSqlScript(scriptPath()); } catch (ErrorOpeningDatabase *e) { throw new ErrorCreatingDatabase(e->path()); } catch (SqlQueryError *e) { qDebug() << e->what(); throw e; } }
KScriptAction::KScriptAction( const QString &scriptDesktopFile, QObject *interface, KActionCollection *ac ) : QObject(interface), KScriptClientInterface( ) { m_interface = 0L; m_action = 0L; m_isValid = false; m_refs = 0; // Read the desktop file if(KDesktopFile::isDesktopFile(scriptDesktopFile)) { KDesktopFile desktop(scriptDesktopFile, true); QFileInfo scriptPath(scriptDesktopFile); m_scriptFile = scriptPath.dirPath(true) + "/" + desktop.readEntry("X-KDE-ScriptName", ""); m_scriptName = desktop.readName(); m_scriptType = desktop.readType(); QString scriptTypeQuery = "([X-KDE-Script-Runner] == '" + m_scriptType + "')"; KTrader::OfferList offers = KTrader::self()->query( "KScriptRunner/KScriptRunner", scriptTypeQuery ); if ( !offers.isEmpty() ) { m_action = new KAction(m_scriptName, KShortcut(), this, SLOT(activate()), ac, "script"); m_isValid = true; m_timeout = new QTimer(this); QString icon = desktop.readIcon(); m_action->setStatusText(desktop.readComment()); if( !icon.isEmpty() ) m_action->setIcon(icon); m_action->setShortcutConfigurable(true); connect( m_timeout, SIGNAL(timeout()), SLOT(cleanup()) ); } } }
void ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID ) { tLog() << "JAVASCRIPT:" << QString( "%1:%2" ).arg( m_scriptPath ).arg( lineNumber ) << message << sourceID; #ifdef QT_DEBUG QFileInfo scriptPath( m_scriptPath ); JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Resolver Error: %1:%2 %3" ).arg( scriptPath.fileName() ).arg( lineNumber ).arg( message ) ) ); #endif }
bool CSquirrel::LoadScript(CString script) { CString scriptPath( "%s/%s", m_pResource->GetPath().Get(), script.Get()); if(SQ_FAILED(sqstd_dofile( m_pVM, scriptPath.Get(), SQFalse, SQTrue ))) { CLogFile::Printf("[%s] Failed to load file %s.", m_pResource->GetName().Get(), script.Get()); return false; } CLogFile::Printf("\t[%s] Loaded file %s.", m_pResource->GetName().Get(), script.Get()); return true; }
//----------------------------------------------------------------------------- /// Add collada materials to materials.cs void updateMaterialsScript(const DTShape::Path &path, bool copyTextures = false) { #if 0 #ifdef DAE2DTS_TOOL if (!ColladaUtils::getOptions().forceUpdateMaterials) return; #endif DTShape::Path scriptPath(path); scriptPath.setFileName("materials"); scriptPath.setExtension("cs"); // First see what materials we need to update PersistenceManager persistMgr; for ( U32 iMat = 0; iMat < AppMesh::appMaterials.size(); iMat++ ) { ColladaAppMaterial *mat = dynamic_cast<ColladaAppMaterial*>( AppMesh::appMaterials[iMat] ); if ( mat ) { Material *mappedMat; if ( Sim::findObject( MATMGR->getMapEntry( mat->getName() ), mappedMat ) ) { // Only update existing materials if forced to if ( ColladaUtils::getOptions().forceUpdateMaterials ) persistMgr.setDirty( mappedMat ); } else { // Create a new material definition persistMgr.setDirty( mat->createMaterial( scriptPath ), scriptPath.getFullPath() ); } } } if ( persistMgr.getDirtyList().empty() ) return; // If importing a sketchup file, the paths will point inside the KMZ so we need to cache them. if (copyTextures) { for (int iMat = 0; iMat < persistMgr.getDirtyList().size(); iMat++) { Material *mat = dynamic_cast<Material*>( persistMgr.getDirtyList()[iMat].getObject() ); copySketchupTexture(path, mat->mDiffuseMapFilename[0]); copySketchupTexture(path, mat->mNormalMapFilename[0]); copySketchupTexture(path, mat->mSpecularMapFilename[0]); } } persistMgr.saveDirty(); #endif }
void VEObj::clean() { int i; string path; for (i = 0; actionScripts[i]; i++) { path = scriptPath(actionScripts[i]); unlink(path.c_str()); } // clean config ::unlink(confPath().c_str()); }
bool CSquirrelVM::LoadScript(CString script) { CString scriptPath( "%s/%s", GetResource()->GetResourceDirectoryPath().Get(), script.Get()); if(!SharedUtility::Exists(script.Get()) && SQ_FAILED(sqstd_dofile( m_pVM, scriptPath.Get(), SQFalse, SQTrue ))) { CLogFile::Printf("[%s] Failed to load file %s.", GetResource()->GetName().Get(), script.Get()); return false; } CLogFile::Printf("\t[%s] Loaded file %s.", GetResource()->GetName().Get(), script.Get()); return true; }
void NodeInstanceManager::HostAlreadyRunningNodes() { QList<ProcessInfo> nodeProcesses = GetProcessInfoList("SELECT * FROM Win32_Process WHERE Name = 'node.exe'"); ProcessInfo pi; foreach( pi, nodeProcesses ) { // Get script name // We suppose the script is the last argument QString scriptName = pi.args.last(); // Check if we have everything needed if ( scriptName.isEmpty() || pi.workingDir.isEmpty() ) continue; QFileInfo scriptPath( QDir(pi.workingDir), scriptName ); if ( !scriptPath.exists() ) continue; // Check if the process matches any available slots bool hasSlot = false; for (int i = 0; i < mInstances.count(); ++i) { NodeInstance* nodeInstance = mInstances[i]; if ( QFileInfo(nodeInstance->GetScriptPath()).canonicalFilePath() == scriptPath.canonicalFilePath() ) { // TODO: Reuse slot hasSlot = true; nodeInstance->EnableExternalProcess( pi.pid ); break; } } if ( !hasSlot ) { // Create new slot NodeInstance* newInstance = CreateInstance(); newInstance->SetScriptPath( scriptPath.absoluteFilePath() ); newInstance->EnableExternalProcess( pi.pid ); // get port newInstance->SetPort( pi.env["PORT"].toInt() ); } }
bool CLuaVM::LoadScript(CString script) { (new CScriptClass<Foo>("Foo"))->AddMethod("abc", &Foo::abc).AddMethod("new", &Foo::abc).Register(this); CString scriptPath( "%s/%s", GetResource()->GetResourceDirectoryPath().Get(), script.Get()); if(!SharedUtility::Exists(script.Get()) && luaL_loadfile(m_pVM, scriptPath.Get()) != 0) { CLogFile::Printf("[%s] Failed to load file %s.", GetResource()->GetName().Get(), script.Get()); return false; } else { if (lua_pcall(m_pVM, 0, LUA_MULTRET, 0) == 0) { CLogFile::Printf("\t[%s] Loaded file %s.", GetResource()->GetName().Get(), script.Get()); return true; } else { std::string strRes = lua_tostring(m_pVM, -1); std::vector <std::string> vecSplit; vecSplit = split(strRes, ':'); if (vecSplit.size() >= 3) { std::string strFile = vecSplit[0]; int iLine = atoi(vecSplit[1].c_str()); std::string strMsg = vecSplit[2].substr(1); CLogFile::Printf("ERROR: %s:%d: %s", strFile.c_str(), iLine, strMsg.c_str()); } else { CLogFile::Printf(strRes.c_str()); } } } CLogFile::Printf("[%s] Failed to load file %s.", GetResource()->GetName().Get(), script.Get()); return false; }
void SSProfile::setBackend(const QString &a, bool relativePath) { backend = QDir::toNativeSeparators(a); #ifdef Q_OS_WIN if (type.compare("Shadowsocks-Python", Qt::CaseInsensitive) == 0) { QDir python(a); python.cdUp(); QString scriptPath(python.absolutePath() + QString("/Scripts/sslocal-script.py")); if (QFile::exists(scriptPath)) { backend = QDir::toNativeSeparators(scriptPath); } else { backend = QString(); } } #endif if (relativePath) { QDir workingDir; backend = workingDir.relativeFilePath(backend); } }
void start(Poco::OSP::BundleContext::Ptr pContext) { // We need to obtain the BundleLoader via the Application's OSPSubsystem. Poco::Util::Application& app = Poco::Util::Application::instance(); Poco::OSP::OSPSubsystem& ospSubsystem = app.getSubsystem<Poco::OSP::OSPSubsystem>(); Poco::OSP::BundleLoader& bundleLoader = ospSubsystem.bundleLoader(); Poco::Path sandboxPath(pContext->persistentDirectory(), SandboxRequestHandler::SANDBOX_BUNDLE + ".bndl"); Poco::File sandboxDir(sandboxPath.toString()); if (!sandboxDir.exists()) { pContext->logger().information("Creating sandbox bundle."); sandboxDir.createDirectories(); Poco::Path metaInfPath(sandboxPath, "META-INF"); Poco::File metaInfDir(metaInfPath.toString()); metaInfDir.createDirectory(); Poco::Path manifestPath(metaInfPath, "manifest.mf"); Poco::SharedPtr<std::istream> pManifestIStream = pContext->thisBundle()->getResource("sandbox/manifest.mf"); Poco::FileOutputStream manifestOStream(manifestPath.toString()); Poco::StreamCopier::copyStream(*pManifestIStream, manifestOStream); Poco::Path extensionsPath(sandboxPath, "extensions.xml"); Poco::SharedPtr<std::istream> pExtensionsIStream = pContext->thisBundle()->getResource("sandbox/extensions.xml"); Poco::FileOutputStream extensionsOStream(extensionsPath.toString()); Poco::StreamCopier::copyStream(*pExtensionsIStream, extensionsOStream); Poco::Path scriptPath(sandboxPath, SandboxRequestHandler::SANDBOX_SCRIPT); Poco::SharedPtr<std::istream> pScriptIStream = pContext->thisBundle()->getResource("sandbox/sandbox.js"); Poco::FileOutputStream scriptOStream(scriptPath.toString()); Poco::StreamCopier::copyStream(*pScriptIStream, scriptOStream); } pContext->logger().information("Loading sandbox bundle."); Poco::OSP::Bundle::Ptr pSandboxBundle = bundleLoader.loadBundle(sandboxPath.toString()); pSandboxBundle->resolve(); }
bool transferSysFiles( Options &options, bool bJustScript ) { Path binpath, libpath; // Under windows, the binary path is usually stored in an envvar. String envpath; if ( ! Sys::_getEnv( "FALCON_BIN_PATH", envpath ) || envpath == "" ) envpath = FALCON_DEFAULT_BIN; binpath.setFullLocation( options.m_sFalconBinDir != "" ? options.m_sFalconBinDir: envpath ); // copy falcon or falrun if ( options.m_sRunner != "" ) binpath.setFilename( options.m_sRunner ); else binpath.setFilename( "falcon.exe" ); // our dlls are in bin, under windows. libpath.setFullLocation( options.m_sFalconLibDir != "" ? options.m_sFalconLibDir : envpath ); if ( ! bJustScript ) { Path tgtpath( options.m_sTargetDir + "/" + options.m_sSystemRoot +"/" ); libpath.setFile( "falcon_engine" ); libpath.setExtension( DllLoader::dllExt() ); tgtpath.setFilename( binpath.getFilename() ); if( ! copyFile( binpath.get(), tgtpath.get() ) ) { warning( "Can't copy system file \"" + binpath.get() + "\" into target path \""+ tgtpath.get()+ "\"" ); // but continue } tgtpath.setFilename( libpath.getFilename() ); if( ! copyFile( libpath.get(), tgtpath.get() ) ) { warning( "Can't copy system file \"" + libpath.get() + "\" into target path \""+ tgtpath.get()+ "\"" ); // but continue } // and now the visual C runtime, if any copyRuntime( binpath, tgtpath ); } // now create the startup script Path mainScriptPath( options.m_sMainScript ); Path scriptPath( options.m_sTargetDir + "/" + mainScriptPath.getFile() + ".bat" ); message( "Creating startup script \"" + scriptPath.get() + "\"" ); FileStream startScript; if( ! startScript.create( scriptPath.get(), (BaseFileStream::t_attributes) 0777 ) ) { error( "Can't create startup script \"" + scriptPath.get() + "\"" ); return false; } startScript.writeString( "@ECHO OFF\r\n" "set OLD_DIR=%CD%\r\n" "set target_dir=%~dp0\r\n" "cd %target_dir%\r\n"); if( bJustScript ) { startScript.writeString( "\"" + binpath.getFilename() + "\" " ); } else { startScript.writeString( " \""+options.m_sSystemRoot + "\\" + binpath.getFilename() + "\" " ); startScript.writeString( " -L \"" + options.m_sSystemRoot +";.\" " ); } // we need to discard the extension, so that the runner decides how to run the program. Path scriptName( options.m_sMainScript ); startScript.writeString( " \"" + scriptName.getFile() +"\" \"%*\"\r\n" ); startScript.writeString( "cd %OLD_DIR%\r\n" ); startScript.flush(); return true; }
static int falcon_handler(request_rec *request) { Falcon::String path; bool phand = false; bool force_ftd = false; // should we handle this as a special path? if ( strcmp( request->handler, FALCON_PROGRAM_HANDLER) == 0 ) { phand = true; } else if ( strcmp( request->handler, FALCON_PROGRAM_FTD) == 0 ) { phand = true; force_ftd = true; } else if ( strcmp(request->handler, FALCON_FAM_TYPE) != 0 && strcmp(request->handler, FALCON_FAL_TYPE) != 0 && strcmp(request->handler, FALCON_FTD_TYPE) != 0) { return DECLINED; } // first time in this process? if( s_core == 0 ) { module_startup(); } Falcon::numeric startedAt = Falcon::Sys::Time::seconds(); // verify that the file exists; decline otherwise const char *script_name = 0; const char *load_path = 0; falcon_dir_config* dircfg = (falcon_dir_config*)ap_get_module_config(request->per_dir_config, &falcon_module ) ; if ( phand ) { // do we have a request configuration? if( dircfg->falconHandler[0] != '\0' ) { script_name = dircfg->falconHandler; } else if( the_falcon_config->loaded != -1 ) { script_name = the_falcon_config->falconHandler; } // else, go to the next the_falcon_config->loaded != -1 check } else { script_name = request->filename; Falcon::FileStat::e_fileType st; if ( ! Falcon::Sys::fal_fileType( script_name, st ) ) { // sorry, the file do not exists, or we cannot access it. return DECLINED; } } // we accepted. but are we working? if( the_falcon_config->loaded == -1 ) { falcon_mod_write_errorstring( request, "<HTML>\n<BODY>\n<H1>FALCON module error</H1>\n" "<p>Couldn't load Falcon configuration file. See the error log of this server " "for further details.</p>\n" "</BODY>\n" "</HTML>\n" ); return OK; } // Set the load path if( dircfg->loadPath[0] != '\0' ) { load_path = dircfg->loadPath; } else if( the_falcon_config->loaded != -1 ) { load_path = the_falcon_config->loadPath; } // prepare the session manager for this process. if ( s_session == 0 ) { if ( the_falcon_config->sessionMode == FM_DEFAULT_SESSION_MODE ) { s_session = new Falcon::WOPI::FileSessionManager( the_falcon_config->uploadDir ); } else { s_session = new Falcon::WOPI::MemSessionManager; } s_session->timeout( the_falcon_config->sessionTimeout ); s_session->startup(); } // we need some random data // for sure, the request address is unique within a time constraint. s_entropy += (((long)(startedAt * 1000))%0xFFFFFFFF + ((long) request)); srand( s_entropy ); //it's a Falcon module. ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, request, "Accepting a request from falcon %s", request->filename ); // first of all, we need a module loader to load the script. // The parameter is the search path for where to search our module Falcon::ModuleLoader theLoader; // As we want to use standard Falcon installation, // tell the loader that is safe to search module in system path if( load_path != 0 && load_path[0] != '\0' ) { theLoader.setSearchPath( load_path ); } else { theLoader.setSearchPath( "" ); theLoader.addFalconPath(); } // also, instruct the module loader to take the script path as added search path Falcon::Path scriptPath( request->canonical_filename ); if ( scriptPath.isValid() ) { Falcon::String spath; scriptPath.getLocation( spath ); theLoader.addDirectoryFront( spath ); } // broadcast the same path to the application. Falcon::Engine::setSearchPath( theLoader.getSearchPath() ); path = theLoader.getSearchPath(); // for now, let's say we're utf-8 theLoader.sourceEncoding( "utf-8" ); Falcon::Engine::setEncodings( "utf-8", "utf-8" ); if( force_ftd ) theLoader.compileTemplate( true ); // Now we need our error handler to manage possible problems in the next steps. // First, create the output brigade we'll need to deal with output. ApacheOutput aoutput( request ); // then create an error handler that may use this output structure. ApacheErrorHandler errhand( the_falcon_config->errorMode, &aoutput ); // Allow the script to load iteratively other resources it may need. ApacheRequest* ar = 0; Falcon::uint32 nSessionToken = 0; // We are ready to go. Let's create our VM and link in minimal stuff // we'll handle errors here ApacheVMachine* vm = new ApacheVMachine(); // perform link of standard modules. vm->link( s_core ); // add the core module vm->link( s_ext ); // prepare the request class. Falcon::Item* i_req = vm->findGlobalItem( "Request" ); fassert( i_req != 0 ); Falcon::Item* i_upld = vm->findGlobalItem( "Uploaded" ); fassert( i_upld != 0 ); Falcon::Item* i_reply = vm->findGlobalItem( "Reply" ); fassert( i_reply != 0 ); Falcon::Item* i_wopi = vm->findGlobalItem( "Wopi" ); fassert( i_wopi != 0 ); // Configure the Apache Request ar = Falcon::dyncast<ApacheRequest*>( i_req->asObject() ); // And the reply here ApacheReply* reply = Falcon::dyncast<ApacheReply*>( i_reply->asObject() ); reply->init( request, &aoutput ); // init and configure ar->init( request, i_upld->asClass(), reply, s_session ); ar->base()->startedAt( startedAt ); // record the session token for automatic close at end. nSessionToken = ar->base()->sessionToken(); vm->stdOut( new Falcon::WOPI::ReplyStream( reply ) ); vm->stdErr( new Falcon::WOPI::ReplyStream( reply ) ); // sets the options ar->base()->setMaxMemUpload( the_falcon_config->maxMemUpload ); if( the_falcon_config->uploadDir[0] != 0 ) ar->base()->setUploadPath( the_falcon_config->uploadDir ); ar->configFromModule( vm->mainModule()->module() ); // configure the WOPI persistent object if ( the_falcon_config->pdataDir[0] != 0 ) Falcon::dyncast<Falcon::WOPI::CoreWopi*>(i_wopi->asObject())->wopi()->dataLocation( the_falcon_config->pdataDir ); Falcon::dyncast<Falcon::WOPI::CoreWopi*>(i_wopi->asObject())->configFromModule( vm->mainModule()->module() ); // ok start processing of the input request. ar->process(); // ok; now prepare the scriptName and scriptPath variables, and set the current working directory // so that the script is ready. if ( scriptPath.isValid() ) { Falcon::CoreString *spath = new Falcon::CoreString; Falcon::CoreString *sfile = new Falcon::CoreString; scriptPath.getLocation( *spath ); scriptPath.getFilename( *sfile ); Falcon::Item *i_scriptPath = vm->findGlobalItem( "scriptPath" ); fassert( i_scriptPath != 0 ); *i_scriptPath = spath; Falcon::Item *i_scriptName = vm->findGlobalItem( "scriptName" ); fassert( i_scriptName != 0 ); *i_scriptName = sfile; int fs; Falcon::Sys::fal_chdir( *spath, fs ); } FALCON_WATCHDOG_TOKEN* wdt = 0; try { Falcon::Runtime rt( &theLoader ); rt.loadFile( script_name ); // tell the watchdog we're going to if( the_falcon_config->runTimeout > 0 ) { // approximate good size. int cbloops = the_falcon_config->runTimeout * 1000; vm->callbackLoops( cbloops > 10000 ? 10000 : cbloops ); wdt = watchdog_push_vm( request, vm, the_falcon_config->runTimeout, reply ); } // try to link our module and its dependencies. // -- It may fail if there are some undefined symbols vm->link( &rt ); vm->launch(); // close our stream aoutput.close(); } catch( Falcon::Error* error ) { reply->commit(); errhand.handleError( error ); aoutput.close(); } if ( wdt != 0 ) { watchdog_vm_is_done( wdt ); } // release all our sessions s_session->releaseSessions( nSessionToken ); if( vm != 0 ) { void *temp_files = ar->base()->getTempFiles(); vm->finalize(); Falcon::memPool->start(); //Falcon::memPool->performGC(); if ( temp_files != 0 ) Falcon::WOPI::Request::removeTempFiles( temp_files, request, ap_log_error_cb ); } return OK; }