QScriptValue Process::ctor(QScriptContext *context, QScriptEngine *engine) { Process *t; switch (context->argumentCount()) { case 0: t = new Process(context); break; default: return context->throwError(QLatin1String("Process()")); } ScriptEngine * const se = static_cast<ScriptEngine *>(engine); const DubiousContextList dubiousContexts ({ DubiousContext(EvalContext::PropertyEvaluation, DubiousContext::SuggestMoving) }); se->checkContext(QLatin1String("qbs.Process"), dubiousContexts); QScriptValue obj = engine->newQObject(t, QScriptEngine::ScriptOwnership); // Get environment QVariant v = engine->property("_qbs_procenv"); if (v.isNull()) { // The build environment is not initialized yet. // This can happen if one uses Process on the RHS of a binding like Group.name. t->m_environment = static_cast<ScriptEngine *>(engine)->environment(); } else { t->m_environment = QProcessEnvironment(*reinterpret_cast<QProcessEnvironment*>(v.value<void*>())); } return obj; }
QScriptValue File::js_makePath(QScriptContext *context, QScriptEngine *engine) { Q_UNUSED(engine); if (Q_UNLIKELY(context->argumentCount() < 1)) { return context->throwError(QScriptContext::SyntaxError, Tr::tr("makePath expects 1 argument")); } const auto se = static_cast<ScriptEngine *>(engine); const DubiousContextList dubiousContexts({ DubiousContext(EvalContext::PropertyEvaluation) }); se->checkContext(QLatin1String("File.makePath()"), dubiousContexts); return QDir::root().mkpath(context->argument(0).toString()); }
QScriptValue File::js_move(QScriptContext *context, QScriptEngine *engine) { Q_UNUSED(engine); if (Q_UNLIKELY(context->argumentCount() < 2)) { return context->throwError(QScriptContext::SyntaxError, Tr::tr("move expects 2 arguments")); } const auto se = static_cast<ScriptEngine *>(engine); const DubiousContextList dubiousContexts({ DubiousContext(EvalContext::PropertyEvaluation) }); se->checkContext(QLatin1String("File.move()"), dubiousContexts); const QString sourceFile = context->argument(0).toString(); const QString targetFile = context->argument(1).toString(); const bool overwrite = context->argumentCount() > 2 ? context->argument(2).toBool() : true; if (Q_UNLIKELY(QFileInfo(sourceFile).isDir())) return context->throwError(QString(QLatin1String("Could not move '%1' to '%2': " "Source file path is a directory.")) .arg(sourceFile, targetFile)); if (Q_UNLIKELY(QFileInfo(targetFile).isDir())) { return context->throwError(QString(QLatin1String("Could not move '%1' to '%2': " "Destination file path is a directory.")) .arg(sourceFile, targetFile)); } QFile f(targetFile); if (overwrite && f.exists() && !f.remove()) return context->throwError(QString(QLatin1String("Could not move '%1' to '%2': %3")) .arg(sourceFile, targetFile, f.errorString())); if (QFile::exists(targetFile)) return context->throwError(QString(QLatin1String("Could not move '%1' to '%2': " "Destination file exists.")) .arg(sourceFile, targetFile)); QFile f2(sourceFile); if (Q_UNLIKELY(!f2.rename(targetFile))) return context->throwError(QString(QLatin1String("Could not move '%1' to '%2': %3")) .arg(sourceFile, targetFile, f2.errorString())); return true; }
QScriptValue File::js_remove(QScriptContext *context, QScriptEngine *engine) { Q_UNUSED(engine); if (Q_UNLIKELY(context->argumentCount() < 1)) { return context->throwError(QScriptContext::SyntaxError, Tr::tr("remove expects 1 argument")); } const auto se = static_cast<ScriptEngine *>(engine); const DubiousContextList dubiousContexts({ DubiousContext(EvalContext::PropertyEvaluation) }); se->checkContext(QLatin1String("File.remove()"), dubiousContexts); QString fileName = context->argument(0).toString(); QString errorMessage; if (Q_UNLIKELY(!removeFileRecursion(QFileInfo(fileName), &errorMessage))) return context->throwError(errorMessage); return true; }
QScriptValue File::js_directoryEntries(QScriptContext *context, QScriptEngine *engine) { Q_UNUSED(engine); if (Q_UNLIKELY(context->argumentCount() < 2)) { return context->throwError(QScriptContext::SyntaxError, Tr::tr("directoryEntries expects 2 arguments")); } const auto se = static_cast<ScriptEngine *>(engine); const DubiousContextList dubiousContexts({ DubiousContext(EvalContext::PropertyEvaluation, DubiousContext::SuggestMoving) }); se->checkContext(QLatin1String("File.directoryEntries()"), dubiousContexts); const QString path = context->argument(0).toString(); const auto filters = static_cast<QDir::Filters>(context->argument(1).toUInt32()); QDir dir(path); const QStringList entries = dir.entryList(filters, QDir::Name); se->addDirectoryEntriesResult(path, filters, entries); return qScriptValueFromSequence(engine, entries); }