void sfFindUserByName(strList *params) { l_slot slot; if (evaluateBool(params->next->string)) { #ifdef WINCIT slot = FindPersonByPartialName(evaluateString(params->string), pCurScript->TW ? pCurScript->TW->LogOrder : NULL); #else slot = FindPersonByPartialName(evaluateString(params->string)); #endif } else { #ifdef WINCIT slot = FindPersonByName(evaluateString(params->string), pCurScript->TW ? pCurScript->TW->LogOrder : NULL); #else slot = FindPersonByName(evaluateString(params->string)); #endif } SETINT(slot); }
void WriteTextFileInstance::startExecution() { bool ok = true; QString filepath = evaluateString(ok, "file"); QString text = evaluateString(ok, "text"); Mode mode = evaluateListElement<Mode>(ok, modes, "mode"); if(!ok) return; QFile file(filepath); if(!file.open(QIODevice::WriteOnly | QIODevice::Text | (mode == Truncate ? QIODevice::Truncate : QIODevice::Append))) { setCurrentParameter("file"); emit executionException(CannotWriteFileException, tr("Cannot open file")); return; } QTextStream textStream(&file); textStream << text; file.close(); emit executionEnded(); }
void WriteRegistryInstance::startExecution() { #ifdef Q_OS_WIN bool ok = true; ActionTools::Registry::Key key = evaluateListElement<ActionTools::Registry::Key>(ok, ReadRegistryInstance::keys, "key"); QString subKey = evaluateString(ok, "subKey"); QString value = evaluateString(ok, "value"); QScriptValue data = evaluateValue(ok, "data"); if(!ok) return; switch(ActionTools::Registry::write(data.toVariant(), key, subKey, value)) { case ActionTools::Registry::WriteCannotFindSubKey: setCurrentParameter("subKey"); emit executionException(CannotFindSubKeyException, tr("Cannot find subKey \"%1\"").arg(subKey)); return; case ActionTools::Registry::WriteCannotWriteValue: setCurrentParameter("value"); emit executionException(CannotWriteValueException, tr("Cannot write value \"%1\"").arg(value)); return; default: break; } #endif emit executionEnded(); }
void sfFindHallByName(strList *params) { if (params->next && evaluateBool(params->next->string)) { #ifndef WINCIT SETINT(partialhall(evaluateString(params->string))); #endif } else { SETINT(hallexists(evaluateString(params->string))); } }
void TextInstance::startExecution() { bool ok = true; mText = evaluateString(ok, "text"); int pause = evaluateInteger(ok, "pause"); if(pause < 0) pause = 0; mTimer->setInterval(pause); mCurrentCharacter = 0; if(!ok) return; if(pause == 0) { if(!mKeyboardDevice.writeText(mText)) { emit executionException(FailedToSendInputException, tr("Unable to write the text")); return; } QTimer::singleShot(1, this, SIGNAL(executionEnded())); } else { pressNextKey(); mTimer->start(); } }
void WebDownloadInstance::startExecution() { bool ok = true; QString urlString = evaluateString(ok, "url"); mDestination = evaluateListElement<Destination>(ok, destinations, "destination"); mVariable = evaluateVariable(ok, "variable"); QString file = evaluateString(ok, "file"); if(!ok) return; QUrl url(urlString); if(url.scheme() == QString()) url = QUrl("http://" + urlString, QUrl::TolerantMode); if(!url.isValid()) { setCurrentParameter("url"); emit executionException(ActionTools::ActionException::BadParameterException, tr("Invalid URL")); return; } if(mDestination == File) { mFile.setFileName(file); if(!mFile.open(QIODevice::WriteOnly)) { setCurrentParameter("file"); emit executionException(CannotOpenFileException, tr("Cannot write to file")); return; } } mReply = mNetworkAccessManager->get(QNetworkRequest(url)); connect(mReply, SIGNAL(finished()), this, SLOT(finished())); connect(mReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); connect(mReply, SIGNAL(readyRead()), this, SLOT(readyRead())); mProgressDialog->setModal(false); mProgressDialog->setWindowTitle(tr("Downloading")); mProgressDialog->setLabelText(tr("Downloading...")); mProgressDialog->setMaximum(100); mProgressDialog->show(); }
core::Error evaluateString(const std::string& str, T* pValue) { sexp::Protect rProtect; SEXP valueSEXP ; core::Error error = evaluateString(str, &valueSEXP, &rProtect); if (error) return error ; return sexp::extract(valueSEXP, pValue); }
IfActionValue ActionInstance::evaluateIfAction(bool &ok, const QString ¶meterName) { QString action = evaluateString(ok, parameterName, QStringLiteral("action")); if(!ok) return IfActionValue(); return IfActionValue(action, subParameter(parameterName, QStringLiteral("line"))); }
bool ActionInstance::evaluateBoolean(bool &ok, const QString ¶meterName, const QString &subParameterName) { QVariant result = evaluateString(ok, parameterName, subParameterName); if(!ok) return false; return result.toBool(); }
// ------------------------------------------------------------------------- void ScriptEngine::evaluateFile( QString sScriptFile ) { // Extract the arguments from the script call. QString sFilePath(CommonDefinitions::sScriptDir.c_str()); QFile file(sFilePath + "/" + sScriptFile); if (!file.open(QIODevice::ReadOnly)) { cerr << "Error: Could not open " << qPrintable(sScriptFile) << " for reading!" << endl; } QTextStream ts(&file); QString sContents = ts.readAll(); file.close(); evaluateString( sContents ); }
void PlaySoundInstance::startExecution() { bool ok = true; QString file = evaluateString(ok, "file"); int volume = evaluateInteger(ok, "volume"); mBlocking = evaluateBoolean(ok, "blocking"); bool looping = evaluateBoolean(ok, "looping"); bool isUrl = evaluateBoolean(ok, "url"); int playbackRate = evaluateInteger(ok, "playbackRate"); if(!ok) return; mMediaPlaylist->clear(); QUrl url; if(isUrl) url = QUrl(file); else url = QUrl::fromLocalFile(file); if(!mMediaPlaylist->addMedia(url)) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to load file %1: %2").arg(file).arg(mMediaPlayer->errorString())); return; } mMediaPlaylist->setPlaybackMode(looping ? QMediaPlaylist::Loop : QMediaPlaylist::CurrentItemOnce); mMediaPlayer->setPlaybackRate(playbackRate / 100.0f); mMediaPlayer->setVolume(volume); mMediaPlayer->play(); if(mMediaPlayer->error() != QMediaPlayer::NoError) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to play file %1: %2").arg(file).arg(mMediaPlayer->errorString())); return; } if(!mBlocking) emit executionEnded(); }
QString ActionInstance::evaluateVariable(bool &ok, const QString ¶meterName, const QString &subParameterName) { QString result = evaluateString(ok, parameterName, subParameterName); if(!ok) return QString(); if(!result.isEmpty() && !NameRegExp.exactMatch(result)) { ok = false; emit executionException(ActionException::InvalidParameterException, tr("A variable name can only contain alphanumeric characters and cannot start with a digit.")); return QString(); } return result; }
double ActionInstance::evaluateDouble(bool &ok, const QString ¶meterName, const QString &subParameterName) { QString result = evaluateString(ok, parameterName, subParameterName); if(!ok || result.isEmpty()) return 0.0; double doubleResult = result.toDouble(&ok); if(!ok) { ok = false; emit executionException(ActionException::InvalidParameterException, tr("Decimal value expected.")); return 0.0; } return doubleResult; }
int ActionInstance::evaluateInteger(bool &ok, const QString ¶meterName, const QString &subParameterName) { QString result = evaluateString(ok, parameterName, subParameterName); if(!ok || result.isEmpty()) return 0; int intResult = result.toInt(&ok); if(!ok) { ok = false; emit executionException(ActionException::InvalidParameterException, tr("Integer value expected.")); return 0; } return intResult; }
void VerbatimXmlComponent::renderBegin() const { auto context = getContext(); auto attribs = getRenderAttributes(context); /*we ALWAYS use the provided id for plain xml tags, regardless of naming *containers etc. this means plain html will always work as expected - and *no plain html component needs its id for anything other than css!*/ auto& id = attribs["id"]; auto sepPos = id.find_last_of(Component::NAMING_SEPARATOR); if (sepPos != id.npos) { id = id.substr(sepPos + 1); } //the root element needs to declare the xhtml namespace if (getTagName() == "html" && attribs.find("xmlns") == attribs.end()) { attribs["xmlns"] = "http://www.w3.org/1999/xhtml"; } getWriter() <<"<" <<impl->getOriginalTag() <<Util::toString(attribs) <<">" <<context->evaluateString(getTextValue()); }
void FindImageInstance::startSearching() { mOpenCVAlgorithms->cancelSearch(); mImagesToSearchIn.clear(); switch(mSource) { case ScreenshotSource: mImagesToSearchIn = ActionTools::ScreenShooter::captureScreens(); break; case WindowSource: { bool ok = true; QString windowName = evaluateString(ok, QStringLiteral("windowName")); if(!ok) return; mWindows = ActionTools::WindowHandle::findWindows(QRegExp(windowName, Qt::CaseSensitive, QRegExp::WildcardUnix)); if(mWindows.isEmpty()) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to find any window named %1").arg(windowName)); return; } mImagesToSearchIn = ActionTools::ScreenShooter::captureWindows(mWindows); } break; case ImageSource: { bool ok = true; QImage imageToSearchIn = evaluateImage(ok, QStringLiteral("imageToSearchIn")); if(!ok) return; if(imageToSearchIn.isNull()) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Invalid image to search in")); return; } mImagesToSearchIn.append(std::make_pair(QPixmap::fromImage(imageToSearchIn), imageToSearchIn.rect())); } break; } QList<QImage> sourceImages; sourceImages.reserve(mImagesToSearchIn.size()); for(const auto &imageToSearchIn: mImagesToSearchIn) sourceImages.append(imageToSearchIn.first.toImage()); if(!mOpenCVAlgorithms->findSubImageAsync(sourceImages, mImageToFind, mConfidenceMinimum, mMaximumMatches, mDownPyramidCount, mSearchExpansion, static_cast<ActionTools::OpenCVAlgorithms::AlgorithmMethod>(mMethod))) { emit executionException(ErrorWhileSearchingException, tr("Error while searching: %1").arg(mOpenCVAlgorithms->errorString())); return; } }
addressType evaluateExpression(void) { if (pc == NULL) return(0); switch (*pc++) { case IDENTIFIER_TAG: return(evaluateSymbol()); case FUNCTION_CALL_TAG: return(evaluateFunctionCall()); case BUILTIN_FUNCTION_CALL_TAG: return(evaluateBuiltinFunctionCall()); case NUMBER_TAG: return(evaluateNumber()); case RELOCATABLE_TAG: return(evaluateRelocatableNumber()); case CONDITION_CODE_TAG: return(evaluateConditionCode()); case SUBEXPRESSION_TAG: return(evaluateExpression()); case UNOP_TAG: return(evaluateUnop()); case BINOP_TAG: return(evaluateBinop()); case PREOP_TAG: return(evaluatePreop()); case POSTOP_TAG: return(evaluatePostop()); case HERE_TAG: return(evaluateHere()); case STRING_TAG: return(evaluateString()); case ARRAY_TAG: return(evaluateArray()); case VALUE_TAG: return(evaluateNumber()); case NULL_TAG: return(0); case BLOCK_TAG: return(evaluateBlock()); case MDEFINE_TAG: return(evaluateMdefine()); case MVARIABLE_TAG: return(evaluateMvariable()); case MIF_TAG: return(evaluateMif()); case MFOR_TAG: return(evaluateMfor()); case MWHILE_TAG: return(evaluateMwhile()); case MDOWHILE_TAG: return(evaluateMdoWhile()); case MDOUNTIL_TAG: return(evaluateMdoUntil()); case PERFORM_TAG: return(evaluatePerform()); case GROUP_TAG: return(evaluateBlock()); case ASSERT_TAG: return(evaluateAssert()); case MSWITCH_TAG: return(evaluateMswitch()); case CLAUSE_TAG: error(CLAUSE_AT_TOP_LEVEL_ERROR); chokePukeAndDie(); case FRETURN_TAG: return(evaluateFreturn()); case END_TAG: return(0); } }
void MultiDataInputInstance::startExecution() { bool ok = true; QString question = evaluateString(ok, QStringLiteral("question")); mMode = evaluateListElement<Mode>(ok, modes, QStringLiteral("mode")); mItems = evaluateItemList(ok, QStringLiteral("items")); QString defaultValue = evaluateString(ok, QStringLiteral("defaultValue")); mVariable = evaluateVariable(ok, QStringLiteral("variable")); QString windowTitle = evaluateString(ok, QStringLiteral("windowTitle")); QImage windowIcon = evaluateImage(ok, QStringLiteral("windowIcon")); mMaximumChoiceCount = evaluateInteger(ok, QStringLiteral("maximumChoiceCount")); if(!ok) return; if(mDialog) delete mDialog; mDialog = new QDialog; mDialog->setWindowFlags(mDialog->windowFlags() | Qt::WindowContextHelpButtonHint); auto layout = new QVBoxLayout(mDialog); mDialog->setLayout(layout); mDialog->setWindowTitle(windowTitle); if(!windowIcon.isNull()) mDialog->setWindowIcon(QIcon(QPixmap::fromImage(windowIcon))); QLabel *questionLabel = new QLabel(mDialog); questionLabel->setText(question); layout->addWidget(questionLabel); switch(mMode) { case ComboBoxMode: case EditableComboBoxMode: { mComboBox = new QComboBox(mDialog); mComboBox->addItems(mItems); int currentItem = mComboBox->findText(defaultValue); if(currentItem == -1) currentItem = 0; mComboBox->setCurrentIndex(currentItem); mComboBox->setEditable(mMode == EditableComboBoxMode); layout->addWidget(mComboBox); } break; case ListMode: { mListWidget = new QListWidget(mDialog); if(mMaximumChoiceCount <= 1) mListWidget->setSelectionMode(QAbstractItemView::SingleSelection); else mListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); mListWidget->addItems(mItems); QList<QListWidgetItem *> defaultItem = mListWidget->findItems(defaultValue, Qt::MatchExactly); if(!defaultItem.isEmpty()) mListWidget->setCurrentItem(defaultItem.first()); layout->addWidget(mListWidget); if(mMaximumChoiceCount > 1) connect(mListWidget, &QListWidget::itemSelectionChanged, this, &MultiDataInputInstance::listItemSelectionChanged); } break; case CheckboxMode: layout->addLayout(createRadioButtonsOrCheckboxes<QCheckBox>(defaultValue, mMaximumChoiceCount <= 1)); break; case RadioButtonMode: layout->addLayout(createRadioButtonsOrCheckboxes<QRadioButton>(defaultValue, true)); break; } if(mMode != ListMode) layout->addStretch(1); QDialogButtonBox *dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, mDialog); layout->addWidget(dialogButtonBox); connect(dialogButtonBox, &QDialogButtonBox::accepted, mDialog, &QDialog::accept); connect(dialogButtonBox, &QDialogButtonBox::rejected, mDialog, &QDialog::reject); connect(mDialog, &QDialog::accepted, this, &MultiDataInputInstance::accepted); connect(mDialog, &QDialog::rejected, this, &MultiDataInputInstance::rejected); for(QLabel *label: mDialog->findChildren<QLabel*>()) label->setOpenExternalLinks(true); mDialog->show(); }
Error executeString(const std::string& str) { sexp::Protect rProtect; SEXP ignoredSEXP ; return evaluateString(str, &ignoredSEXP, &rProtect); }
int BaseModel::getArraySize( NifItem * array ) const { return evaluateString( array, array->arr1() ); }
void WindowConditionInstance::startExecution() { bool ok = true; QString title = evaluateString(ok, QStringLiteral("title")); mCondition = evaluateListElement<Condition>(ok, conditions, QStringLiteral("condition")); mIfTrue = evaluateIfAction(ok, QStringLiteral("ifTrue")); ActionTools::IfActionValue ifFalse = evaluateIfAction(ok, QStringLiteral("ifFalse")); mPosition = evaluateVariable(ok, QStringLiteral("position")); mSize = evaluateVariable(ok, QStringLiteral("size")); mXCoordinate = evaluateVariable(ok, QStringLiteral("xCoordinate")); mYCoordinate = evaluateVariable(ok, QStringLiteral("yCoordinate")); mWidth = evaluateVariable(ok, QStringLiteral("width")); mHeight = evaluateVariable(ok, QStringLiteral("height")); mProcessId = evaluateVariable(ok, QStringLiteral("processId")); if(!ok) return; mTitleRegExp = QRegExp(title, Qt::CaseSensitive, QRegExp::WildcardUnix); ActionTools::WindowHandle foundWindow = findWindow(); if((foundWindow.isValid() && mCondition == Exists) || (!foundWindow.isValid() && mCondition == DontExists)) { QString line = evaluateSubParameter(ok, mIfTrue.actionParameter()); if(!ok) return; if(mIfTrue.action() == ActionTools::IfActionValue::GOTO) setNextLine(line); else if(mIfTrue.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) return; } executionEnded(); } else { QString line = evaluateSubParameter(ok, ifFalse.actionParameter()); if(!ok) return; if(ifFalse.action() == ActionTools::IfActionValue::GOTO) { setNextLine(line); executionEnded(); } else if(ifFalse.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) return; executionEnded(); } else if(ifFalse.action() == ActionTools::IfActionValue::WAIT) { connect(&mTimer, &QTimer::timeout, this, &WindowConditionInstance::checkWindow); mTimer.setInterval(100); mTimer.start(); } else executionEnded(); } }
void MessageBoxInstance::startExecution() { bool ok = true; QString message = evaluateString(ok, "message"); QString title = evaluateString(ok, "title"); Icon icon = evaluateListElement<Icon>(ok, icons, "icon"); TextMode textMode = evaluateListElement<TextMode>(ok, textmodes, "textMode"); Buttons button = evaluateListElement<Buttons>(ok, buttons, "type"); QString customIcon = evaluateString(ok, "customIcon"); QString windowIcon = evaluateString(ok, "windowIcon"); mIfYes = evaluateIfAction(ok, "ifYes"); mIfNo = evaluateIfAction(ok, "ifNo"); mMessageBox = 0; if(!ok) return; mMessageBox = new QMessageBox(); mMessageBox->setIcon(messageBoxIcon(icon)); mMessageBox->setWindowModality(Qt::NonModal); mMessageBox->setText(message); mMessageBox->setWindowTitle(title); switch(textMode) { case HtmlTextMode: mMessageBox->setTextFormat(Qt::RichText); break; case PlainTextMode: mMessageBox->setTextFormat(Qt::PlainText); break; case AutoTextMode: default: mMessageBox->setTextFormat(Qt::AutoText); break; } if(!customIcon.isEmpty()) { QPixmap customIconPixmap; if(customIconPixmap.load(customIcon)) mMessageBox->setIconPixmap(customIconPixmap); } if(!windowIcon.isEmpty()) { QPixmap windowIconPixmap; if(windowIconPixmap.load(windowIcon)) mMessageBox->setWindowIcon(QIcon(windowIconPixmap)); } switch(button) { case OkButton: mMessageBox->setStandardButtons(QMessageBox::Ok); break; case YesNoButtons: mMessageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No); break; } mMessageBox->adjustSize(); QRect screenGeometry = QApplication::desktop()->availableGeometry(); mMessageBox->move(screenGeometry.center()); mMessageBox->move(mMessageBox->pos().x() - mMessageBox->width()/2, mMessageBox->pos().y() - mMessageBox->height()/2); mMessageBox->open(this, SLOT(buttonClicked())); }
void sfGetgroupslot(strList *params) { SETINT(FindGroupByName(evaluateString(params->string))); }