Fix capitalization problems with qmlviewer

qmlviewer is picky about file path capitalization, and will bail out with
'File name case mismatch' if e.g. the working directory is wrongly
capitalized. Prevent this by computing the canonical path of
the qml file + working directory in advance.

Reviewed-by: Alessandro Portale
Task-number: QTCREATORBUG-3417
This commit is contained in:
Kai Koehne
2010-12-21 12:39:14 +01:00
parent 550a85a432
commit e414335f26
2 changed files with 37 additions and 3 deletions

View File

@@ -45,6 +45,10 @@
#include <qt4projectmanager/qtoutputformatter.h>
#include <qt4projectmanager/qt4projectmanagerconstants.h>
#ifdef Q_OS_WIN32
#include <Windows.h>
#endif
using Core::EditorManager;
using Core::ICore;
using Core::IEditor;
@@ -144,16 +148,18 @@ QString QmlProjectRunConfiguration::viewerArguments() const
Utils::QtcProcess::addArg(&args, importPath);
}
const QString &s = mainScript();
if (!s.isEmpty())
QString s = mainScript();
if (!s.isEmpty()) {
s = canonicalCapsPath(s);
Utils::QtcProcess::addArg(&args, s);
}
return args;
}
QString QmlProjectRunConfiguration::workingDirectory() const
{
QFileInfo projectFile(qmlTarget()->qmlProject()->file()->fileName());
return projectFile.absolutePath();
return canonicalCapsPath(projectFile.absolutePath());
}
int QmlProjectRunConfiguration::qtVersionId() const
@@ -172,6 +178,32 @@ void QmlProjectRunConfiguration::setQtVersionId(int id)
m_configurationWidget.data()->updateQtVersionComboBox();
}
/* QtDeclarative checks explicitly that the capitalization for any URL / path
is exactly like the capitalization on disk. This method is uses the same
native Windows API's to get the exact canonical path. */
QString QmlProjectRunConfiguration::canonicalCapsPath(const QString &fileName)
{
QString canonicalPath = QFileInfo(fileName).canonicalFilePath();
#if defined(Q_OS_WIN32)
wchar_t *buffer = 0;
do {
long length = ::GetLongPathName((wchar_t*)fileName.utf16(), NULL, 0);
if (!length)
break;
buffer = new wchar_t[length];
DWORD rv = ::GetLongPathName((wchar_t*)fileName.utf16(), buffer, length);
if (!rv)
break;
canonicalPath = QString((QChar*)buffer);
} while (false);
delete buffer;
#endif
return canonicalPath;
}
Qt4ProjectManager::QtVersion *QmlProjectRunConfiguration::qtVersion() const
{
if (m_qtVersionId == -1)