2010-11-06 23:04:47 +01:00
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
//LameXP includes
# include "Global.h"
# include "Dialog_SplashScreen.h"
# include "Dialog_MainWindow.h"
2010-11-17 19:35:50 +01:00
# include "Dialog_Processing.h"
2010-11-06 23:04:47 +01:00
# include "Thread_Initialization.h"
2010-11-09 22:06:11 +01:00
# include "Thread_MessageProducer.h"
2010-11-12 21:02:14 +01:00
# include "Model_Settings.h"
2010-11-06 23:04:47 +01:00
//Qt includes
# include <QApplication>
# include <QMessageBox>
# include <QDate>
2010-11-19 13:31:45 +01:00
# include <QMutex>
2010-11-06 23:04:47 +01:00
///////////////////////////////////////////////////////////////////////////////
// Main function
///////////////////////////////////////////////////////////////////////////////
int lamexp_main ( int argc , char * argv [ ] )
{
2010-11-09 22:06:11 +01:00
int iResult = - 1 ;
2010-11-07 23:06:30 +01:00
//Init console
lamexp_init_console ( argc , argv ) ;
2010-11-06 23:04:47 +01:00
//Print version info
2010-11-07 23:06:30 +01:00
qDebug ( " LameXP - Audio Encoder Front-End " ) ;
2010-11-06 23:04:47 +01:00
qDebug ( " Version %d.%02d %s, Build %d [%s], MSVC compiler v%02d.%02d " , lamexp_version_major ( ) , lamexp_version_minor ( ) , lamexp_version_release ( ) , lamexp_version_build ( ) , lamexp_version_date ( ) . toString ( Qt : : ISODate ) . toLatin1 ( ) . constData ( ) , _MSC_VER / 100 , _MSC_VER % 100 ) ;
2010-11-07 23:06:30 +01:00
qDebug ( " Copyright (C) 2004-%04d LoRd_MuldeR <MuldeR2@GMX.de> \n " , max ( lamexp_version_date ( ) . year ( ) , QDate : : currentDate ( ) . year ( ) ) ) ;
2010-11-06 23:04:47 +01:00
//print license info
qDebug ( " This program is free software: you can redistribute it and/or modify " ) ;
2010-11-08 00:24:54 +01:00
qDebug ( " it under the terms of the GNU General Public License <http://www.gnu.org/>. " ) ;
2010-11-06 23:04:47 +01:00
qDebug ( " This program comes with ABSOLUTELY NO WARRANTY. \n " ) ;
2010-11-13 02:11:15 +01:00
2010-11-06 23:04:47 +01:00
//Print warning, if this is a "debug" build
LAMEXP_CHECK_DEBUG_BUILD ;
2010-11-09 22:06:11 +01:00
2010-11-15 04:42:06 +01:00
//Detect CPU capabilities
lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features ( ) ;
qDebug ( " CPU brand string: %s " , cpuFeatures . brand ) ;
qDebug ( " CPU signature: Family: %d, Model: %d, Stepping: %d " , cpuFeatures . family , cpuFeatures . model , cpuFeatures . stepping ) ;
2010-11-15 14:02:58 +01:00
qDebug ( " CPU capabilities: MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s " , LAMEXP_BOOL ( cpuFeatures . mmx ) , LAMEXP_BOOL ( cpuFeatures . sse ) , LAMEXP_BOOL ( cpuFeatures . sse2 ) , LAMEXP_BOOL ( cpuFeatures . sse3 ) , LAMEXP_BOOL ( cpuFeatures . ssse3 ) , LAMEXP_BOOL ( cpuFeatures . x64 ) ) ;
qDebug ( " CPU no. of cores: %d \n " , cpuFeatures . count ) ;
2010-11-15 04:42:06 +01:00
2010-11-06 23:04:47 +01:00
//Initialize Qt
lamexp_init_qt ( argc , argv ) ;
//Check for expiration
if ( lamexp_version_demo ( ) )
{
QDate expireDate = lamexp_version_date ( ) . addDays ( 14 ) ;
qWarning ( QString ( " Note: This demo (pre-release) version of LameXP will expire at %1. \n " ) . arg ( expireDate . toString ( Qt : : ISODate ) ) . toLatin1 ( ) . constData ( ) ) ;
if ( QDate : : currentDate ( ) > = expireDate )
{
2010-11-12 21:02:14 +01:00
qWarning ( " Binary has expired !!! " ) ;
2010-11-07 23:06:30 +01:00
QMessageBox : : warning ( NULL , " LameXP - Expired " , QString ( " This demo (pre-release) version of LameXP has expired at %1. \n LameXP is free software and release versions won't expire. " ) . arg ( expireDate . toString ( ) ) , " Exit Program " ) ;
2010-11-06 23:04:47 +01:00
return 0 ;
}
}
2010-11-08 21:47:35 +01:00
//Check for multiple instances of LameXP
2010-11-09 22:06:11 +01:00
if ( ( iResult = lamexp_init_ipc ( ) ) ! = 0 )
2010-11-08 21:47:35 +01:00
{
qDebug ( " LameXP is already running, connecting to running instance... " ) ;
2010-11-09 22:06:11 +01:00
if ( iResult = = 1 )
{
MessageProducerThread * messageProducerThread = new MessageProducerThread ( ) ;
messageProducerThread - > start ( ) ;
if ( ! messageProducerThread - > wait ( 30000 ) )
{
messageProducerThread - > terminate ( ) ;
QMessageBox messageBox ( QMessageBox : : Critical , " LameXP " , " LameXP is already running, but the running instance doesn't respond! " , QMessageBox : : NoButton , NULL , Qt : : Dialog | Qt : : MSWindowsFixedSizeDialogHint | Qt : : WindowStaysOnTopHint ) ;
messageBox . exec ( ) ;
messageProducerThread - > wait ( ) ;
LAMEXP_DELETE ( messageProducerThread ) ;
return - 1 ;
}
LAMEXP_DELETE ( messageProducerThread ) ;
}
2010-11-08 21:47:35 +01:00
return 0 ;
}
2010-11-09 22:06:11 +01:00
//Kill application?
for ( int i = 0 ; i < argc ; i + + )
2010-11-08 21:47:35 +01:00
{
2010-11-09 22:06:11 +01:00
if ( ! _stricmp ( " --kill " , argv [ i ] ) | | ! _stricmp ( " --force-kill " , argv [ i ] ) )
{
return 0 ;
}
2010-11-08 21:47:35 +01:00
}
2010-11-06 23:04:47 +01:00
//Show splash screen
InitializationThread * poInitializationThread = new InitializationThread ( ) ;
SplashScreen : : showSplash ( poInitializationThread ) ;
LAMEXP_DELETE ( poInitializationThread ) ;
//Show main window
MainWindow * poMainWindow = new MainWindow ( ) ;
poMainWindow - > show ( ) ;
2010-11-08 21:47:35 +01:00
iResult = QApplication : : instance ( ) - > exec ( ) ;
2010-11-06 23:04:47 +01:00
LAMEXP_DELETE ( poMainWindow ) ;
2010-11-17 19:35:50 +01:00
//Show processing dialog
ProcessingDialog * processingDialog = new ProcessingDialog ( ) ;
processingDialog - > exec ( ) ;
LAMEXP_DELETE ( processingDialog ) ;
2010-11-06 23:04:47 +01:00
//Final clean-up
qDebug ( " Shutting down, please wait... \n " ) ;
2010-11-12 21:02:14 +01:00
2010-11-06 23:04:47 +01:00
//Terminate
return iResult ;
}
///////////////////////////////////////////////////////////////////////////////
// Applicaton entry point
///////////////////////////////////////////////////////////////////////////////
int main ( int argc , char * argv [ ] )
{
try
{
2010-11-07 16:32:54 +01:00
int iResult ;
2010-11-06 23:04:47 +01:00
qInstallMsgHandler ( lamexp_message_handler ) ;
2010-11-07 16:32:54 +01:00
LAMEXP_MEMORY_CHECK ( iResult = lamexp_main ( argc , argv ) ) ;
2010-11-06 23:04:47 +01:00
lamexp_finalization ( ) ;
return iResult ;
}
catch ( char * error )
{
fflush ( stdout ) ;
fflush ( stderr ) ;
fprintf ( stderr , " \n EXCEPTION ERROR: %s \n " , error ) ;
FatalAppExit ( 0 , L " Unhandeled exception error, application will exit! " ) ;
TerminateProcess ( GetCurrentProcess ( ) , - 1 ) ;
}
catch ( int error )
{
fflush ( stdout ) ;
fflush ( stderr ) ;
fprintf ( stderr , " \n EXCEPTION ERROR: Error code 0x%X \n " , error ) ;
FatalAppExit ( 0 , L " Unhandeled exception error, application will exit! " ) ;
TerminateProcess ( GetCurrentProcess ( ) , - 1 ) ;
}
catch ( . . . )
{
fflush ( stdout ) ;
fflush ( stderr ) ;
fprintf ( stderr , " \n EXCEPTION ERROR !!! \n " ) ;
FatalAppExit ( 0 , L " Unhandeled exception error, application will exit! " ) ;
TerminateProcess ( GetCurrentProcess ( ) , - 1 ) ;
}
}