mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 15:13:41 +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;
|
||||
}
|
||||
|
||||
void Application::handleScriptEngineLoaded(const QUrl& scriptURL) {
|
||||
void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
|
||||
ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
|
||||
|
||||
_scriptEnginesHash.insertMulti(scriptURL.toString(), scriptEngine);
|
||||
_scriptEnginesHash.insertMulti(scriptFilename, scriptEngine);
|
||||
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
||||
UserActivityLogger::getInstance().loadedScript(scriptURL.toString());
|
||||
UserActivityLogger::getInstance().loadedScript(scriptFilename);
|
||||
|
||||
// register our application services and set it off on its own thread
|
||||
registerScriptEngineWithApplicationServices(scriptEngine);
|
||||
}
|
||||
|
||||
void Application::handleScriptLoadError(const QUrl& scriptURL) {
|
||||
void Application::handleScriptLoadError(const QString& scriptFilename) {
|
||||
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) {
|
||||
|
|
|
@ -394,8 +394,8 @@ private slots:
|
|||
void idle();
|
||||
void aboutToQuit();
|
||||
|
||||
void handleScriptEngineLoaded(const QUrl& scriptURL);
|
||||
void handleScriptLoadError(const QUrl& scriptURL);
|
||||
void handleScriptEngineLoaded(const QString& scriptFilename);
|
||||
void handleScriptLoadError(const QString& scriptFilename);
|
||||
|
||||
void connectedToDomain(const QString& hostname);
|
||||
|
||||
|
|
|
@ -156,31 +156,30 @@ void ScriptEngine::loadURL(const QUrl& scriptURL) {
|
|||
if (_isRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString scriptURLString = scriptURL.toString();
|
||||
_fileNameString = scriptURLString;
|
||||
|
||||
_fileNameString = scriptURL.toString();
|
||||
|
||||
QUrl url(scriptURL);
|
||||
|
||||
// if the scheme length is one or lower, maybe they typed in a file, let's try
|
||||
const int WINDOWS_DRIVE_LETTER_SIZE = 1;
|
||||
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
|
||||
if (url.isValid()) {
|
||||
if (url.scheme() == "file") {
|
||||
QString fileName = url.toLocalFile();
|
||||
QFile scriptFile(fileName);
|
||||
_fileNameString = url.toLocalFile();
|
||||
QFile scriptFile(_fileNameString);
|
||||
if (scriptFile.open(QFile::ReadOnly | QFile::Text)) {
|
||||
qDebug() << "Loading file:" << fileName;
|
||||
qDebug() << "ScriptEngine loading file:" << _fileNameString;
|
||||
QTextStream in(&scriptFile);
|
||||
_scriptContents = in.readAll();
|
||||
emit scriptLoaded(url);
|
||||
emit scriptLoaded(_fileNameString);
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << fileName;
|
||||
emit errorLoadingScript(url);
|
||||
qDebug() << "ERROR Loading file:" << _fileNameString;
|
||||
emit errorLoadingScript(_fileNameString);
|
||||
}
|
||||
} else {
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
|
@ -195,10 +194,10 @@ void ScriptEngine::handleScriptDownload() {
|
|||
|
||||
if (reply->error() == QNetworkReply::NoError && reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
|
||||
_scriptContents = reply->readAll();
|
||||
emit scriptLoaded(reply->url());
|
||||
emit scriptLoaded(_fileNameString);
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << reply->url().toString();
|
||||
emit errorLoadingScript(reply->url());
|
||||
emit errorLoadingScript(_fileNameString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,8 +107,8 @@ public slots:
|
|||
void nodeKilled(SharedNodePointer node);
|
||||
|
||||
signals:
|
||||
void scriptLoaded(const QUrl& scriptURL);
|
||||
void errorLoadingScript(const QUrl& scriptURL);
|
||||
void scriptLoaded(const QString& scriptFilename);
|
||||
void errorLoadingScript(const QString& scriptFilename);
|
||||
void update(float deltaTime);
|
||||
void scriptEnding();
|
||||
void finished(const QString& fileNameString);
|
||||
|
|
Loading…
Reference in a new issue