mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-16 22:30:42 +02:00
started on making ~ mean the application directory in script paths
This commit is contained in:
parent
2ad02941e4
commit
7c0bb72aff
4 changed files with 46 additions and 20 deletions
|
@ -43,24 +43,55 @@ ScriptEngines::ScriptEngines()
|
|||
}
|
||||
|
||||
QString normalizeScriptUrl(const QString& rawScriptUrl) {
|
||||
if (!rawScriptUrl.startsWith("http:") && !rawScriptUrl.startsWith("https:") && !rawScriptUrl.startsWith("atp:")) {
|
||||
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
|
||||
QString fullNormal;
|
||||
if (rawScriptUrl.startsWith("file:")) {
|
||||
return rawScriptUrl.toLower();
|
||||
fullNormal = rawScriptUrl.toLower();
|
||||
} else {
|
||||
// Force lowercase on file scripts because of drive letter weirdness.
|
||||
fullNormal = QUrl::fromLocalFile(rawScriptUrl).toString().toLower();
|
||||
}
|
||||
// Force lowercase on file scripts because of drive letter weirdness.
|
||||
return QUrl::fromLocalFile(rawScriptUrl).toString().toLower();
|
||||
QString defaultScriptLoc = defaultScriptsLocation();
|
||||
if (fullNormal.startsWith(defaultScriptLoc)) {
|
||||
return "~" + fullNormal.mid(defaultScriptLoc.size());
|
||||
}
|
||||
return fullNormal;
|
||||
#endif
|
||||
|
||||
}
|
||||
return QUrl(rawScriptUrl).toString();
|
||||
}
|
||||
|
||||
QString expandScriptUrl(const QString& normalizedScriptURL) {
|
||||
if (normalizedScriptURL.startsWith("http:") ||
|
||||
normalizedScriptURL.startsWith("https:") ||
|
||||
normalizedScriptURL.startsWith("atp:")) {
|
||||
return QUrl(normalizedScriptURL).toString();
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
if (normalizedScriptURL.startsWith("file:")) {
|
||||
url = QUrl(normalizedScriptURL);
|
||||
} else {
|
||||
url = QUrl::fromLocalFile(normalizedScriptURL);
|
||||
}
|
||||
|
||||
QString path = url.path();
|
||||
QStringList splitPath = path.split("/");
|
||||
if (splitPath.size() > 0 && splitPath[0] == "~") {
|
||||
QString defaultScriptLoc = defaultScriptsLocation();
|
||||
url.setPath(defaultScriptLoc + splitPath.mid(1).join("/"));
|
||||
return url.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QObject* scriptsModel();
|
||||
|
||||
void ScriptEngines::registerScriptInitializer(ScriptInitializer initializer) {
|
||||
|
|
|
@ -96,4 +96,7 @@ protected:
|
|||
ScriptsModelFilter _scriptsModelFilter;
|
||||
};
|
||||
|
||||
QString normalizeScriptUrl(const QString& rawScriptUrl);
|
||||
QString expandScriptUrl(const QString& normalizedScriptURL);
|
||||
|
||||
#endif // hifi_ScriptEngine_h
|
||||
|
|
|
@ -161,12 +161,8 @@ void ScriptsModel::requestDefaultFiles(QString marker) {
|
|||
QString localDir = url.toLocalFile() + "/scripts";
|
||||
QDirIterator it(localDir, QStringList() << "*.js", QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString jsFullPath = it.next();
|
||||
QString jsPartialPath = jsFullPath.mid(localDir.length() + 1); // + 1 to skip a separator
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
||||
jsFullPath = jsFullPath.toLower();
|
||||
jsPartialPath = jsPartialPath.toLower();
|
||||
#endif
|
||||
QString jsFullPath = normalizeScriptUrl(it.next());
|
||||
QString jsPartialPath = normalizeScriptUrl(jsFullPath.mid(localDir.length() + 1)); // + 1 to skip a separator
|
||||
_treeNodes.append(new TreeNodeScript(jsPartialPath, jsFullPath, SCRIPT_ORIGIN_DEFAULT));
|
||||
}
|
||||
} else {
|
||||
|
@ -231,7 +227,7 @@ bool ScriptsModel::parseXML(QByteArray xmlFile) {
|
|||
while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == CONTAINER_NAME)) {
|
||||
if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == KEY_NAME) {
|
||||
xml.readNext();
|
||||
lastKey = xml.text().toString();
|
||||
lastKey = normalizeScriptUrl(xml.text().toString());
|
||||
if (jsRegex.exactMatch(xml.text().toString())) {
|
||||
_treeNodes.append(new TreeNodeScript(lastKey.mid(MODELS_LOCATION.length()),
|
||||
defaultScriptsLocation() + "/" + lastKey,
|
||||
|
@ -278,12 +274,8 @@ void ScriptsModel::reloadLocalFiles() {
|
|||
const QFileInfoList localFiles = _localDirectory.entryInfoList();
|
||||
for (int i = 0; i < localFiles.size(); i++) {
|
||||
QFileInfo file = localFiles[i];
|
||||
QString fileName = file.fileName();
|
||||
QString absPath = file.absoluteFilePath();
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
||||
fileName = fileName.toLower();
|
||||
absPath = absPath.toLower();
|
||||
#endif
|
||||
QString fileName = normalizeScriptUrl(file.fileName());
|
||||
QString absPath = normalizeScriptUrl(file.absoluteFilePath());
|
||||
_treeNodes.append(new TreeNodeScript(fileName, absPath, SCRIPT_ORIGIN_LOCAL));
|
||||
}
|
||||
rebuildTree();
|
||||
|
@ -310,7 +302,7 @@ void ScriptsModel::rebuildTree() {
|
|||
for (pathIterator = pathList.constBegin(); pathIterator != pathList.constEnd(); ++pathIterator) {
|
||||
hash.append(*pathIterator + "/");
|
||||
if (!folders.contains(hash)) {
|
||||
folders[hash] = new TreeNodeFolder(*pathIterator, parent);
|
||||
folders[hash] = new TreeNodeFolder(normalizeScriptUrl(*pathIterator), parent);
|
||||
}
|
||||
parent = folders[hash];
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ QString findMostRecentFileExtension(const QString& originalFileName, QVector<QSt
|
|||
|
||||
QString defaultScriptsLocation() {
|
||||
#ifdef Q_OS_WIN
|
||||
return "file:///" + QCoreApplication::applicationDirPath();
|
||||
return QString("file:///" + QCoreApplication::applicationDirPath()).toLower();
|
||||
#elif defined(Q_OS_OSX)
|
||||
return "file:///" + QCoreApplication::applicationDirPath() + "/../..";
|
||||
return QString("file:///" + QCoreApplication::applicationDirPath() + "/../..").toLower();
|
||||
#else
|
||||
return "http://s3.amazonaws.com/hifi-public";
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue