Make message handler routine thread-safe.
This commit is contained in:
parent
092e664ad1
commit
98dc212d68
BIN
res/images/Working.gif
Normal file
BIN
res/images/Working.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
@ -25,7 +25,7 @@
|
||||
#define VER_LAMEXP_MAJOR 4
|
||||
#define VER_LAMEXP_MINOR_HI 0
|
||||
#define VER_LAMEXP_MINOR_LO 0
|
||||
#define VER_LAMEXP_BUILD 40
|
||||
#define VER_LAMEXP_BUILD 41
|
||||
#define VER_LAMEXP_SUFFIX TechPreview
|
||||
|
||||
/*
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <QSysInfo>
|
||||
#include <QStringList>
|
||||
#include <QSystemSemaphore>
|
||||
#include <QMutex>
|
||||
|
||||
//LameXP includes
|
||||
#include "Resource.h"
|
||||
@ -107,6 +108,9 @@ static QSystemSemaphore *g_lamexp_semaphore_write_ptr = NULL;
|
||||
//Image formats
|
||||
static const char *g_lamexp_imageformats[] = {"png", "gif", "ico", "svg", NULL};
|
||||
|
||||
//Global locks
|
||||
static QMutex g_lamexp_message_mutex;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GLOBAL FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -172,6 +176,54 @@ const QDate &lamexp_version_date(void)
|
||||
return g_lamexp_version_date;
|
||||
}
|
||||
|
||||
/*
|
||||
* Qt message handler
|
||||
*/
|
||||
void lamexp_message_handler(QtMsgType type, const char *msg)
|
||||
{
|
||||
static HANDLE hConsole = NULL;
|
||||
QMutexLocker lock(&g_lamexp_message_mutex);
|
||||
|
||||
if(!hConsole)
|
||||
{
|
||||
hConsole = CreateFile(L"CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
|
||||
if(hConsole == INVALID_HANDLE_VALUE) hConsole = NULL;
|
||||
}
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
|
||||
GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case QtCriticalMsg:
|
||||
case QtFatalMsg:
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
fprintf(stderr, "\nCRITICAL ERROR !!!\n%s\n\n", msg);
|
||||
MessageBoxA(NULL, msg, "LameXP - CRITICAL ERROR", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fflush(stderr);
|
||||
break;
|
||||
default:
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fflush(stderr);
|
||||
break;
|
||||
}
|
||||
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
|
||||
|
||||
if(type == QtCriticalMsg || type == QtFatalMsg)
|
||||
{
|
||||
FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
|
||||
TerminateProcess(GetCurrentProcess(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the console
|
||||
*/
|
||||
|
@ -31,10 +31,11 @@
|
||||
//Win32
|
||||
#include <Windows.h>
|
||||
|
||||
//Class declarations
|
||||
//Declarations
|
||||
class QString;
|
||||
class LockedFile;
|
||||
class QDate;
|
||||
enum QtMsgType;
|
||||
|
||||
//Types definitions
|
||||
typedef struct
|
||||
@ -65,6 +66,7 @@ unsigned int lamexp_toolver_neroaac(void);
|
||||
void lamexp_init_console(int argc, char* argv[]);
|
||||
bool lamexp_init_qt(int argc, char* argv[]);
|
||||
int lamexp_init_ipc(void);
|
||||
void lamexp_message_handler(QtMsgType type, const char *msg);
|
||||
void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0);
|
||||
bool lamexp_check_tool(const QString &toolName);
|
||||
const QString lamexp_lookup_tool(const QString &toolName);
|
||||
|
49
src/Main.cpp
49
src/Main.cpp
@ -32,6 +32,7 @@
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QDate>
|
||||
#include <QMutex>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Main function
|
||||
@ -134,54 +135,6 @@ int lamexp_main(int argc, char* argv[])
|
||||
return iResult;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Message Handler
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void lamexp_message_handler(QtMsgType type, const char *msg)
|
||||
{
|
||||
static HANDLE hConsole = NULL;
|
||||
|
||||
if(!hConsole)
|
||||
{
|
||||
hConsole = CreateFile(L"CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
|
||||
}
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
|
||||
GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case QtCriticalMsg:
|
||||
case QtFatalMsg:
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
fprintf(stderr, "\nCRITICAL ERROR !!!\n%s\n\n", msg);
|
||||
MessageBoxA(NULL, msg, "LameXP - CRITICAL ERROR", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fflush(stderr);
|
||||
break;
|
||||
default:
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fflush(stderr);
|
||||
break;
|
||||
}
|
||||
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
|
||||
|
||||
if(type == QtCriticalMsg || type == QtFatalMsg)
|
||||
{
|
||||
FatalAppExit(0, L"The application has encountered a critical error and will exit now!");
|
||||
TerminateProcess(GetCurrentProcess(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Applicaton entry point
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -178,6 +178,7 @@ void InitializationThread::initNeroAac(void)
|
||||
{
|
||||
qWarning("Nero process failed to create!");
|
||||
qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData());
|
||||
qDebug("File '%s' does exist?\n%s\n!", neroFileInfo[0].canonicalFilePath().toUtf8().constData(), (neroFileInfo[0].exists() ? "Yes, it still exists" : "Nope, it disappeared"));
|
||||
process.kill();
|
||||
process.waitForFinished(-1);
|
||||
for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
|
||||
@ -223,7 +224,7 @@ void InitializationThread::initNeroAac(void)
|
||||
|
||||
if(!(neroVersion > 0))
|
||||
{
|
||||
qWarning("Nero AAC version could not be determined!", neroVersion);
|
||||
qWarning("Nero AAC version could not be determined -> AAC encoding support will be disabled!", neroVersion);
|
||||
for(int i = 0; i < 3; i++) LAMEXP_DELETE(neroBin[i]);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user