mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:03:57 +02:00
convert running-scripts window to use local script files
This commit is contained in:
parent
442339bbc3
commit
b88770228e
6 changed files with 20 additions and 22 deletions
|
@ -224,7 +224,6 @@ static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStanda
|
|||
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).append("/script.js");
|
||||
#endif
|
||||
|
||||
const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js";
|
||||
Setting::Handle<int> maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS);
|
||||
|
||||
const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensions {
|
||||
|
|
|
@ -216,7 +216,7 @@ QVariantList ScriptEngines::getRunning() {
|
|||
static const QString SETTINGS_KEY = "Settings";
|
||||
|
||||
void ScriptEngines::loadDefaultScripts() {
|
||||
loadScript(defaultScriptsFileName());
|
||||
loadScript(defaultScriptsLocation() + "/defaultScripts.js");
|
||||
}
|
||||
|
||||
void ScriptEngines::loadOneScript(const QString& scriptFilename) {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <QXmlStreamReader>
|
||||
|
||||
#include <NetworkAccessManager.h>
|
||||
#include <PathUtils.h>
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
#include "ScriptEngines.h"
|
||||
|
@ -23,11 +24,7 @@
|
|||
#define __STR1__(x) __STR2__(x)
|
||||
#define __LOC__ __FILE__ "(" __STR1__(__LINE__) ") : Warning Msg: "
|
||||
|
||||
|
||||
static const QString S3_URL = "http://s3.amazonaws.com/hifi-public";
|
||||
static const QString PUBLIC_URL = "http://public.highfidelity.io";
|
||||
static const QString MODELS_LOCATION = "scripts/";
|
||||
|
||||
static const QString PREFIX_PARAMETER_NAME = "prefix";
|
||||
static const QString MARKER_PARAMETER_NAME = "marker";
|
||||
static const QString IS_TRUNCATED_NAME = "IsTruncated";
|
||||
|
@ -63,7 +60,7 @@ ScriptsModel::ScriptsModel(QObject* parent) :
|
|||
|
||||
connect(&_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &ScriptsModel::reloadLocalFiles);
|
||||
reloadLocalFiles();
|
||||
reloadRemoteFiles();
|
||||
reloadDefaultFiles();
|
||||
}
|
||||
|
||||
ScriptsModel::~ScriptsModel() {
|
||||
|
@ -140,24 +137,24 @@ void ScriptsModel::updateScriptsLocation(const QString& newPath) {
|
|||
reloadLocalFiles();
|
||||
}
|
||||
|
||||
void ScriptsModel::reloadRemoteFiles() {
|
||||
void ScriptsModel::reloadDefaultFiles() {
|
||||
if (!_loadingScripts) {
|
||||
_loadingScripts = true;
|
||||
for (int i = _treeNodes.size() - 1; i >= 0; i--) {
|
||||
TreeNodeBase* node = _treeNodes.at(i);
|
||||
if (node->getType() == TREE_NODE_TYPE_SCRIPT &&
|
||||
static_cast<TreeNodeScript*>(node)->getOrigin() == SCRIPT_ORIGIN_REMOTE)
|
||||
static_cast<TreeNodeScript*>(node)->getOrigin() == SCRIPT_ORIGIN_DEFAULT)
|
||||
{
|
||||
delete node;
|
||||
_treeNodes.removeAt(i);
|
||||
}
|
||||
}
|
||||
requestRemoteFiles();
|
||||
requestDefaultFiles();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptsModel::requestRemoteFiles(QString marker) {
|
||||
QUrl url(S3_URL);
|
||||
void ScriptsModel::requestDefaultFiles(QString marker) {
|
||||
QUrl url(defaultScriptsLocation());
|
||||
QUrlQuery query;
|
||||
query.addQueryItem(PREFIX_PARAMETER_NAME, MODELS_LOCATION);
|
||||
if (!marker.isEmpty()) {
|
||||
|
@ -218,7 +215,9 @@ bool ScriptsModel::parseXML(QByteArray xmlFile) {
|
|||
xml.readNext();
|
||||
lastKey = xml.text().toString();
|
||||
if (jsRegex.exactMatch(xml.text().toString())) {
|
||||
_treeNodes.append(new TreeNodeScript(lastKey.mid(MODELS_LOCATION.length()), S3_URL + "/" + lastKey, SCRIPT_ORIGIN_REMOTE));
|
||||
_treeNodes.append(new TreeNodeScript(lastKey.mid(MODELS_LOCATION.length()),
|
||||
defaultScriptsLocation() + "/" + lastKey,
|
||||
SCRIPT_ORIGIN_DEFAULT));
|
||||
}
|
||||
}
|
||||
xml.readNext();
|
||||
|
@ -236,7 +235,7 @@ bool ScriptsModel::parseXML(QByteArray xmlFile) {
|
|||
}
|
||||
|
||||
if (truncated) {
|
||||
requestRemoteFiles(lastKey);
|
||||
requestDefaultFiles(lastKey);
|
||||
}
|
||||
|
||||
// If this request was not truncated, we are done.
|
||||
|
|
|
@ -21,7 +21,7 @@ class TreeNodeFolder;
|
|||
|
||||
enum ScriptOrigin {
|
||||
SCRIPT_ORIGIN_LOCAL,
|
||||
SCRIPT_ORIGIN_REMOTE
|
||||
SCRIPT_ORIGIN_DEFAULT
|
||||
};
|
||||
|
||||
enum TreeNodeType {
|
||||
|
@ -84,10 +84,10 @@ protected slots:
|
|||
void updateScriptsLocation(const QString& newPath);
|
||||
void downloadFinished();
|
||||
void reloadLocalFiles();
|
||||
void reloadRemoteFiles();
|
||||
void reloadDefaultFiles();
|
||||
|
||||
protected:
|
||||
void requestRemoteFiles(QString marker = QString());
|
||||
void requestDefaultFiles(QString marker = QString());
|
||||
bool parseXML(QByteArray xmlFile);
|
||||
void rebuildTree();
|
||||
|
||||
|
|
|
@ -54,13 +54,13 @@ QString findMostRecentFileExtension(const QString& originalFileName, QVector<QSt
|
|||
return newestFileName;
|
||||
}
|
||||
|
||||
QString defaultScriptsFileName() {
|
||||
QString defaultScriptsLocation() {
|
||||
#ifdef Q_OS_WIN
|
||||
return QCoreApplication::applicationDirPath() + "/scripts/defaultScripts.js";
|
||||
return "file://" + QCoreApplication::applicationDirPath() + "/scripts";
|
||||
#elif defined(Q_OS_OSX)
|
||||
return QCoreApplication::applicationDirPath() + "/../../scripts/defaultScripts.js";
|
||||
return "file://" + QCoreApplication::applicationDirPath() + "/../../scripts";
|
||||
#else
|
||||
static const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js";
|
||||
static const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts";
|
||||
return DEFAULT_SCRIPTS_JS_URL;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -27,6 +27,6 @@ public:
|
|||
QString fileNameWithoutExtension(const QString& fileName, const QVector<QString> possibleExtensions);
|
||||
QString findMostRecentFileExtension(const QString& originalFileName, QVector<QString> possibleExtensions);
|
||||
|
||||
QString defaultScriptsFileName();
|
||||
QString defaultScriptsLocation();
|
||||
|
||||
#endif // hifi_PathUtils_h
|
||||
|
|
Loading…
Reference in a new issue