From 143d9797796b7ca48c0964a96f4c178f18af2fa3 Mon Sep 17 00:00:00 2001 From: Iakov 'Jake' Kirilenko Date: Fri, 19 Jan 2024 18:51:21 +0300 Subject: [PATCH] Fix incorrect override for script engine + disable totally writeToFile, writeData, and removeFile --- .../src/trikTextualInterpreter.cpp | 5 ++--- .../src/twoDExecutionControl.cpp | 21 +++++++++++++------ .../robots/trikKitInterpreterCommon_fr.ts | 8 +++---- .../robots/trikKitInterpreterCommon_ru.ts | 8 +++---- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp index 01304831d9..538899482c 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp @@ -105,10 +105,9 @@ void trik::TrikTextualInterpreter::interpretScriptExercise(const QString &script mBrick.processSensors(true); mBrick.setCurrentInputs(inputs); if (languageExtension.contains("js")) { - mScriptRunner.run(jsOverrides + "script.writeToFile = null;\n" + script); + mScriptRunner.run(jsOverrides + script); } else if (languageExtension.contains("py")) { - auto updatedScript = script; - mScriptRunner.run(updatedScript.insert(0, "\nscript.writeToFile = None\n"), "dummyFile.py"); + mScriptRunner.run(script, "dummyFile.py"); } else { reportError(tr("Unsupported script file type")); } diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp b/plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp index f54ce15297..6326c23fa8 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/twoDExecutionControl.cpp @@ -21,6 +21,12 @@ #include #include #include +#include + +#define NOTIFY_DISABLED(methodName) do {\ + QLOG_WARN() << "Script tried to use disabled method:" << #methodName; \ + (Q_EMIT textInStdOut(tr("'%1' is disabled\n").arg(#methodName))); \ + } while(0) TwoDExecutionControl::TwoDExecutionControl( trik::TrikBrick &brick @@ -117,21 +123,23 @@ void TwoDExecutionControl::system(const QString &command, bool synchronously) { Q_UNUSED(command) Q_UNUSED(synchronously) - emit textInStdOut("system is disabled\n"); + NOTIFY_DISABLED(system); } void TwoDExecutionControl::writeToFile(const QString &file, const QString &text) { QFile out(mBrick.getCurrentDir().absoluteFilePath(file)); - out.open(QIODevice::WriteOnly | QIODevice::Append); - out.write(text.toUtf8()); + Q_UNUSED(out) + Q_UNUSED(text) + NOTIFY_DISABLED(writeToFile); } void TwoDExecutionControl::writeData(const QString &file, const QVector &bytes) { QFile out(mBrick.getCurrentDir().absoluteFilePath(file)); - out.open(QIODevice::WriteOnly | QIODevice::Append); - out.write(reinterpret_cast(bytes.data()), bytes.size()); + Q_UNUSED(out) + Q_UNUSED(bytes) + NOTIFY_DISABLED(writeData); } QStringList TwoDExecutionControl::readAll(const QString &file) const @@ -142,7 +150,8 @@ QStringList TwoDExecutionControl::readAll(const QString &file) const void TwoDExecutionControl::removeFile(const QString &file) { QFile out(mBrick.getCurrentDir().absoluteFilePath(file)); - out.remove(); + Q_UNUSED(out) + NOTIFY_DISABLED(removeFile); } int TwoDExecutionControl::timeInterval(int packedTimeLeft, int packedTimeRight) diff --git a/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts b/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts index 88a3fd07a3..2c68df2ce9 100644 --- a/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts +++ b/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts @@ -4,7 +4,7 @@ QObject - + Bogus input values @@ -105,7 +105,7 @@ TwoDExecutionControl - + No cofigured random device @@ -265,8 +265,8 @@ trik::TrikTextualInterpreter - - + + Unsupported script file type diff --git a/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts b/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts index 451802b166..d7eca2bc42 100644 --- a/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts +++ b/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts @@ -4,7 +4,7 @@ QObject - + Bogus input values Неподходящие значения аргументов @@ -161,7 +161,7 @@ TwoDExecutionControl - + No cofigured random device Генератор случайных чисел не сконфигурирован @@ -330,8 +330,8 @@ trik::TrikTextualInterpreter - - + + Unsupported script file type Неверный формат файла