mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-02 11:13:43 +02:00
Add function hasValidScriptSuffix and check if script extensions are JavaScript or JSON files
This commit is contained in:
parent
1fa3e6bda2
commit
e9fac38bbb
2 changed files with 16 additions and 0 deletions
|
@ -425,6 +425,15 @@ QString ScriptEngine::getFilename() const {
|
||||||
return lastPart;
|
return lastPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptEngine::hasValidScriptSuffix(const QString& scriptFileName) {
|
||||||
|
QFileInfo fileInfo(scriptFileName);
|
||||||
|
QString scriptSuffixToLower = fileInfo.completeSuffix().toLower();
|
||||||
|
if (scriptSuffixToLower == "js" || scriptSuffixToLower == "json") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||||
if (_isRunning) {
|
if (_isRunning) {
|
||||||
return;
|
return;
|
||||||
|
@ -434,6 +443,12 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||||
_fileNameString = url.toString();
|
_fileNameString = url.toString();
|
||||||
_isReloading = reload;
|
_isReloading = reload;
|
||||||
|
|
||||||
|
// Check that script is an actual script
|
||||||
|
if (!hasValidScriptSuffix(_fileNameString)) {
|
||||||
|
qCDebug(scriptengine) << "File extension of file: " + _fileNameString + " is not a currently supported script type";
|
||||||
|
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