2010-11-06 23:04:47 +01:00
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
2014-01-01 17:05:52 +01:00
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
2010-11-06 23:04:47 +01:00
//
// 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
2013-10-23 20:56:57 +02:00
// (at your option) any later version, but always including the *additional*
// restrictions defined in the "License.txt" file.
2010-11-06 23:04:47 +01:00
//
// 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-19 21:11:54 +01:00
# include "Model_FileList.h"
# include "Model_AudioFile.h"
2010-11-20 02:14:22 +01:00
# include "Encoder_Abstract.h"
2010-11-06 23:04:47 +01:00
2014-11-25 02:14:42 +01:00
//MUitls
# include <MUtils/Global.h>
# include <MUtils/OSSupport.h>
# include <MUtils/Version.h>
2014-11-25 03:15:03 +01:00
# include <MUtils/CPUFeatures.h>
2014-11-25 22:34:20 +01:00
# include <MUtils/Terminal.h>
2014-11-26 02:39:02 +01:00
# include <MUtils/Startup.h>
2014-12-13 23:27:47 +01:00
# include <MUtils/IPCChannel.h>
2014-11-25 02:14:42 +01:00
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-20 02:14:22 +01:00
# include <QDir>
2010-11-06 23:04:47 +01:00
2014-12-20 23:44:43 +01:00
//VLD
# ifdef _MSC_VER
# include <vld.h>
# endif
2010-11-06 23:04:47 +01:00
///////////////////////////////////////////////////////////////////////////////
2014-12-14 19:33:28 +01:00
// Helper functions
2010-11-06 23:04:47 +01:00
///////////////////////////////////////////////////////////////////////////////
2014-12-14 19:33:28 +01:00
static void lamexp_print_logo ( void )
2010-11-06 23:04:47 +01:00
{
//Print version info
2011-07-26 22:17:14 +02:00
qDebug ( " LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d) " , lamexp_version_major ( ) , lamexp_version_minor ( ) , lamexp_version_release ( ) , lamexp_version_build ( ) ) ;
2014-11-25 22:34:20 +01:00
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 ( " Built on %s at %s with %s for Win-%s. \n " , MUTILS_UTF8 ( MUtils : : Version : : app_build_date ( ) . toString ( Qt : : ISODate ) ) , MUTILS_UTF8 ( MUtils : : Version : : app_build_time ( ) . toString ( Qt : : ISODate ) ) , MUtils : : Version : : compiler_version ( ) , MUtils : : Version : : compiler_arch ( ) ) ;
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/>. " ) ;
2011-07-26 22:17:14 +02:00
qDebug ( " Note that this program is distributed with ABSOLUTELY NO WARRANTY. \n " ) ;
2010-11-13 02:11:15 +01:00
2014-11-25 22:34:20 +01:00
//Print library version
qDebug ( " This application is powerd by MUtils library v%u.%02u (%s, %s). \n " , MUtils : : Version : : lib_version_major ( ) , MUtils : : Version : : lib_version_minor ( ) , MUTILS_UTF8 ( MUtils : : Version : : lib_build_date ( ) . toString ( Qt : : ISODate ) ) , MUTILS_UTF8 ( MUtils : : Version : : lib_build_time ( ) . toString ( Qt : : ISODate ) ) ) ;
2014-12-14 19:33:28 +01:00
2010-11-06 23:04:47 +01:00
//Print warning, if this is a "debug" build
2014-11-25 02:14:42 +01:00
if ( MUTILS_DEBUG )
2011-04-14 01:40:11 +02:00
{
qWarning ( " --------------------------------------------------------- " ) ;
qWarning ( " DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!! " ) ;
2014-11-25 02:14:42 +01:00
qWarning ( " --------------------------------------------------------- \n " ) ;
2011-04-14 01:40:11 +02:00
}
2014-12-14 19:33:28 +01:00
}
static int lamexp_initialize_ipc ( MUtils : : IPCChannel * const ipcChannel )
{
int iResult = 0 ;
if ( ( iResult = ipcChannel - > initialize ( ) ) ! = MUtils : : IPCChannel : : RET_SUCCESS_MASTER )
{
if ( iResult = = MUtils : : IPCChannel : : RET_SUCCESS_SLAVE )
{
qDebug ( " LameXP is already running, connecting to running instance... " ) ;
QScopedPointer < MessageProducerThread > messageProducerThread ( new MessageProducerThread ( ipcChannel ) ) ;
messageProducerThread - > start ( ) ;
if ( ! messageProducerThread - > wait ( 30000 ) )
{
qWarning ( " MessageProducer thread has encountered timeout -> going to kill! " ) ;
messageProducerThread - > terminate ( ) ;
messageProducerThread - > wait ( ) ;
MUtils : : OS : : system_message_err ( L " LameXP " , L " LameXP is already running, but the running instance doesn't respond! " ) ;
return - 1 ;
}
return 0 ;
}
else
{
qFatal ( " The IPC initialization has failed! " ) ;
return - 1 ;
}
}
return 1 ;
}
static void lamexp_show_splash ( const MUtils : : CPUFetaures : : cpu_info_t & cpuFeatures , SettingsModel * const settingsModel )
{
QScopedPointer < InitializationThread > poInitializationThread ( new InitializationThread ( cpuFeatures ) ) ;
SplashScreen : : showSplash ( poInitializationThread . data ( ) ) ;
settingsModel - > slowStartup ( poInitializationThread - > getSlowIndicator ( ) ) ;
}
2014-12-20 23:44:43 +01:00
static int lamexp_main_loop ( const MUtils : : CPUFetaures : : cpu_info_t & cpuFeatures , MUtils : : IPCChannel * const ipcChannel , int & iShutdown )
2014-12-14 19:33:28 +01:00
{
int iResult = - 1 ;
bool bAccepted = true ;
2014-12-20 23:44:43 +01:00
//Create models
QScopedPointer < FileListModel > fileListModel ( new FileListModel ( ) ) ;
QScopedPointer < AudioFileModel_MetaInfo > metaInfo ( new AudioFileModel_MetaInfo ( ) ) ;
QScopedPointer < SettingsModel > settingsModel ( new SettingsModel ( ) ) ;
//Show splash screen
lamexp_show_splash ( cpuFeatures , settingsModel . data ( ) ) ;
//Validate settings
settingsModel - > validate ( ) ;
2014-12-14 19:33:28 +01:00
//Create main window
2014-12-20 23:44:43 +01:00
QScopedPointer < MainWindow > poMainWindow ( new MainWindow ( ipcChannel , fileListModel . data ( ) , metaInfo . data ( ) , settingsModel . data ( ) ) ) ;
2014-12-14 19:33:28 +01:00
//Main application loop
while ( bAccepted & & ( iShutdown < = SHUTDOWN_FLAG_NONE ) )
{
//Show main window
poMainWindow - > show ( ) ;
iResult = qApp - > exec ( ) ;
bAccepted = poMainWindow - > isAccepted ( ) ;
//Sync settings
settingsModel - > syncNow ( ) ;
//Show processing dialog
if ( bAccepted & & ( fileListModel - > rowCount ( ) > 0 ) )
{
2014-12-20 23:44:43 +01:00
ProcessingDialog * processingDialog = new ProcessingDialog ( fileListModel . data ( ) , metaInfo . data ( ) , settingsModel . data ( ) ) ;
2014-12-14 19:33:28 +01:00
processingDialog - > exec ( ) ;
iShutdown = processingDialog - > getShutdownFlag ( ) ;
MUTILS_DELETE ( processingDialog ) ;
}
}
return iResult ;
}
///////////////////////////////////////////////////////////////////////////////
// Main function
///////////////////////////////////////////////////////////////////////////////
static int lamexp_main ( int & argc , char * * argv )
{
int iResult = - 1 ;
int iShutdown = SHUTDOWN_FLAG_NONE ;
2010-11-09 22:06:11 +01:00
2014-12-14 19:33:28 +01:00
//Print logo
lamexp_print_logo ( ) ;
2014-11-26 02:39:02 +01:00
//Get CLI arguments
const QStringList & arguments = MUtils : : OS : : arguments ( ) ;
2012-06-21 18:31:36 +02:00
//Enumerate CLI arguments
qDebug ( " Command-Line Arguments: " ) ;
2012-06-22 15:49:56 +02:00
for ( int i = 0 ; i < arguments . count ( ) ; i + + )
2012-06-21 18:31:36 +02:00
{
2014-11-25 02:14:42 +01:00
qDebug ( " argv[%d]=%s " , i , MUTILS_UTF8 ( arguments . at ( i ) ) ) ;
2012-06-21 18:31:36 +02:00
}
2014-11-25 22:34:20 +01:00
qDebug ( " " ) ;
2012-06-21 18:31:36 +02:00
2010-11-15 04:42:06 +01:00
//Detect CPU capabilities
2014-11-25 22:34:20 +01:00
const MUtils : : CPUFetaures : : cpu_info_t cpuFeatures = MUtils : : CPUFetaures : : detect ( MUtils : : OS : : arguments ( ) ) ;
2014-11-25 03:15:03 +01:00
qDebug ( " CPU vendor id : %s (Intel=%s) " , cpuFeatures . vendor , MUTILS_BOOL2STR ( cpuFeatures . intel ) ) ;
2010-11-20 22:14:10 +01:00
qDebug ( " CPU brand string : %s " , cpuFeatures . brand ) ;
2014-11-25 03:15:03 +01:00
qDebug ( " CPU signature : Family=%d Model=%d Stepping=%d " , cpuFeatures . family , cpuFeatures . model , cpuFeatures . stepping ) ;
qDebug ( " CPU capabilities : MMX=%s SSE=%s SSE2=%s SSE3=%s SSSE3=%s SSE4=%s SSE4.2=%s x64=%s " , MUTILS_BOOL2STR ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_MMX ) , MUTILS_BOOL2STR ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSE ) , MUTILS_BOOL2STR ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSE2 ) , MUTILS_BOOL2STR ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSE3 ) , MUTILS_BOOL2STR ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSSE3 ) , MUTILS_BOOL2STR ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSE4 ) , MUTILS_BOOL2STR ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSE42 ) , MUTILS_BOOL2STR ( cpuFeatures . x64 ) ) ;
2010-11-24 21:00:59 +01:00
qDebug ( " Number of CPU's : %d \n " , cpuFeatures . count ) ;
2012-12-10 23:35:14 +01:00
2010-11-06 23:04:47 +01:00
//Initialize Qt
2014-12-20 23:44:43 +01:00
QScopedPointer < QApplication > application ( MUtils : : Startup : : create_qt ( argc , argv , QLatin1String ( " LameXP - Audio Encoder Front-End " ) ) ) ;
if ( application . isNull ( ) )
2010-12-27 01:50:22 +01:00
{
2014-12-13 23:27:47 +01:00
return EXIT_FAILURE ;
2010-12-27 01:50:22 +01:00
}
2010-11-21 21:51:22 +01:00
2014-11-29 01:25:18 +01:00
//Initialize application
2014-12-20 23:44:43 +01:00
application - > setWindowIcon ( lamexp_app_icon ( ) ) ;
application - > setApplicationVersion ( QString ( ) . sprintf ( " %d.%02d.%04d " , lamexp_version_major ( ) , lamexp_version_minor ( ) , lamexp_version_build ( ) ) ) ;
2014-11-29 01:25:18 +01:00
2010-11-06 23:04:47 +01:00
//Check for expiration
if ( lamexp_version_demo ( ) )
{
2014-11-25 02:14:42 +01:00
const QDate currentDate = MUtils : : OS : : current_date ( ) ;
2014-11-25 22:34:20 +01:00
if ( currentDate . addDays ( 1 ) < MUtils : : Version : : app_build_date ( ) )
2011-12-25 22:29:04 +01:00
{
2014-11-25 22:34:20 +01:00
qFatal ( " System's date (%s) is before LameXP build date (%s). Huh? " , currentDate . toString ( Qt : : ISODate ) . toLatin1 ( ) . constData ( ) , MUtils : : Version : : app_build_date ( ) . toString ( Qt : : ISODate ) . toLatin1 ( ) . constData ( ) ) ;
2011-12-25 22:29:04 +01:00
}
2011-01-20 22:06:59 +01:00
qWarning ( QString ( " Note: This demo (pre-release) version of LameXP will expire at %1. \n " ) . arg ( lamexp_version_expires ( ) . toString ( Qt : : ISODate ) ) . toLatin1 ( ) . constData ( ) ) ;
2010-11-06 23:04:47 +01:00
}
2014-12-13 23:27:47 +01:00
//Initialize IPC
2014-12-14 19:33:28 +01:00
QScopedPointer < MUtils : : IPCChannel > ipcChannel ( new MUtils : : IPCChannel ( " lamexp-v4 " , lamexp_version_build ( ) , " instance " ) ) ;
if ( ( iResult = lamexp_initialize_ipc ( ipcChannel . data ( ) ) ) < 1 )
2010-11-08 21:47:35 +01:00
{
2014-12-14 19:33:28 +01:00
return ( iResult = = 0 ) ? EXIT_SUCCESS : EXIT_FAILURE ;
2010-11-08 21:47:35 +01:00
}
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
{
2012-06-23 18:18:57 +02:00
if ( ! arguments [ i ] . compare ( " --kill " , Qt : : CaseInsensitive ) | | ! arguments [ i ] . compare ( " --force-kill " , Qt : : CaseInsensitive ) )
2010-11-09 22:06:11 +01:00
{
2014-12-13 23:27:47 +01:00
return EXIT_SUCCESS ;
2010-11-09 22:06:11 +01:00
}
2010-11-08 21:47:35 +01:00
}
2010-11-06 23:04:47 +01:00
2011-10-19 00:24:03 +02:00
//Self-test
2014-11-25 02:14:42 +01:00
if ( MUTILS_DEBUG )
2011-10-19 00:24:03 +02:00
{
InitializationThread : : selfTest ( ) ;
}
2010-11-20 22:14:10 +01:00
//Main application loop
2014-12-14 19:33:28 +01:00
iResult = lamexp_main_loop ( cpuFeatures , ipcChannel . data ( ) , iShutdown ) ;
2011-02-07 22:01:06 +01:00
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
2011-03-18 01:12:17 +01:00
//Shotdown computer
2014-12-14 19:33:28 +01:00
if ( iShutdown > SHUTDOWN_FLAG_NONE )
2011-03-18 01:12:17 +01:00
{
2014-12-14 19:33:28 +01:00
if ( ! MUtils : : OS : : shutdown_computer ( QApplication : : applicationFilePath ( ) , 12 , true , ( iShutdown = = SHUTDOWN_FLAG_HIBERNATE ) ) )
2011-03-18 01:12:17 +01:00
{
QMessageBox messageBox ( QMessageBox : : Critical , " LameXP " , " Sorry, LameXP was unable to shutdown your computer! " , QMessageBox : : NoButton , NULL , Qt : : Dialog | Qt : : MSWindowsFixedSizeDialogHint | Qt : : WindowStaysOnTopHint ) ;
}
}
2010-11-06 23:04:47 +01:00
//Terminate
return iResult ;
}
///////////////////////////////////////////////////////////////////////////////
// Applicaton entry point
///////////////////////////////////////////////////////////////////////////////
2011-06-22 01:10:53 +02:00
int main ( int argc , char * argv [ ] )
2011-03-04 23:40:09 +01:00
{
2014-12-04 22:59:30 +01:00
return MUtils : : Startup : : startup ( argc , argv , lamexp_main , lamexp_version_demo ( ) ) ;
2011-03-05 01:56:00 +01:00
}