mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 10:43:45 +02:00
fix URL/filename discrepancy for local scripts
This commit is contained in:
parent
a549b4b152
commit
98f56aaa0c
4 changed files with 20 additions and 21 deletions
|
@ -4042,20 +4042,20 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
|
||||||
return scriptEngine;
|
return scriptEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::handleScriptEngineLoaded(const QUrl& scriptURL) {
|
void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
|
||||||
ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||||
|
|
||||||
_scriptEnginesHash.insertMulti(scriptURL.toString(), scriptEngine);
|
_scriptEnginesHash.insertMulti(scriptFilename, scriptEngine);
|
||||||
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
||||||
UserActivityLogger::getInstance().loadedScript(scriptURL.toString());
|
UserActivityLogger::getInstance().loadedScript(scriptFilename);
|
||||||
|
|
||||||
// register our application services and set it off on its own thread
|
// register our application services and set it off on its own thread
|
||||||
registerScriptEngineWithApplicationServices(scriptEngine);
|
registerScriptEngineWithApplicationServices(scriptEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::handleScriptLoadError(const QUrl& scriptURL) {
|
void Application::handleScriptLoadError(const QString& scriptFilename) {
|
||||||
qDebug() << "Application::loadScript(), script failed to load...";
|
qDebug() << "Application::loadScript(), script failed to load...";
|
||||||
QMessageBox::warning(getWindow(), "Error Loading Script", scriptURL.toString() + " failed to load.");
|
QMessageBox::warning(getWindow(), "Error Loading Script", scriptFilename + " failed to load.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::scriptFinished(const QString& scriptName) {
|
void Application::scriptFinished(const QString& scriptName) {
|
||||||
|
|
|
@ -394,8 +394,8 @@ private slots:
|
||||||
void idle();
|
void idle();
|
||||||
void aboutToQuit();
|
void aboutToQuit();
|
||||||
|
|
||||||
void handleScriptEngineLoaded(const QUrl& scriptURL);
|
void handleScriptEngineLoaded(const QString& scriptFilename);
|
||||||
void handleScriptLoadError(const QUrl& scriptURL);
|
void handleScriptLoadError(const QString& scriptFilename);
|
||||||
|
|
||||||
void connectedToDomain(const QString& hostname);
|
void connectedToDomain(const QString& hostname);
|
||||||
|
|
||||||
|
|
|
@ -156,31 +156,30 @@ void ScriptEngine::loadURL(const QUrl& scriptURL) {
|
||||||
if (_isRunning) {
|
if (_isRunning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString scriptURLString = scriptURL.toString();
|
_fileNameString = scriptURL.toString();
|
||||||
_fileNameString = scriptURLString;
|
|
||||||
|
|
||||||
QUrl url(scriptURL);
|
QUrl url(scriptURL);
|
||||||
|
|
||||||
// if the scheme length is one or lower, maybe they typed in a file, let's try
|
// if the scheme length is one or lower, maybe they typed in a file, let's try
|
||||||
const int WINDOWS_DRIVE_LETTER_SIZE = 1;
|
const int WINDOWS_DRIVE_LETTER_SIZE = 1;
|
||||||
if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
|
if (url.scheme().size() <= WINDOWS_DRIVE_LETTER_SIZE) {
|
||||||
url = QUrl::fromLocalFile(scriptURLString);
|
url = QUrl::fromLocalFile(_fileNameString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, let's see if it's valid... and if so, load it
|
// ok, let's see if it's valid... and if so, load it
|
||||||
if (url.isValid()) {
|
if (url.isValid()) {
|
||||||
if (url.scheme() == "file") {
|
if (url.scheme() == "file") {
|
||||||
QString fileName = url.toLocalFile();
|
_fileNameString = url.toLocalFile();
|
||||||
QFile scriptFile(fileName);
|
QFile scriptFile(_fileNameString);
|
||||||
if (scriptFile.open(QFile::ReadOnly | QFile::Text)) {
|
if (scriptFile.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
qDebug() << "Loading file:" << fileName;
|
qDebug() << "ScriptEngine loading file:" << _fileNameString;
|
||||||
QTextStream in(&scriptFile);
|
QTextStream in(&scriptFile);
|
||||||
_scriptContents = in.readAll();
|
_scriptContents = in.readAll();
|
||||||
emit scriptLoaded(url);
|
emit scriptLoaded(_fileNameString);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "ERROR Loading file:" << fileName;
|
qDebug() << "ERROR Loading file:" << _fileNameString;
|
||||||
emit errorLoadingScript(url);
|
emit errorLoadingScript(_fileNameString);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||||
|
@ -195,10 +194,10 @@ void ScriptEngine::handleScriptDownload() {
|
||||||
|
|
||||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||||
_scriptContents = reply->readAll();
|
_scriptContents = reply->readAll();
|
||||||
emit scriptLoaded(reply->url());
|
emit scriptLoaded(_fileNameString);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "ERROR Loading file:" << reply->url().toString();
|
qDebug() << "ERROR Loading file:" << reply->url().toString();
|
||||||
emit errorLoadingScript(reply->url());
|
emit errorLoadingScript(_fileNameString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,8 @@ public slots:
|
||||||
void nodeKilled(SharedNodePointer node);
|
void nodeKilled(SharedNodePointer node);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void scriptLoaded(const QUrl& scriptURL);
|
void scriptLoaded(const QString& scriptFilename);
|
||||||
void errorLoadingScript(const QUrl& scriptURL);
|
void errorLoadingScript(const QString& scriptFilename);
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
void scriptEnding();
|
void scriptEnding();
|
||||||
void finished(const QString& fileNameString);
|
void finished(const QString& fileNameString);
|
||||||
|
|
Loading…
Reference in a new issue