mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 20:58:38 +02:00
Merge pull request #10536 from misslivirose/fix/check-extension-running-scripts
Fix/check extension running scripts
This commit is contained in:
commit
f8b92b6666
2 changed files with 14 additions and 0 deletions
|
@ -421,6 +421,12 @@ QString ScriptEngine::getFilename() const {
|
||||||
return lastPart;
|
return lastPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptEngine::hasValidScriptSuffix(const QString& scriptFileName) {
|
||||||
|
QFileInfo fileInfo(scriptFileName);
|
||||||
|
QString scriptSuffixToLower = fileInfo.completeSuffix().toLower();
|
||||||
|
return scriptSuffixToLower.contains(QString("js"), Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||||
if (_isRunning) {
|
if (_isRunning) {
|
||||||
return;
|
return;
|
||||||
|
@ -430,6 +436,13 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||||
_fileNameString = url.toString();
|
_fileNameString = url.toString();
|
||||||
_isReloading = reload;
|
_isReloading = reload;
|
||||||
|
|
||||||
|
// Check that script has a supported file extension
|
||||||
|
if (!hasValidScriptSuffix(_fileNameString)) {
|
||||||
|
scriptErrorMessage("File extension of file: " + _fileNameString + " is not a currently supported script type");
|
||||||
|
emit errorLoadingScript(_fileNameString);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior
|
const auto maxRetries = 0; // for consistency with previous scriptCache->getScript() behavior
|
||||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||||
scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) {
|
scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) {
|
||||||
|
|
|
@ -146,6 +146,7 @@ public:
|
||||||
/// to run... NOTE - this is used by Application currently to load the url. We don't really want it to be exposed
|
/// to run... NOTE - this is used by Application currently to load the url. We don't really want it to be exposed
|
||||||
/// to scripts. we may not need this to be invokable
|
/// to scripts. we may not need this to be invokable
|
||||||
void loadURL(const QUrl& scriptURL, bool reload);
|
void loadURL(const QUrl& scriptURL, bool reload);
|
||||||
|
bool hasValidScriptSuffix(const QString& scriptFileName);
|
||||||
|
|
||||||
Q_INVOKABLE QString getContext() const;
|
Q_INVOKABLE QString getContext() const;
|
||||||
Q_INVOKABLE bool isClientScript() const { return _context == CLIENT_SCRIPT; }
|
Q_INVOKABLE bool isClientScript() const { return _context == CLIENT_SCRIPT; }
|
||||||
|
|
Loading…
Reference in a new issue