Moved startup and error handling routines into MUtilities library.
This commit is contained in:
parent
29d8b98a3f
commit
a2f1885717
@ -146,7 +146,6 @@ copy /Y "$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\bin\Win32\*.manifes
|
|||||||
<CreateHotpatchableImage>false</CreateHotpatchableImage>
|
<CreateHotpatchableImage>false</CreateHotpatchableImage>
|
||||||
<MultiProcessorCompilation>false</MultiProcessorCompilation>
|
<MultiProcessorCompilation>false</MultiProcessorCompilation>
|
||||||
<OpenMPSupport>false</OpenMPSupport>
|
<OpenMPSupport>false</OpenMPSupport>
|
||||||
<DebugInformationFormat>None</DebugInformationFormat>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
<CompileAsManaged>false</CompileAsManaged>
|
<CompileAsManaged>false</CompileAsManaged>
|
||||||
<AdditionalOptions>/wd4005 %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/wd4005 %(AdditionalOptions)</AdditionalOptions>
|
||||||
@ -178,7 +177,6 @@ copy /Y "$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\bin\Win32\*.manifes
|
|||||||
</CreateHotPatchableImage>
|
</CreateHotPatchableImage>
|
||||||
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(QTDIR)\plugins\imageformats;$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\lib\Win32;$(SolutionDir)\etc\Prerequisites\keccak\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(QTDIR)\plugins\imageformats;$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\lib\Win32;$(SolutionDir)\etc\Prerequisites\keccak\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
<TreatLinkerWarningAsErrors>true</TreatLinkerWarningAsErrors>
|
||||||
<ProgramDatabaseFile />
|
|
||||||
</Link>
|
</Link>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
<Message>Copy plugin DLL%27s</Message>
|
<Message>Copy plugin DLL%27s</Message>
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
#define VER_LAMEXP_MINOR_HI 1
|
#define VER_LAMEXP_MINOR_HI 1
|
||||||
#define VER_LAMEXP_MINOR_LO 1
|
#define VER_LAMEXP_MINOR_LO 1
|
||||||
#define VER_LAMEXP_TYPE Beta
|
#define VER_LAMEXP_TYPE Beta
|
||||||
#define VER_LAMEXP_PATCH 1
|
#define VER_LAMEXP_PATCH 2
|
||||||
#define VER_LAMEXP_BUILD 1597
|
#define VER_LAMEXP_BUILD 1600
|
||||||
#define VER_LAMEXP_CONFG 1558
|
#define VER_LAMEXP_CONFG 1558
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -115,18 +115,15 @@ bool lamexp_exec_shell(const QWidget *win, const QString &url, const QString &pa
|
|||||||
void lamexp_finalization(void);
|
void lamexp_finalization(void);
|
||||||
unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok = NULL);
|
unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok = NULL);
|
||||||
void lamexp_free_window_icon(lamexp_icon_t *icon);
|
void lamexp_free_window_icon(lamexp_icon_t *icon);
|
||||||
void lamexp_init_error_handlers(void);
|
|
||||||
int lamexp_init_ipc(void);
|
int lamexp_init_ipc(void);
|
||||||
bool lamexp_init_qt(int argc, char* argv[]);
|
bool lamexp_init_qt(int argc, char* argv[]);
|
||||||
bool lamexp_install_translator(const QString &language);
|
bool lamexp_install_translator(const QString &language);
|
||||||
bool lamexp_install_translator_from_file(const QString &qmFile);
|
bool lamexp_install_translator_from_file(const QString &qmFile);
|
||||||
void lamexp_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
|
|
||||||
void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
|
void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
|
||||||
void lamexp_ipc_send(unsigned int command, const char* message);
|
void lamexp_ipc_send(unsigned int command, const char* message);
|
||||||
bool lamexp_is_executable(const QString &path);
|
bool lamexp_is_executable(const QString &path);
|
||||||
bool lamexp_is_hibernation_supported(void);
|
bool lamexp_is_hibernation_supported(void);
|
||||||
const QString lamexp_lookup_tool(const QString &toolName);
|
const QString lamexp_lookup_tool(const QString &toolName);
|
||||||
void lamexp_message_handler(QtMsgType type, const char *msg);
|
|
||||||
const char *lamexp_mulders_url(void);
|
const char *lamexp_mulders_url(void);
|
||||||
void lamexp_natural_string_sort(QStringList &list, const bool bIgnoreCase);
|
void lamexp_natural_string_sort(QStringList &list, const bool bIgnoreCase);
|
||||||
int lamexp_network_status(void);
|
int lamexp_network_status(void);
|
||||||
|
@ -190,73 +190,12 @@ bool lamexp_detect_wine(void)
|
|||||||
return g_lamexp_wine.bIsWine;
|
return g_lamexp_wine.bIsWine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Qt message handler
|
|
||||||
*/
|
|
||||||
void lamexp_message_handler(QtMsgType type, const char *msg)
|
|
||||||
{
|
|
||||||
if((!msg) || (!(msg[0])))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MUtils::Terminal::write(type, msg);
|
|
||||||
|
|
||||||
if((type == QtCriticalMsg) || (type == QtFatalMsg))
|
|
||||||
{
|
|
||||||
MUtils::OS::fatal_exit(MUTILS_WCHR(QString::fromUtf8(msg)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Invalid parameters handler
|
|
||||||
*/
|
|
||||||
static void lamexp_invalid_param_handler(const wchar_t* exp, const wchar_t* fun, const wchar_t* fil, unsigned int, uintptr_t)
|
|
||||||
{
|
|
||||||
MUtils::OS::fatal_exit(L"Invalid parameter handler invoked, application will exit!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Signal handler
|
|
||||||
*/
|
|
||||||
static void lamexp_signal_handler(int signal_num)
|
|
||||||
{
|
|
||||||
signal(signal_num, lamexp_signal_handler);
|
|
||||||
MUtils::OS::fatal_exit(L"Signal handler invoked, application will exit!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Global exception handler
|
|
||||||
*/
|
|
||||||
static LONG WINAPI lamexp_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo)
|
|
||||||
{
|
|
||||||
MUtils::OS::fatal_exit(L"Unhandeled exception handler invoked, application will exit!");
|
|
||||||
return LONG_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialize error handlers
|
|
||||||
*/
|
|
||||||
void lamexp_init_error_handlers(void)
|
|
||||||
{
|
|
||||||
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
|
||||||
SetUnhandledExceptionFilter(lamexp_exception_handler);
|
|
||||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
|
|
||||||
_set_invalid_parameter_handler(lamexp_invalid_param_handler);
|
|
||||||
|
|
||||||
static const int signal_num[6] = { SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
|
|
||||||
|
|
||||||
for(size_t i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
signal(signal_num[i], lamexp_signal_handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for debugger (detect routine)
|
* Check for debugger (detect routine)
|
||||||
*/
|
*/
|
||||||
static __forceinline bool lamexp_check_for_debugger(void)
|
static __forceinline bool lamexp_check_for_debugger(void)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
CloseHandle((HANDLE)((DWORD_PTR)-3));
|
CloseHandle((HANDLE)((DWORD_PTR)-3));
|
||||||
|
70
src/Main.cpp
70
src/Main.cpp
@ -39,6 +39,7 @@
|
|||||||
#include <MUtils/Version.h>
|
#include <MUtils/Version.h>
|
||||||
#include <MUtils/CPUFeatures.h>
|
#include <MUtils/CPUFeatures.h>
|
||||||
#include <MUtils/Terminal.h>
|
#include <MUtils/Terminal.h>
|
||||||
|
#include <MUtils/Startup.h>
|
||||||
|
|
||||||
//Qt includes
|
//Qt includes
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -51,18 +52,12 @@
|
|||||||
// Main function
|
// Main function
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static int lamexp_main(int argc, char* argv[])
|
static int lamexp_main(int &argc, char **argv)
|
||||||
{
|
{
|
||||||
int iResult = -1;
|
int iResult = -1;
|
||||||
int iShutdown = shutdownFlag_None;
|
int iShutdown = shutdownFlag_None;
|
||||||
bool bAccepted = true;
|
bool bAccepted = true;
|
||||||
|
|
||||||
//Get CLI arguments
|
|
||||||
const QStringList &arguments = MUtils::OS::arguments();
|
|
||||||
|
|
||||||
//Init console
|
|
||||||
MUtils::Terminal::setup(arguments, MUTILS_DEBUG || lamexp_version_demo());
|
|
||||||
|
|
||||||
//Print version info
|
//Print version info
|
||||||
qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
|
qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
|
||||||
qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(MUtils::Version::app_build_date().year(), MUtils::OS::current_date().year()));
|
qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(MUtils::Version::app_build_date().year(), MUtils::OS::current_date().year()));
|
||||||
@ -84,6 +79,9 @@ static int lamexp_main(int argc, char* argv[])
|
|||||||
qWarning("---------------------------------------------------------\n");
|
qWarning("---------------------------------------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get CLI arguments
|
||||||
|
const QStringList &arguments = MUtils::OS::arguments();
|
||||||
|
|
||||||
//Enumerate CLI arguments
|
//Enumerate CLI arguments
|
||||||
qDebug("Command-Line Arguments:");
|
qDebug("Command-Line Arguments:");
|
||||||
for(int i = 0; i < arguments.count(); i++)
|
for(int i = 0; i < arguments.count(); i++)
|
||||||
@ -103,6 +101,7 @@ static int lamexp_main(int argc, char* argv[])
|
|||||||
//Initialize Qt
|
//Initialize Qt
|
||||||
if(!lamexp_init_qt(argc, argv))
|
if(!lamexp_init_qt(argc, argv))
|
||||||
{
|
{
|
||||||
|
lamexp_finalization();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +131,12 @@ static int lamexp_main(int argc, char* argv[])
|
|||||||
messageBox.exec();
|
messageBox.exec();
|
||||||
messageProducerThread->wait();
|
messageProducerThread->wait();
|
||||||
MUTILS_DELETE(messageProducerThread);
|
MUTILS_DELETE(messageProducerThread);
|
||||||
|
lamexp_finalization();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
MUTILS_DELETE(messageProducerThread);
|
MUTILS_DELETE(messageProducerThread);
|
||||||
}
|
}
|
||||||
|
lamexp_finalization();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,6 +145,7 @@ static int lamexp_main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
|
lamexp_finalization();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,6 +219,7 @@ static int lamexp_main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Terminate
|
//Terminate
|
||||||
|
lamexp_finalization();
|
||||||
return iResult;
|
return iResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,58 +227,7 @@ static int lamexp_main(int argc, char* argv[])
|
|||||||
// Applicaton entry point
|
// Applicaton entry point
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static int _main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
if(MUTILS_DEBUG)
|
|
||||||
{
|
|
||||||
int iResult = -1;
|
|
||||||
qInstallMsgHandler(lamexp_message_handler);
|
|
||||||
iResult = lamexp_main(argc, argv);
|
|
||||||
lamexp_finalization();
|
|
||||||
return iResult;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int iResult = -1;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
qInstallMsgHandler(lamexp_message_handler);
|
|
||||||
iResult = lamexp_main(argc, argv);
|
|
||||||
lamexp_finalization();
|
|
||||||
}
|
|
||||||
catch(const std::exception &error)
|
|
||||||
{
|
|
||||||
PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error.what());
|
|
||||||
MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
|
|
||||||
MUtils::OS::fatal_exit(L"Unhandeled C++ exception error, application will exit!");
|
|
||||||
}
|
|
||||||
return iResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if(MUTILS_DEBUG)
|
return MUtils::Startup::startup(argc, argv, lamexp_main);
|
||||||
{
|
|
||||||
int exit_code = -1;
|
|
||||||
LAMEXP_MEMORY_CHECK(_main, exit_code, argc, argv);
|
|
||||||
return exit_code;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
__try
|
|
||||||
{
|
|
||||||
lamexp_init_error_handlers();
|
|
||||||
return _main(argc, argv);
|
|
||||||
}
|
|
||||||
__except(1)
|
|
||||||
{
|
|
||||||
PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnhandeled structured exception error!\n");
|
|
||||||
MUtils::OS::fatal_exit(L"Unhandeled structured exception error, application will exit!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user