GUI: recode log file encoding of host name to UTF-8

See https://bugreports.qt.io/browse/QTBUG-49640 for the bug description
and rationale.
This commit is contained in:
Moritz Bunkus 2015-11-25 21:55:05 +01:00
parent a9355ab443
commit 2ea08319f8
3 changed files with 50 additions and 1 deletions

View File

@ -1,3 +1,11 @@
2015-11-25 Moritz Bunkus <moritz@bunkus.org>
* MKVToolNix GUI: bug fix: implemented a workaround for a bug in
Qt which caused the GUI not to start anymore due to failing to
detect a stale lock file if the GUI had crashed before on a
computer with a host name that included non-ASCII characters. See
https://bugreports.qt.io/browse/QTBUG-49640
2015-11-22 Moritz Bunkus <moritz@bunkus.org>
* mkvmerge: bug fix: a track's number of bits per audio sample

View File

@ -1,6 +1,7 @@
#include "common/common_pch.h"
#include <QDir>
#include <QFile>
#include <QLibraryInfo>
#include <QLocalServer>
#include <QLocalSocket>
@ -65,6 +66,41 @@ App::App(int &argc,
App::~App() {
}
void
App::fixLockFileHostName(QString const &lockFilePath) {
// Due to a bug in Qt up to and including v5.5.1 the lock file
// contains the host name in the wrong encoding. If the host name
// contains non-ASCII characters stale lock file detection will
// fail. See https://bugreports.qt.io/browse/QTBUG-49640
if (!QFileInfo{lockFilePath}.exists())
return;
QFile lockFile{lockFilePath};
if (!lockFile.open(QIODevice::ReadWrite))
return;
auto const alreadyFixed = Q("alreadyFixedByMKVToolNix");
auto lines = QList<QByteArray>{};
for (int idx = 0; idx < 4; ++idx)
lines << lockFile.readLine();
if (QString::fromLocal8Bit(lines[3]) == alreadyFixed)
return;
lines[2].chop(1);
lines[2] = Q("%1\n").arg(QString::fromLocal8Bit(lines[2])).toUtf8();
lines[3] = alreadyFixed.toLocal8Bit();
lockFile.seek(0);
for (auto const &line : lines)
lockFile.write(line);
lockFile.resize(lockFile.pos());
}
QString
App::communicatorSocketName() {
return Q("MKVToolNix-GUI-Instance-Communicator");
@ -74,7 +110,10 @@ void
App::setupInstanceCommunicator() {
auto socketName = communicatorSocketName();
auto lockFilePath = QDir{QDir::tempPath()}.filePath(Q("%1.lock").arg(socketName));
m_instanceLock = std::make_unique<QLockFile>(lockFilePath);
fixLockFileHostName(lockFilePath);
m_instanceLock = std::make_unique<QLockFile>(lockFilePath);
m_instanceLock->setStaleLockTime(0);
if (!m_instanceLock->tryLock(0)) {

View File

@ -87,6 +87,8 @@ public:
static QString communicatorSocketName();
static QString settingsBaseGroupName();
static void fixLockFileHostName(QString const &lockFilePath);
};
}}