mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-16 22:30:42 +02:00
Merge pull request #7494 from sethalves/use-local-scripts
Use local scripts
This commit is contained in:
commit
4a1e82892a
8 changed files with 156 additions and 70 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 {
|
||||
|
|
|
@ -234,7 +234,7 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
|||
void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) {
|
||||
_scriptContents = scriptContents;
|
||||
if (_wantSignals) {
|
||||
emit scriptLoaded(_fileNameString);
|
||||
emit scriptLoaded(url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,13 +13,14 @@
|
|||
|
||||
#include <SettingHandle.h>
|
||||
#include <UserActivityLogger.h>
|
||||
#include <PathUtils.h>
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
#include "ScriptEngineLogging.h"
|
||||
|
||||
#define __STR2__(x) #x
|
||||
#define __STR1__(x) __STR2__(x)
|
||||
#define __LOC__ __FILE__ "("__STR1__(__LINE__)") : Warning Msg: "
|
||||
#define __LOC__ __FILE__ "(" __STR1__(__LINE__) ") : Warning Msg: "
|
||||
|
||||
#ifndef __APPLE__
|
||||
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||
|
@ -41,25 +42,53 @@ ScriptEngines::ScriptEngines()
|
|||
_scriptsModelFilter.setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
QString normalizeScriptUrl(const QString& rawScriptUrl) {
|
||||
if (!rawScriptUrl.startsWith("http:") && !rawScriptUrl.startsWith("https:") && !rawScriptUrl.startsWith("atp:")) {
|
||||
#ifdef Q_OS_LINUX
|
||||
if (rawScriptUrl.startsWith("file:")) {
|
||||
return rawScriptUrl;
|
||||
}
|
||||
return QUrl::fromLocalFile(rawScriptUrl).toString();
|
||||
#else
|
||||
if (rawScriptUrl.startsWith("file:")) {
|
||||
return rawScriptUrl.toLower();
|
||||
}
|
||||
// Force lowercase on file scripts because of drive letter weirdness.
|
||||
return QUrl::fromLocalFile(rawScriptUrl).toString().toLower();
|
||||
#endif
|
||||
QUrl normalizeScriptURL(const QUrl& rawScriptURL) {
|
||||
if (rawScriptURL.scheme() == "file") {
|
||||
QUrl fullNormal = rawScriptURL;
|
||||
QUrl defaultScriptLoc = defaultScriptsLocation();
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#else
|
||||
// Force lowercase on file scripts because of drive letter weirdness.
|
||||
if (rawScriptURL.isLocalFile()) {
|
||||
fullNormal.setPath(fullNormal.path().toLower());
|
||||
}
|
||||
#endif
|
||||
// if this url is something "beneath" the default script url, replace the local path with ~
|
||||
if (fullNormal.scheme() == defaultScriptLoc.scheme() &&
|
||||
fullNormal.host() == defaultScriptLoc.host() &&
|
||||
fullNormal.path().startsWith(defaultScriptLoc.path())) {
|
||||
fullNormal.setPath("/~/" + fullNormal.path().mid(defaultScriptLoc.path().size()));
|
||||
}
|
||||
return fullNormal;
|
||||
} else if (rawScriptURL.scheme() == "http" || rawScriptURL.scheme() == "https" || rawScriptURL.scheme() == "atp") {
|
||||
return rawScriptURL;
|
||||
} else {
|
||||
// don't accidently support gopher
|
||||
return QUrl("");
|
||||
}
|
||||
return QUrl(rawScriptUrl).toString();
|
||||
}
|
||||
|
||||
QUrl expandScriptUrl(const QUrl& normalizedScriptURL) {
|
||||
if (normalizedScriptURL.scheme() == "http" ||
|
||||
normalizedScriptURL.scheme() == "https" ||
|
||||
normalizedScriptURL.scheme() == "atp") {
|
||||
return normalizedScriptURL;
|
||||
} else if (normalizedScriptURL.scheme() == "file") {
|
||||
if (normalizedScriptURL.path().startsWith("/~/")) {
|
||||
QUrl url = normalizedScriptURL;
|
||||
QStringList splitPath = url.path().split("/");
|
||||
QUrl defaultScriptsLoc = defaultScriptsLocation();
|
||||
url.setPath(defaultScriptsLoc.path() + "/" + splitPath.mid(2).join("/")); // 2 to skip the slashes in /~/
|
||||
return url;
|
||||
}
|
||||
return normalizedScriptURL;
|
||||
} else {
|
||||
return QUrl("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QObject* scriptsModel();
|
||||
|
||||
void ScriptEngines::registerScriptInitializer(ScriptInitializer initializer) {
|
||||
|
@ -192,19 +221,25 @@ QVariantList ScriptEngines::getLocal() {
|
|||
}
|
||||
|
||||
QVariantList ScriptEngines::getRunning() {
|
||||
const int WINDOWS_DRIVE_LETTER_SIZE = 1;
|
||||
QVariantList result;
|
||||
auto runningScripts = getRunningScripts();
|
||||
foreach(const QString& runningScript, runningScripts) {
|
||||
QUrl runningScriptURL = QUrl(runningScript);
|
||||
if (runningScriptURL.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
|
||||
if (!runningScriptURL.isValid()) {
|
||||
runningScriptURL = QUrl::fromLocalFile(runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
|
||||
}
|
||||
QVariantMap resultNode;
|
||||
resultNode.insert("name", runningScriptURL.fileName());
|
||||
resultNode.insert("url", runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
|
||||
QUrl displayURL = expandScriptUrl(QUrl(runningScriptURL));
|
||||
QString displayURLString;
|
||||
if (displayURL.isLocalFile()) {
|
||||
displayURLString = displayURL.toLocalFile();
|
||||
} else {
|
||||
displayURLString = displayURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded));
|
||||
}
|
||||
resultNode.insert("url", displayURLString);
|
||||
// The path contains the exact path/URL of the script, which also is used in the stopScript function.
|
||||
resultNode.insert("path", runningScript);
|
||||
resultNode.insert("path", normalizeScriptURL(runningScript).toString());
|
||||
resultNode.insert("local", runningScriptURL.isLocalFile());
|
||||
result.append(resultNode);
|
||||
}
|
||||
|
@ -213,10 +248,11 @@ QVariantList ScriptEngines::getRunning() {
|
|||
|
||||
|
||||
static const QString SETTINGS_KEY = "Settings";
|
||||
static const QString DEFAULT_SCRIPTS_JS_URL = "http://s3.amazonaws.com/hifi-public/scripts/defaultScripts.js";
|
||||
|
||||
void ScriptEngines::loadDefaultScripts() {
|
||||
loadScript(DEFAULT_SCRIPTS_JS_URL);
|
||||
QUrl defaultScriptsLoc = defaultScriptsLocation();
|
||||
defaultScriptsLoc.setPath(defaultScriptsLoc.path() + "/scripts/defaultScripts.js");
|
||||
loadScript(defaultScriptsLoc.toString());
|
||||
}
|
||||
|
||||
void ScriptEngines::loadOneScript(const QString& scriptFilename) {
|
||||
|
@ -265,7 +301,7 @@ void ScriptEngines::saveScripts() {
|
|||
for (auto it = runningScripts.begin(); it != runningScripts.end(); ++it) {
|
||||
if (getScriptEngine(*it)->isUserLoaded()) {
|
||||
settings.setArrayIndex(i);
|
||||
settings.setValue("script", *it);
|
||||
settings.setValue("script", normalizeScriptURL(*it).toString());
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
@ -307,11 +343,16 @@ void ScriptEngines::stopAllScripts(bool restart) {
|
|||
}
|
||||
}
|
||||
|
||||
bool ScriptEngines::stopScript(const QString& rawScriptUrl, bool restart) {
|
||||
bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
|
||||
bool stoppedScript = false;
|
||||
{
|
||||
QUrl scriptURL = normalizeScriptURL(QUrl(rawScriptURL));
|
||||
if (!scriptURL.isValid()) {
|
||||
scriptURL = normalizeScriptURL(QUrl::fromLocalFile(rawScriptURL));
|
||||
}
|
||||
const QString scriptURLString = scriptURL.toString();
|
||||
|
||||
QReadLocker lock(&_scriptEnginesHashLock);
|
||||
const QString scriptURLString = normalizeScriptUrl(rawScriptUrl);
|
||||
if (_scriptEnginesHash.contains(scriptURLString)) {
|
||||
ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURLString];
|
||||
if (restart) {
|
||||
|
@ -344,18 +385,19 @@ void ScriptEngines::reloadAllScripts() {
|
|||
stopAllScripts(true);
|
||||
}
|
||||
|
||||
ScriptEngine* ScriptEngines::loadScript(const QString& scriptFilename, bool isUserLoaded, bool loadScriptFromEditor, bool activateMainWindow, bool reload) {
|
||||
ScriptEngine* ScriptEngines::loadScript(const QUrl& scriptFilename, bool isUserLoaded, bool loadScriptFromEditor,
|
||||
bool activateMainWindow, bool reload) {
|
||||
if (thread() != QThread::currentThread()) {
|
||||
ScriptEngine* result { nullptr };
|
||||
QMetaObject::invokeMethod(this, "loadScript", Qt::BlockingQueuedConnection, Q_RETURN_ARG(ScriptEngine*, result),
|
||||
Q_ARG(QString, scriptFilename),
|
||||
Q_ARG(QUrl, scriptFilename),
|
||||
Q_ARG(bool, isUserLoaded),
|
||||
Q_ARG(bool, loadScriptFromEditor),
|
||||
Q_ARG(bool, activateMainWindow),
|
||||
Q_ARG(bool, reload));
|
||||
return result;
|
||||
}
|
||||
QUrl scriptUrl(scriptFilename);
|
||||
QUrl scriptUrl = normalizeScriptURL(scriptFilename);
|
||||
auto scriptEngine = getScriptEngine(scriptUrl.toString());
|
||||
if (scriptEngine) {
|
||||
return scriptEngine;
|
||||
|
@ -368,7 +410,7 @@ ScriptEngine* ScriptEngines::loadScript(const QString& scriptFilename, bool isUs
|
|||
}, Qt::QueuedConnection);
|
||||
|
||||
|
||||
if (scriptFilename.isNull()) {
|
||||
if (scriptFilename.isEmpty()) {
|
||||
launchScriptEngine(scriptEngine);
|
||||
} else {
|
||||
// connect to the appropriate signals of this script engine
|
||||
|
@ -376,17 +418,17 @@ ScriptEngine* ScriptEngines::loadScript(const QString& scriptFilename, bool isUs
|
|||
connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &ScriptEngines::onScriptEngineError);
|
||||
|
||||
// get the script engine object to load the script at the designated script URL
|
||||
scriptEngine->loadURL(scriptUrl, reload);
|
||||
scriptEngine->loadURL(QUrl(expandScriptUrl(scriptUrl.toString())), reload);
|
||||
}
|
||||
|
||||
return scriptEngine;
|
||||
}
|
||||
|
||||
ScriptEngine* ScriptEngines::getScriptEngine(const QString& rawScriptUrl) {
|
||||
ScriptEngine* ScriptEngines::getScriptEngine(const QString& rawScriptURL) {
|
||||
ScriptEngine* result = nullptr;
|
||||
{
|
||||
QReadLocker lock(&_scriptEnginesHashLock);
|
||||
const QString scriptURLString = normalizeScriptUrl(rawScriptUrl);
|
||||
const QString scriptURLString = normalizeScriptURL(QUrl(rawScriptURL)).toString();
|
||||
auto it = _scriptEnginesHash.find(scriptURLString);
|
||||
if (it != _scriptEnginesHash.end()) {
|
||||
result = it.value();
|
||||
|
@ -396,15 +438,17 @@ ScriptEngine* ScriptEngines::getScriptEngine(const QString& rawScriptUrl) {
|
|||
}
|
||||
|
||||
// FIXME - change to new version of ScriptCache loading notification
|
||||
void ScriptEngines::onScriptEngineLoaded(const QString& rawScriptUrl) {
|
||||
UserActivityLogger::getInstance().loadedScript(rawScriptUrl);
|
||||
void ScriptEngines::onScriptEngineLoaded(const QString& rawScriptURL) {
|
||||
UserActivityLogger::getInstance().loadedScript(rawScriptURL);
|
||||
ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||
|
||||
launchScriptEngine(scriptEngine);
|
||||
|
||||
{
|
||||
QWriteLocker lock(&_scriptEnginesHashLock);
|
||||
const QString scriptURLString = normalizeScriptUrl(rawScriptUrl);
|
||||
QUrl url = QUrl(rawScriptURL);
|
||||
QUrl normalized = normalizeScriptURL(url);
|
||||
const QString scriptURLString = normalized.toString();
|
||||
_scriptEnginesHash.insertMulti(scriptURLString, scriptEngine);
|
||||
}
|
||||
emit scriptCountChanged();
|
||||
|
@ -427,11 +471,11 @@ void ScriptEngines::launchScriptEngine(ScriptEngine* scriptEngine) {
|
|||
}
|
||||
|
||||
|
||||
void ScriptEngines::onScriptFinished(const QString& rawScriptUrl, ScriptEngine* engine) {
|
||||
void ScriptEngines::onScriptFinished(const QString& rawScriptURL, ScriptEngine* engine) {
|
||||
bool removed = false;
|
||||
{
|
||||
QWriteLocker lock(&_scriptEnginesHashLock);
|
||||
const QString scriptURLString = normalizeScriptUrl(rawScriptUrl);
|
||||
const QString scriptURLString = normalizeScriptURL(QUrl(rawScriptURL)).toString();
|
||||
for (auto it = _scriptEnginesHash.find(scriptURLString); it != _scriptEnginesHash.end(); ++it) {
|
||||
if (it.value() == engine) {
|
||||
_scriptEnginesHash.erase(it);
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
ScriptsModelFilter* scriptsModelFilter() { return &_scriptsModelFilter; };
|
||||
|
||||
Q_INVOKABLE void loadOneScript(const QString& scriptFilename);
|
||||
Q_INVOKABLE ScriptEngine* loadScript(const QString& scriptFilename = QString(),
|
||||
Q_INVOKABLE ScriptEngine* loadScript(const QUrl& scriptFilename = QString(),
|
||||
bool isUserLoaded = true, bool loadScriptFromEditor = false, bool activateMainWindow = false, bool reload = false);
|
||||
Q_INVOKABLE bool stopScript(const QString& scriptHash, bool restart = false);
|
||||
|
||||
|
@ -96,4 +96,7 @@ protected:
|
|||
ScriptsModelFilter _scriptsModelFilter;
|
||||
};
|
||||
|
||||
QUrl normalizeScriptURL(const QUrl& rawScriptURL);
|
||||
QUrl expandScriptUrl(const QUrl& normalizedScriptURL);
|
||||
|
||||
#endif // hifi_ScriptEngine_h
|
||||
|
|
|
@ -13,21 +13,19 @@
|
|||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QDirIterator>
|
||||
|
||||
#include <NetworkAccessManager.h>
|
||||
#include <PathUtils.h>
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
#include "ScriptEngines.h"
|
||||
#include "ScriptEngineLogging.h"
|
||||
#define __STR2__(x) #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 PREFIX_PARAMETER_NAME = "prefix";
|
||||
static const QString MARKER_PARAMETER_NAME = "marker";
|
||||
static const QString IS_TRUNCATED_NAME = "IsTruncated";
|
||||
|
@ -63,7 +61,7 @@ ScriptsModel::ScriptsModel(QObject* parent) :
|
|||
|
||||
connect(&_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &ScriptsModel::reloadLocalFiles);
|
||||
reloadLocalFiles();
|
||||
reloadRemoteFiles();
|
||||
reloadDefaultFiles();
|
||||
}
|
||||
|
||||
ScriptsModel::~ScriptsModel() {
|
||||
|
@ -140,36 +138,56 @@ 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);
|
||||
QUrlQuery query;
|
||||
query.addQueryItem(PREFIX_PARAMETER_NAME, MODELS_LOCATION);
|
||||
if (!marker.isEmpty()) {
|
||||
query.addQueryItem(MARKER_PARAMETER_NAME, marker);
|
||||
}
|
||||
url.setQuery(query);
|
||||
void ScriptsModel::requestDefaultFiles(QString marker) {
|
||||
QUrl url(defaultScriptsLocation());
|
||||
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
QNetworkReply* reply = networkAccessManager.get(request);
|
||||
connect(reply, SIGNAL(finished()), SLOT(downloadFinished()));
|
||||
if (url.isLocalFile()) {
|
||||
// if the url indicates a local directory, use QDirIterator
|
||||
// QString localDir = url.toLocalFile() + "/scripts";
|
||||
QString localDir = expandScriptUrl(url).toLocalFile() + "/scripts";
|
||||
int localDirPartCount = localDir.split("/").size();
|
||||
#ifdef Q_OS_WIN
|
||||
localDirPartCount++; // one for the drive letter
|
||||
#endif
|
||||
QDirIterator it(localDir, QStringList() << "*.js", QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QUrl jsFullPath = QUrl::fromLocalFile(it.next());
|
||||
QString jsPartialPath = jsFullPath.path().split("/").mid(localDirPartCount).join("/");
|
||||
jsFullPath = normalizeScriptURL(jsFullPath);
|
||||
_treeNodes.append(new TreeNodeScript(jsPartialPath, jsFullPath.toString(), SCRIPT_ORIGIN_DEFAULT));
|
||||
}
|
||||
_loadingScripts = false;
|
||||
} else {
|
||||
// the url indicates http(s), use QNetworkRequest
|
||||
QUrlQuery query;
|
||||
query.addQueryItem(PREFIX_PARAMETER_NAME, MODELS_LOCATION);
|
||||
if (!marker.isEmpty()) {
|
||||
query.addQueryItem(MARKER_PARAMETER_NAME, marker);
|
||||
}
|
||||
url.setQuery(query);
|
||||
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
QNetworkReply* reply = networkAccessManager.get(request);
|
||||
connect(reply, SIGNAL(finished()), SLOT(downloadFinished()));
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptsModel::downloadFinished() {
|
||||
|
@ -182,8 +200,10 @@ void ScriptsModel::downloadFinished() {
|
|||
if (!data.isEmpty()) {
|
||||
finished = parseXML(data);
|
||||
} else {
|
||||
qCDebug(scriptengine) << "Error: Received no data when loading remote scripts";
|
||||
qCDebug(scriptengine) << "Error: Received no data when loading default scripts";
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Error: when loading default scripts --" << reply->error();
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
|
@ -218,7 +238,11 @@ 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));
|
||||
QString localPath = lastKey.split("/").mid(1).join("/");
|
||||
QUrl fullPath = defaultScriptsLocation();
|
||||
fullPath.setPath(fullPath.path() + "/" + lastKey);
|
||||
const QString fullPathStr = normalizeScriptURL(fullPath).toString();
|
||||
_treeNodes.append(new TreeNodeScript(localPath, fullPathStr, SCRIPT_ORIGIN_DEFAULT));
|
||||
}
|
||||
}
|
||||
xml.readNext();
|
||||
|
@ -231,12 +255,12 @@ bool ScriptsModel::parseXML(QByteArray xmlFile) {
|
|||
|
||||
// Error handling
|
||||
if (xml.hasError()) {
|
||||
qCDebug(scriptengine) << "Error loading remote scripts: " << xml.errorString();
|
||||
qCDebug(scriptengine) << "Error loading default scripts: " << xml.errorString();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (truncated) {
|
||||
requestRemoteFiles(lastKey);
|
||||
requestDefaultFiles(lastKey);
|
||||
}
|
||||
|
||||
// If this request was not truncated, we are done.
|
||||
|
@ -261,7 +285,9 @@ void ScriptsModel::reloadLocalFiles() {
|
|||
const QFileInfoList localFiles = _localDirectory.entryInfoList();
|
||||
for (int i = 0; i < localFiles.size(); i++) {
|
||||
QFileInfo file = localFiles[i];
|
||||
_treeNodes.append(new TreeNodeScript(file.fileName(), file.absoluteFilePath(), SCRIPT_ORIGIN_LOCAL));
|
||||
QString fileName = file.fileName();
|
||||
QUrl absPath = normalizeScriptURL(QUrl::fromLocalFile(file.absoluteFilePath()));
|
||||
_treeNodes.append(new TreeNodeScript(fileName, absPath.toString(), SCRIPT_ORIGIN_LOCAL));
|
||||
}
|
||||
rebuildTree();
|
||||
endResetModel();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include "PathUtils.h"
|
||||
|
||||
|
||||
|
@ -53,3 +54,14 @@ QString findMostRecentFileExtension(const QString& originalFileName, QVector<QSt
|
|||
}
|
||||
return newestFileName;
|
||||
}
|
||||
|
||||
QUrl defaultScriptsLocation() {
|
||||
#ifdef Q_OS_WIN
|
||||
return QUrl(("file:///" + QCoreApplication::applicationDirPath()).toLower());
|
||||
#elif defined(Q_OS_OSX)
|
||||
return QUrl(("file://" + QCoreApplication::applicationDirPath() + "/../Resources").toLower());
|
||||
#else
|
||||
// return "http://s3.amazonaws.com/hifi-public";
|
||||
return QUrl("file://" + QCoreApplication::applicationDirPath());
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -27,4 +27,6 @@ public:
|
|||
QString fileNameWithoutExtension(const QString& fileName, const QVector<QString> possibleExtensions);
|
||||
QString findMostRecentFileExtension(const QString& originalFileName, QVector<QString> possibleExtensions);
|
||||
|
||||
QUrl defaultScriptsLocation();
|
||||
|
||||
#endif // hifi_PathUtils_h
|
||||
|
|
Loading…
Reference in a new issue