From 282528ea675233ad46fc6e42a090b9521a4364af Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 29 Sep 2011 20:06:09 +0200 Subject: [PATCH] Set text codec to UTF-8, so qDebug/qWarning/qFatal don't destroy Unicode strings. Also remove qDebug64() and friends, as we don't need them any more. --- etc/Translation/Blank.ts | 6 ++--- src/Config.h | 2 +- src/Dialog_MainWindow.cpp | 6 ++--- src/Global.cpp | 45 ++++++++++++++--------------------- src/Global.h | 6 ++--- src/Thread_DiskObserver.cpp | 4 ++-- src/Thread_FileAnalyzer.cpp | 8 +++---- src/Thread_Initialization.cpp | 2 +- 8 files changed, 35 insertions(+), 44 deletions(-) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index 20a69697..f71e1e0e 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -2684,17 +2684,17 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. - + Executable '%1' requires Qt v%2, but found Qt v%3. - + Executable '%1' requires Windows 2000 or later. diff --git a/src/Config.h b/src/Config.h index 63726dde..bd0b5ad1 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_PATCH 2 -#define VER_LAMEXP_BUILD 700 +#define VER_LAMEXP_BUILD 702 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 2a7336b7..2cb2f368 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -745,13 +745,13 @@ void MainWindow::dropEvent(QDropEvent *event) } if(file.isFile()) { - qDebug64("Dropped File: %1", file.canonicalFilePath()); + qDebug("Dropped File: %s", file.canonicalFilePath().toUtf8().constData()); droppedFiles << file.canonicalFilePath(); continue; } if(file.isDir()) { - qDebug64("Dropped Folder: %1", file.canonicalFilePath()); + qDebug("Dropped Folder: %s", file.canonicalFilePath().toUtf8().constData()); QList list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Files | QDir::NoSymLinks); if(list.count() > 0) { @@ -765,7 +765,7 @@ void MainWindow::dropEvent(QDropEvent *event) list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); for(int j = 0; j < list.count(); j++) { - qDebug64("Descending to Folder: %1", list.at(j).canonicalFilePath()); + qDebug("Descending to Folder: %s", list.at(j).canonicalFilePath().toUtf8().constData()); urls.prepend(QUrl::fromLocalFile(list.at(j).canonicalFilePath())); } } diff --git a/src/Global.cpp b/src/Global.cpp index 2274cc3f..bcf07649 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -368,17 +368,14 @@ static void lamexp_console_color(FILE* file, WORD attributes) void lamexp_message_handler(QtMsgType type, const char *msg) { static const char *GURU_MEDITATION = "\n\nGURU MEDITATION !!!\n\n"; - - const char *text = msg; - const char *buffer = NULL; QMutexLocker lock(&g_lamexp_message_mutex); - if((strlen(msg) > 8) && (_strnicmp(msg, "@BASE64@", 8) == 0)) - { - buffer = _strdup(QByteArray::fromBase64(msg + 8).constData()); - if(buffer) text = buffer; - } + //if((strlen(msg) > 8) && (_strnicmp(msg, "@BASE64@", 8) == 0)) + //{ + // buffer = _strdup(QByteArray::fromBase64(msg + 8).constData()); + // if(buffer) text = buffer; + //} if(g_lamexp_console_attached) { @@ -393,17 +390,17 @@ void lamexp_message_handler(QtMsgType type, const char *msg) fflush(stderr); lamexp_console_color(stderr, FOREGROUND_RED | FOREGROUND_INTENSITY); fprintf(stderr, GURU_MEDITATION); - fprintf(stderr, "%s\n", text); + fprintf(stderr, "%s\n", msg); fflush(stderr); break; case QtWarningMsg: lamexp_console_color(stderr, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); - fprintf(stderr, "%s\n", text); + fprintf(stderr, "%s\n", msg); fflush(stderr); break; default: lamexp_console_color(stderr, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); - fprintf(stderr, "%s\n", text); + fprintf(stderr, "%s\n", msg); fflush(stderr); break; } @@ -413,42 +410,33 @@ void lamexp_message_handler(QtMsgType type, const char *msg) } else { - char temp[1024] = {'\0'}; + QString temp("[LameXP][%1] %2"); switch(type) { case QtCriticalMsg: case QtFatalMsg: - _snprintf_s(temp, 1024, _TRUNCATE, "[LameXP][C] %s", text); + temp = temp.arg("C", QString::fromUtf8(msg)); break; case QtWarningMsg: - _snprintf_s(temp, 1024, _TRUNCATE, "[LameXP][C] %s", text); + temp = temp.arg("W", QString::fromUtf8(msg)); break; default: - _snprintf_s(temp, 1024, _TRUNCATE, "[LameXP][C] %s", text); + temp = temp.arg("I", QString::fromUtf8(msg)); break; } - char *ptr = strchr(temp, '\n'); - while(ptr != NULL) - { - *ptr = '\t'; - ptr = strchr(temp, '\n'); - } - - strncat_s(temp, 1024, "\n", _TRUNCATE); - OutputDebugStringA(temp); + temp.replace("\n", "\t").append("\n"); + OutputDebugStringA(temp.toLatin1().constData()); } if(type == QtCriticalMsg || type == QtFatalMsg) { lock.unlock(); - MessageBoxW(NULL, QWCHAR(QString::fromUtf8(text)), L"LameXP - GURU MEDITATION", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL); + MessageBoxW(NULL, QWCHAR(QString::fromUtf8(msg)), 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); } - - LAMEXP_SAFE_FREE(buffer); } /* @@ -822,6 +810,9 @@ bool lamexp_init_qt(int argc, char* argv[]) application->setOrganizationDomain("mulder.at.gg"); application->setWindowIcon((date.month() == 12 && date.day() >= 24 && date.day() <= 26) ? QIcon(":/MainIcon2.png") : QIcon(":/MainIcon.png")); + //Set text Codec for locale + QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); + //Load plugins from application directory QCoreApplication::setLibraryPaths(QStringList() << QApplication::applicationDirPath()); qDebug("Library Path:\n%s\n", QApplication::libraryPaths().first().toUtf8().constData()); diff --git a/src/Global.h b/src/Global.h index e61b4342..487dc46e 100644 --- a/src/Global.h +++ b/src/Global.h @@ -140,9 +140,9 @@ SIZE_T lamexp_dbg_private_bytes(void); #define LAMEXP_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" LAMEXP_MAKE_STRING(__LINE__) ") : warning: " TXT)) //Output Qt debug message (Unicode-safe versions) -#define qDebug64(FORMAT, ...) qDebug("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); -#define qWarning64(FORMAT, ...) qWarning("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); -#define qFatal64(FORMAT, ...) qFatal("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); +//#define qDebug64(FORMAT, ...) qDebug("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); +//#define qWarning64(FORMAT, ...) qWarning("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); +//#define qFatal64(FORMAT, ...) qFatal("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData()); //Check for debug build #if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG) diff --git a/src/Thread_DiskObserver.cpp b/src/Thread_DiskObserver.cpp index a58259de..564521bd 100644 --- a/src/Thread_DiskObserver.cpp +++ b/src/Thread_DiskObserver.cpp @@ -73,8 +73,8 @@ void DiskObserverThread::observe(void) freeSpace = lamexp_free_diskspace(m_path); if(freeSpace < minimumSpace) { - qWarning64("Free diskspace on '%1' dropped below %2 MB, only %3 MB free!", m_path, QString::number(minimumSpace / 1048576), QString::number(freeSpace / 1048576)); - emit messageLogged(tr("Low diskspace on drive '%1' detected (only %2 MB are free), problems can occur!").arg(QDir::toNativeSeparators(m_path), QString::number(freeSpace / 1048576)), true); + qWarning("Free diskspace on '%s' dropped below %s MB, only %s MB free!", m_path.toUtf8().constData(), QString::number(minimumSpace / 1048576ui64).toUtf8().constData(), QString::number(freeSpace / 1048576ui64).toUtf8().constData()); + emit messageLogged(tr("Low diskspace on drive '%1' detected (only %2 MB are free), problems can occur!").arg(QDir::toNativeSeparators(m_path), QString::number(freeSpace / 1048576ui64)), true); minimumSpace = min(freeSpace, (minimumSpace >> 1)); } Sleep(1000); diff --git a/src/Thread_FileAnalyzer.cpp b/src/Thread_FileAnalyzer.cpp index 440cdf75..6b69ddc1 100644 --- a/src/Thread_FileAnalyzer.cpp +++ b/src/Thread_FileAnalyzer.cpp @@ -84,7 +84,7 @@ void FileAnalyzer::run() { int fileType = fileTypeNormal; QString currentFile = QDir::fromNativeSeparators(m_inputFiles.takeFirst()); - qDebug64("Analyzing: %1", currentFile); + qDebug("Analyzing: %s", currentFile.toUtf8().constData()); emit fileSelected(QFileInfo(currentFile).fileName()); AudioFileModel file = analyzeFile(currentFile, &fileType); @@ -134,13 +134,13 @@ void FileAnalyzer::run() } else { - qDebug64("Rejected Avisynth file: %1", file.filePath()); + qDebug("Rejected Avisynth file: %s", file.filePath().toUtf8().constData()); m_filesRejected++; } } else { - qDebug64("Rejected file of unknown type: %1", file.filePath()); + qDebug("Rejected file of unknown type: %s", file.filePath().toUtf8().constData()); m_filesRejected++; } continue; @@ -513,7 +513,7 @@ bool FileAnalyzer::checkFile_CDDA(QFile &file) void FileAnalyzer::retrieveCover(AudioFileModel &audioFile, const QString &filePath) { - qDebug64("Retrieving cover from: %1", filePath); + qDebug("Retrieving cover from: %s", filePath.toUtf8().constData()); QString extension; switch(m_currentCover) diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index d691d1cf..f6cac289 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -299,7 +299,7 @@ void InitializationThread::initTranslations(void) if(lamexp_translation_register(langId, qmFile, langName, systemId)) { - qDebug64("Registering translation: %1 = %2 (%3)", qmFile, langName, QString::number(systemId)); + qDebug("Registering translation: %s = %s (%u)", qmFile.toUtf8().constData(), langName.toUtf8().constData(), systemId); } else {