Implemented a workaround to pass UTF-8 strings through qDebug(): As the argument of qDebug() is defined as char*, we cannot pass UTF-16 strings. And as qDebug() mangles UTF-8 strings, we cannot pass UTF-8 encoded strings directly either. Consequently we will now encode UTF-8 strings as Base64 before passing them to qDebug(). A special prefix ("@BASE64@") is used to indicate Base64 encoded strings.

This commit is contained in:
LoRd_MuldeR 2011-03-10 02:07:51 +01:00
parent 3f40f1ed66
commit 4973aeca68
4 changed files with 30 additions and 17 deletions

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 1
#define VER_LAMEXP_BUILD 360
#define VER_LAMEXP_BUILD 363
#define VER_LAMEXP_SUFFIX Beta-8
/*

View File

@ -263,6 +263,14 @@ void lamexp_message_handler(QtMsgType type, const char *msg)
{
static HANDLE hConsole = NULL;
QMutexLocker lock(&g_lamexp_message_mutex);
const char *buffer = NULL, *text = msg;
char temp[1024];
if(!strncmp(msg, "@BASE64@", 8))
{
buffer = _strdup(QByteArray::fromBase64(msg + 8).constData());
if(buffer) text = buffer;
}
if(!hConsole)
{
@ -275,6 +283,8 @@ void lamexp_message_handler(QtMsgType type, const char *msg)
if(hConsole)
{
int len = sprintf_s(temp, 1024, "%s\n", text);
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
SetConsoleOutputCP(CP_UTF8);
@ -286,18 +296,18 @@ void lamexp_message_handler(QtMsgType type, const char *msg)
fflush(stdout);
fflush(stderr);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
fwprintf(stderr, L"\nGURU MEDITATION !!!\n%S\n\n", msg);
MessageBoxW(NULL, (wchar_t*) QString::fromUtf8(msg).utf16(), L"LameXP - GURU MEDITATION", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
WriteFile(hConsole, temp, len, NULL, NULL);
FlushFileBuffers(hConsole);
break;
case QtWarningMsg:
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
fwprintf(stderr, L"%S\n", msg);
fflush(stderr);
WriteFile(hConsole, temp, len, NULL, NULL);
FlushFileBuffers(hConsole);
break;
default:
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
fwprintf(stderr, L"%S\n", msg);
fflush(stderr);
WriteFile(hConsole, temp, len, NULL, NULL);
FlushFileBuffers(hConsole);
break;
}
@ -305,32 +315,35 @@ void lamexp_message_handler(QtMsgType type, const char *msg)
}
else
{
char temp_buffer[1024];
switch(type)
{
case QtCriticalMsg:
case QtFatalMsg:
sprintf_s(temp_buffer, 1024, "[LameXP][C] %s", msg);
sprintf_s(temp, 1024, "[LameXP][C] %s", text);
break;
case QtWarningMsg:
sprintf_s(temp_buffer, 1024, "[LameXP][W] %s", msg);
sprintf_s(temp, 1024, "[LameXP][W] %s", text);
break;
default:
sprintf_s(temp_buffer, 1024, "[LameXP][I] %s", msg);
sprintf_s(temp, 1024, "[LameXP][I] %s", text);
break;
}
OutputDebugStringA(temp_buffer);
while(char *ptr = strchr(temp, '\n')) *ptr = '\t';
strcat_s(temp, 1024, "\n");
OutputDebugStringA(temp);
}
if(type == QtCriticalMsg || type == QtFatalMsg)
{
lock.unlock();
MessageBoxW(NULL, QWCHAR(QString::fromUtf8(text)), L"LameXP - GURU MEDITATION", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
TerminateProcess(GetCurrentProcess(), -1);
}
}
if(buffer) free((void*) buffer);
}
/*
* Initialize the console

View File

@ -74,7 +74,7 @@ void FileAnalyzer::run()
while(!m_inputFiles.isEmpty())
{
QString currentFile = QDir::fromNativeSeparators(m_inputFiles.takeFirst());
qDebug("Analyzing: %s", currentFile.toUtf8().constData());
qDebug("@BASE64@%s", QString("Analyzing: %1").arg(currentFile).toUtf8().toBase64().constData());
emit fileSelected(QFileInfo(currentFile).fileName());
AudioFileModel file = analyzeFile(currentFile);
if(file.fileName().isEmpty() || file.formatContainerType().isEmpty() || file.formatAudioType().isEmpty())
@ -82,7 +82,7 @@ void FileAnalyzer::run()
if(!PlaylistImporter::importPlaylist(m_inputFiles, currentFile))
{
m_filesRejected++;
qDebug("Skipped: %s", file.filePath().toUtf8().constData());
qDebug("@BASE64@%s", QString("Skipped: %1").arg(file.filePath()).toUtf8().toBase64().constData());
}
continue;
}

View File

@ -228,7 +228,7 @@ void InitializationThread::initTranslations(void)
if(lamexp_translation_register(langId, qmFile, langName, systemId))
{
qDebug("Registering translation: %s = %s (%u)", qmFile.toLatin1().constData(), langName.toLatin1().constData(), systemId);
qDebug("@BASE64@%s", QString("Registering translation: %1 = %2 (%3)").arg(qmFile, langName, QString::number(systemId)).toUtf8().toBase64().constData());
}
else
{