Showing the changes to libraries/script-engine/src/ScriptsModel.cpp (1 of 6 files). Show all
Unified · Split
| @@ -15,6 +15,7 @@ · 14 unmodified lines | |||
| 15 | #include <QXmlStreamReader> | 15 | #include <QXmlStreamReader> |
| 16 | 16 | ||
| 17 | #include <NetworkAccessManager.h> | 17 | #include <NetworkAccessManager.h> |
| 18 | #include <PathUtils.h> | ||
| 18 | 19 | ||
| 19 | #include "ScriptEngine.h" | 20 | #include "ScriptEngine.h" |
| 20 | #include "ScriptEngines.h" | 21 | #include "ScriptEngines.h" |
| @@ -23,11 +24,7 @@ · 2 unmodified lines | |||
| 23 | #define __STR1__(x) __STR2__(x) | 24 | #define __STR1__(x) __STR2__(x) |
| 24 | #define __LOC__ __FILE__ "(" __STR1__(__LINE__) ") : Warning Msg: " | 25 | #define __LOC__ __FILE__ "(" __STR1__(__LINE__) ") : Warning Msg: " |
| 25 | 26 | ||
| 26 | |||
| 27 | static const QString S3_URL = "http://s3.amazonaws.com/hifi-public"; | ||
| 28 | static const QString PUBLIC_URL = "http://public.highfidelity.io"; | ||
| 29 | static const QString MODELS_LOCATION = "scripts/"; | 27 | static const QString MODELS_LOCATION = "scripts/"; |
| 30 | |||
| 31 | static const QString PREFIX_PARAMETER_NAME = "prefix"; | 28 | static const QString PREFIX_PARAMETER_NAME = "prefix"; |
| 32 | static const QString MARKER_PARAMETER_NAME = "marker"; | 29 | static const QString MARKER_PARAMETER_NAME = "marker"; |
| 33 | static const QString IS_TRUNCATED_NAME = "IsTruncated"; | 30 | static const QString IS_TRUNCATED_NAME = "IsTruncated"; |
| @@ -63,7 +60,7 @@ ScriptsModel::ScriptsModel(QObject* parent) : · 29 unmodified lines | |||
| 63 | 60 | ||
| 64 | connect(&_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &ScriptsModel::reloadLocalFiles); | 61 | connect(&_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &ScriptsModel::reloadLocalFiles); |
| 65 | reloadLocalFiles(); | 62 | reloadLocalFiles(); |
| 66 | reloadRemoteFiles(); | 63 | reloadDefaultFiles(); |
| 67 | } | 64 | } |
| 68 | 65 | ||
| 69 | ScriptsModel::~ScriptsModel() { | 66 | ScriptsModel::~ScriptsModel() { |
| @@ -140,24 +137,24 @@ void ScriptsModel::updateScriptsLocation(const QString& newPath) { · 70 unmodified lines | |||
| 140 | reloadLocalFiles(); | 137 | reloadLocalFiles(); |
| 141 | } | 138 | } |
| 142 | 139 | ||
| 143 | void ScriptsModel::reloadRemoteFiles() { | 140 | void ScriptsModel::reloadDefaultFiles() { |
| 144 | if (!_loadingScripts) { | 141 | if (!_loadingScripts) { |
| 145 | _loadingScripts = true; | 142 | _loadingScripts = true; |
| 146 | for (int i = _treeNodes.size() - 1; i >= 0; i--) { | 143 | for (int i = _treeNodes.size() - 1; i >= 0; i--) { |
| 147 | TreeNodeBase* node = _treeNodes.at(i); | 144 | TreeNodeBase* node = _treeNodes.at(i); |
| 148 | if (node->getType() == TREE_NODE_TYPE_SCRIPT && | 145 | if (node->getType() == TREE_NODE_TYPE_SCRIPT && |
| 149 | static_cast<TreeNodeScript*>(node)->getOrigin() == SCRIPT_ORIGIN_REMOTE) | 146 | static_cast<TreeNodeScript*>(node)->getOrigin() == SCRIPT_ORIGIN_DEFAULT) |
| 150 | { | 147 | { |
| 151 | delete node; | 148 | delete node; |
| 152 | _treeNodes.removeAt(i); | 149 | _treeNodes.removeAt(i); |
| 153 | } | 150 | } |
| 154 | } | 151 | } |
| 155 | requestRemoteFiles(); | 152 | requestDefaultFiles(); |
| 156 | } | 153 | } |
| 157 | } | 154 | } |
| 158 | 155 | ||
| 159 | void ScriptsModel::requestRemoteFiles(QString marker) { | 156 | void ScriptsModel::requestDefaultFiles(QString marker) { |
| 160 | QUrl url(S3_URL); | 157 | QUrl url(defaultScriptsLocation()); |
| 161 | QUrlQuery query; | 158 | QUrlQuery query; |
| 162 | query.addQueryItem(PREFIX_PARAMETER_NAME, MODELS_LOCATION); | 159 | query.addQueryItem(PREFIX_PARAMETER_NAME, MODELS_LOCATION); |
| 163 | if (!marker.isEmpty()) { | 160 | if (!marker.isEmpty()) { |
| @@ -218,7 +215,9 @@ bool ScriptsModel::parseXML(QByteArray xmlFile) { · 54 unmodified lines | |||
| 218 | xml.readNext(); | 215 | xml.readNext(); |
| 219 | lastKey = xml.text().toString(); | 216 | lastKey = xml.text().toString(); |
| 220 | if (jsRegex.exactMatch(xml.text().toString())) { | 217 | if (jsRegex.exactMatch(xml.text().toString())) { |
| 221 | _treeNodes.append(new TreeNodeScript(lastKey.mid(MODELS_LOCATION.length()), S3_URL + "/" + lastKey, SCRIPT_ORIGIN_REMOTE)); | 218 | _treeNodes.append(new TreeNodeScript(lastKey.mid(MODELS_LOCATION.length()), |
| 219 | defaultScriptsLocation() + "/" + lastKey, | ||
| 220 | SCRIPT_ORIGIN_DEFAULT)); | ||
| 222 | } | 221 | } |
| 223 | } | 222 | } |
| 224 | xml.readNext(); | 223 | xml.readNext(); |
| @@ -236,7 +235,7 @@ bool ScriptsModel::parseXML(QByteArray xmlFile) { · 11 unmodified lines | |||
| 236 | } | 235 | } |
| 237 | 236 | ||
| 238 | if (truncated) { | 237 | if (truncated) { |
| 239 | requestRemoteFiles(lastKey); | 238 | requestDefaultFiles(lastKey); |
| 240 | } | 239 | } |
| 241 | 240 | ||
| 242 | // If this request was not truncated, we are done. | 241 | // If this request was not truncated, we are done. |