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