convert running-scripts window to use local script files

This commit is contained in:
Seth Alves 2016-03-29 10:40:56 -07:00
parent 442339bbc3
commit b88770228e
6 changed files with 20 additions and 22 deletions

View file

@ -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 {

View file

@ -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) {

View file

@ -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.

View file

@ -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();

View file

@ -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
}

View file

@ -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