Squish: Fix object map handling on Windows

Ensure we are using UTF8 all over the place especially when
using external tools and their stdin or stdout streams.
This fixes bad encoding issues on Windows when having unicode
characters inside the objects map file.

Change-Id: Ic8e66a876abe0903308002cd25315b1eaa3788b1
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2022-11-11 12:50:59 +01:00
parent 3922ee3c72
commit b55c10f189
4 changed files with 16 additions and 13 deletions

View File

@@ -12,7 +12,7 @@
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <QDir> #include <QtCore5Compat/QTextCodec>
namespace Squish { namespace Squish {
namespace Internal { namespace Internal {
@@ -187,13 +187,13 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
if (fileName.isEmpty()) if (fileName.isEmpty())
return OpenResult::CannotHandle; return OpenResult::CannotHandle;
QString text; QByteArray text;
if (realFileName.fileName() == "objects.map") { if (realFileName.fileName() == "objects.map") {
Utils::FileReader reader; Utils::FileReader reader;
if (!reader.fetch(realFileName, QIODevice::Text, error)) if (!reader.fetch(realFileName, QIODevice::Text, error))
return OpenResult::ReadError; return OpenResult::ReadError;
text = QString::fromLocal8Bit(reader.data()); text = reader.data();
} else { } else {
const Utils::FilePath base = SquishPlugin::squishSettings()->squishPath.filePath(); const Utils::FilePath base = SquishPlugin::squishSettings()->squishPath.filePath();
if (base.isEmpty()) { if (base.isEmpty()) {
@@ -212,11 +212,12 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
Utils::QtcProcess objectMapReader; Utils::QtcProcess objectMapReader;
objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read", objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read",
"--scriptedObjectMapPath", realFileName.toUserOutput()}}); "--scriptedObjectMapPath", realFileName.toUserOutput()}});
objectMapReader.setCodec(QTextCodec::codecForName("UTF-8"));
objectMapReader.start(); objectMapReader.start();
objectMapReader.waitForFinished(); objectMapReader.waitForFinished();
text = objectMapReader.cleanedStdOut(); text = objectMapReader.cleanedStdOut().toUtf8();
} }
if (!setContents(text.toUtf8())) { if (!setContents(text)) {
if (error) if (error)
error->append(Tr::tr("Failure while parsing objects.map content.")); error->append(Tr::tr("Failure while parsing objects.map content."));
return OpenResult::ReadError; return OpenResult::ReadError;

View File

@@ -346,7 +346,7 @@ void ObjectsMapEditorWidget::onPropertiesContentModified(const QString &text)
const QModelIndex &idx = m_objMapFilterModel->mapToSource(selected.first()); const QModelIndex &idx = m_objMapFilterModel->mapToSource(selected.first());
if (auto item = static_cast<ObjectsMapTreeItem *>(m_document->model()->itemForIndex(idx))) if (auto item = static_cast<ObjectsMapTreeItem *>(m_document->model()->itemForIndex(idx)))
item->setPropertiesContent(text.toLocal8Bit().trimmed()); item->setPropertiesContent(text.toUtf8().trimmed());
} }
void ObjectsMapEditorWidget::onJumpToSymbolicNameClicked() void ObjectsMapEditorWidget::onJumpToSymbolicNameClicked()

View File

@@ -130,19 +130,20 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
if (properties.isEmpty() || properties.at(0) != '{') if (properties.isEmpty() || properties.at(0) != '{')
return false; return false;
QString p = QString::fromUtf8(properties);
ParseState state = None; ParseState state = None;
QByteArray name; QString name;
QByteArray value; QString value;
QByteArray oper; QString oper;
bool masquerading = false; bool masquerading = false;
for (char c : properties) { for (QChar c : p) {
if (masquerading) { if (masquerading) {
value.append('\\').append(c); value.append('\\').append(c);
masquerading = false; masquerading = false;
continue; continue;
} }
switch (c) { switch (c.unicode()) {
case '=': case '=':
if (state == Value) { if (state == Value) {
value.append(c); value.append(c);
@@ -172,7 +173,7 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
} else if (state == Value) { } else if (state == Value) {
state = None; state = None;
Property prop; Property prop;
if (!prop.set(QLatin1String(name), QLatin1String(oper), QLatin1String(value))) { if (!prop.set(name, oper, value)) {
propertyRoot->removeChildren(); propertyRoot->removeChildren();
return false; return false;
} }
@@ -214,7 +215,7 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
} }
break; break;
default: default:
if (QChar::isSpace(c)) { if (c.isSpace()) {
if (state == Value) { if (state == Value) {
value.append(c); value.append(c);
} else if (state == Name) { } else if (state == Name) {

View File

@@ -10,6 +10,7 @@ QtcPlugin {
Depends { name: "Utils" } Depends { name: "Utils" }
Depends { name: "Qt.widgets" } Depends { name: "Qt.widgets" }
Depends { name: "Qt.core5compat" }
files: [ files: [
"deletesymbolicnamedialog.cpp", "deletesymbolicnamedialog.cpp",