From f220d40bb855c90c59614a6737a5a0c652c2e23a Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 10 Jun 2015 13:55:21 -0700 Subject: [PATCH] Re-download scripts upon Reload All --- interface/src/Application.cpp | 3 +++ libraries/script-engine/src/ScriptCache.cpp | 9 ++++++++- libraries/script-engine/src/ScriptCache.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 651e343087..882997d38a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4344,6 +4344,8 @@ void Application::scriptFinished(const QString& scriptName) { } void Application::stopAllScripts(bool restart) { + auto scriptCache = DependencyManager::get(); + // stops all current running scripts for (QHash::const_iterator it = _scriptEnginesHash.constBegin(); it != _scriptEnginesHash.constEnd(); it++) { @@ -4351,6 +4353,7 @@ void Application::stopAllScripts(bool restart) { continue; } if (restart && it.value()->isUserLoaded()) { + scriptCache->deleteScript(it.key()); connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&))); } it.value()->stop(); diff --git a/libraries/script-engine/src/ScriptCache.cpp b/libraries/script-engine/src/ScriptCache.cpp index 8f854cfdc3..6b7e03df33 100644 --- a/libraries/script-engine/src/ScriptCache.cpp +++ b/libraries/script-engine/src/ScriptCache.cpp @@ -44,7 +44,7 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is QNetworkRequest networkRequest = QNetworkRequest(url); networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); - qCDebug(scriptengine) << "Downloading script at" << url.toString(); + qCDebug(scriptengine) << "Downloading script at:" << url.toString(); QNetworkReply* reply = networkAccessManager.get(networkRequest); connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloaded); } @@ -52,6 +52,13 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is return scriptContents; } +void ScriptCache::deleteScript(const QUrl& url) { + if (_scriptCache.contains(url)) { + qCDebug(scriptengine) << "Delete script from cache:" << url.toString(); + _scriptCache.remove(url); + } +} + void ScriptCache::scriptDownloaded() { QNetworkReply* reply = qobject_cast(sender()); QUrl url = reply->url(); diff --git a/libraries/script-engine/src/ScriptCache.h b/libraries/script-engine/src/ScriptCache.h index 16bf04c53e..820c11b073 100644 --- a/libraries/script-engine/src/ScriptCache.h +++ b/libraries/script-engine/src/ScriptCache.h @@ -27,6 +27,7 @@ class ScriptCache : public QObject, public Dependency { public: QString getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending); + void deleteScript(const QUrl& url); void addScriptToBadScriptList(const QUrl& url) { _badScripts.insert(url); } bool isInBadScriptList(const QUrl& url) { return _badScripts.contains(url); }