2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
2014-01-27 19:58:24 +01:00
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
2012-01-28 16:40:14 +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
// (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
///////////////////////////////////////////////////////////////////////////////
# include "global.h"
# include "win_main.h"
2014-02-01 19:19:06 +01:00
# include "cli.h"
2014-01-27 20:21:29 +01:00
# include "ipc.h"
2012-02-08 00:29:47 +01:00
# include "taskbar7.h"
2012-01-28 16:40:14 +01:00
//Qt includes
2013-11-14 02:29:18 +01:00
# include <QApplication>
2012-01-28 16:40:14 +01:00
# include <QDate>
2012-01-28 18:55:40 +01:00
# include <QPlastiqueStyle>
2012-01-28 16:40:14 +01:00
2013-11-03 18:34:20 +01:00
//Windows includes
# define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
2014-01-27 20:21:29 +01:00
//Forward declaration
2014-02-01 19:19:06 +01:00
void handleMultipleInstances ( const QStringList & args , IPC * ipc ) ;
2014-01-27 20:21:29 +01:00
2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Main function
///////////////////////////////////////////////////////////////////////////////
static int x264_main ( int argc , char * argv [ ] )
{
2014-02-01 20:21:24 +01:00
//Get CLI arguments
const QStringList & arguments = x264_arguments ( ) ;
2012-01-28 16:40:14 +01:00
//Init console
2014-02-01 20:21:24 +01:00
x264_init_console ( arguments ) ;
2012-01-28 16:40:14 +01:00
//Print version info
2012-02-11 00:19:24 +01:00
qDebug ( " Simple x264 Launcher v%u.%02u.%u - use 64-Bit x264 with 32-Bit Avisynth " , x264_version_major ( ) , x264_version_minor ( ) , x264_version_build ( ) ) ;
2012-01-28 16:40:14 +01:00
qDebug ( " Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved. " , qMax ( x264_version_date ( ) . year ( ) , QDate : : currentDate ( ) . year ( ) ) ) ;
qDebug ( " Built on %s at %s with %s for Win-%s. \n " , x264_version_date ( ) . toString ( Qt : : ISODate ) . toLatin1 ( ) . constData ( ) , x264_version_time ( ) , x264_version_compiler ( ) , x264_version_arch ( ) ) ;
//print license info
qDebug ( " This program is free software: you can redistribute it and/or modify " ) ;
qDebug ( " it under the terms of the GNU General Public License <http://www.gnu.org/>. " ) ;
qDebug ( " Note that this program is distributed with ABSOLUTELY NO WARRANTY. \n " ) ;
//Print warning, if this is a "debug" build
if ( X264_DEBUG )
{
qWarning ( " --------------------------------------------------------- " ) ;
qWarning ( " DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!! " ) ;
qWarning ( " --------------------------------------------------------- \n " ) ;
}
//Detect CPU capabilities
2013-11-03 17:08:02 +01:00
const x264_cpu_t cpuFeatures = x264_detect_cpu_features ( arguments ) ;
2012-01-28 16:40:14 +01:00
qDebug ( " CPU vendor id : %s (Intel: %s) " , cpuFeatures . vendor , X264_BOOL ( cpuFeatures . intel ) ) ;
qDebug ( " CPU brand string : %s " , cpuFeatures . brand ) ;
qDebug ( " CPU signature : Family: %d, Model: %d, Stepping: %d " , cpuFeatures . family , cpuFeatures . model , cpuFeatures . stepping ) ;
2012-02-07 03:37:47 +01:00
qDebug ( " CPU capabilities : MMX=%s, MMXEXT=%s, SSE=%s, SSE2=%s, SSE3=%s, SSSE3=%s, X64=%s " , X264_BOOL ( cpuFeatures . mmx ) , X264_BOOL ( cpuFeatures . mmx2 ) , X264_BOOL ( cpuFeatures . sse ) , X264_BOOL ( cpuFeatures . sse2 ) , X264_BOOL ( cpuFeatures . sse3 ) , X264_BOOL ( cpuFeatures . ssse3 ) , X264_BOOL ( cpuFeatures . x64 ) ) ;
2012-01-28 16:40:14 +01:00
qDebug ( " Number of CPU's : %d \n " , cpuFeatures . count ) ;
2012-02-06 22:40:07 +01:00
2014-01-27 20:21:29 +01:00
//Initialize the IPC handler class
bool firstInstance = false ;
IPC * ipc = new IPC ( ) ;
2014-01-27 20:34:59 +01:00
if ( ipc - > initialize ( firstInstance ) )
2014-01-27 20:21:29 +01:00
{
if ( ! firstInstance )
{
2014-01-27 21:54:24 +01:00
qDebug ( " This is *not* the fist instance -> sending all CLI commands to first instance! " ) ;
2014-01-27 20:21:29 +01:00
handleMultipleInstances ( arguments , ipc ) ;
X264_DELETE ( ipc ) ;
return 0 ;
}
}
else
{
qWarning ( " IPC initialization has failed! " ) ;
}
2012-01-28 16:40:14 +01:00
//Initialize Qt
if ( ! x264_init_qt ( argc , argv ) )
{
return - 1 ;
}
2012-02-08 00:29:47 +01:00
2012-02-10 01:58:45 +01:00
//Running in portable mode?
if ( x264_portable ( ) )
{
qDebug ( " Application is running in portable mode! \n " ) ;
}
2012-02-08 00:29:47 +01:00
//Taskbar init
WinSevenTaskbar : : init ( ) ;
2012-01-28 16:40:14 +01:00
2012-01-28 18:55:40 +01:00
//Set style
2014-02-01 20:21:24 +01:00
if ( ! CLIParser : : checkFlag ( CLI_PARAM_NO_GUI_STYLE , arguments ) )
2012-02-08 22:50:36 +01:00
{
qApp - > setStyle ( new QPlastiqueStyle ( ) ) ;
}
2012-01-28 18:55:40 +01:00
//Create Main Window
2014-01-27 21:54:24 +01:00
MainWindow * mainWin = new MainWindow ( & cpuFeatures , ipc ) ;
2012-01-28 16:40:14 +01:00
mainWin - > show ( ) ;
2012-01-28 18:55:40 +01:00
//Run application
2012-01-28 16:40:14 +01:00
int ret = qApp - > exec ( ) ;
2012-02-08 00:29:47 +01:00
//Taskbar uninit
WinSevenTaskbar : : init ( ) ;
2012-01-28 18:55:40 +01:00
2014-01-27 20:34:59 +01:00
//Clean up
2012-01-28 16:40:14 +01:00
X264_DELETE ( mainWin ) ;
2014-01-27 20:34:59 +01:00
X264_DELETE ( ipc ) ;
2012-01-28 16:40:14 +01:00
return ret ;
}
2014-01-27 20:21:29 +01:00
///////////////////////////////////////////////////////////////////////////////
// Multi-instance handler
///////////////////////////////////////////////////////////////////////////////
2014-02-01 19:19:06 +01:00
void handleMultipleInstances ( const QStringList & args , IPC * ipc )
2014-01-27 20:21:29 +01:00
{
bool commandSent = false ;
2014-02-01 15:34:11 +01:00
unsigned int flags = 0 ;
2014-01-27 20:21:29 +01:00
2014-02-01 19:19:06 +01:00
//Initialize command-line parser
CLIParser parser ( args ) ;
int identifier ;
QStringList options ;
2014-01-27 21:54:24 +01:00
2014-01-27 20:21:29 +01:00
//Process all command-line arguments
2014-02-01 19:19:06 +01:00
while ( parser . nextOption ( identifier , & options ) )
2014-01-27 20:21:29 +01:00
{
2014-02-01 19:19:06 +01:00
switch ( identifier )
2014-01-27 20:21:29 +01:00
{
2014-02-01 19:19:06 +01:00
case CLI_PARAM_ADD_FILE :
ipc - > sendAsync ( IPC_OPCODE_ADD_FILE , options , flags ) ;
2014-01-27 21:54:24 +01:00
commandSent = true ;
2014-02-01 19:19:06 +01:00
break ;
case CLI_PARAM_ADD_JOB :
ipc - > sendAsync ( IPC_OPCODE_ADD_JOB , options , flags ) ;
2014-01-27 21:54:24 +01:00
commandSent = true ;
2014-02-01 15:34:11 +01:00
break ;
2014-02-01 19:19:06 +01:00
case CLI_PARAM_FORCE_START :
flags = ( ( flags | IPC_FLAG_FORCE_START ) & ( ~ IPC_FLAG_FORCE_ENQUEUE ) ) ;
break ;
case CLI_PARAM_NO_FORCE_START :
flags = ( flags & ( ~ IPC_FLAG_FORCE_START ) ) ;
break ;
case CLI_PARAM_FORCE_ENQUEUE :
flags = ( ( flags | IPC_FLAG_FORCE_ENQUEUE ) & ( ~ IPC_FLAG_FORCE_START ) ) ;
break ;
case CLI_PARAM_NO_FORCE_ENQUEUE :
flags = ( flags & ( ~ IPC_FLAG_FORCE_ENQUEUE ) ) ;
break ;
2014-01-27 20:34:59 +01:00
}
2014-01-27 20:21:29 +01:00
}
//If no argument has been sent yet, send a ping!
if ( ! commandSent )
{
2014-01-29 23:59:03 +01:00
ipc - > sendAsync ( IPC_OPCODE_PING , QStringList ( ) ) ;
2014-01-27 20:21:29 +01:00
}
}
2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Applicaton entry point
///////////////////////////////////////////////////////////////////////////////
2013-11-03 18:34:20 +01:00
LONG WINAPI x264_exception_handler ( __in struct _EXCEPTION_POINTERS * ExceptionInfo ) ;
void x264_invalid_param_handler ( const wchar_t * , const wchar_t * , const wchar_t * , unsigned int , uintptr_t ) ;
2012-01-28 16:40:14 +01:00
static int _main ( int argc , char * argv [ ] )
{
if ( X264_DEBUG )
{
int iResult = - 1 ;
qInstallMsgHandler ( x264_message_handler ) ;
2012-04-30 16:56:01 +02:00
X264_MEMORY_CHECK ( x264_main , iResult , argc , argv ) ;
2012-01-28 16:40:14 +01:00
x264_finalization ( ) ;
return iResult ;
}
else
{
int iResult = - 1 ;
try
{
qInstallMsgHandler ( x264_message_handler ) ;
iResult = x264_main ( argc , argv ) ;
x264_finalization ( ) ;
}
catch ( char * error )
{
fflush ( stdout ) ;
fflush ( stderr ) ;
fprintf ( stderr , " \n GURU MEDITATION !!! \n \n Exception error message: %s \n " , error ) ;
2012-12-15 19:12:56 +01:00
x264_fatal_exit ( L " Unhandeled C++ exception error, application will exit! " ) ;
2012-01-28 16:40:14 +01:00
}
catch ( int error )
{
fflush ( stdout ) ;
fflush ( stderr ) ;
fprintf ( stderr , " \n GURU MEDITATION !!! \n \n Exception error code: 0x%X \n " , error ) ;
2012-12-15 19:12:56 +01:00
x264_fatal_exit ( L " Unhandeled C++ exception error, application will exit! " ) ;
2012-01-28 16:40:14 +01:00
}
catch ( . . . )
{
fflush ( stdout ) ;
fflush ( stderr ) ;
fprintf ( stderr , " \n GURU MEDITATION !!! \n " ) ;
2012-12-15 19:12:56 +01:00
x264_fatal_exit ( L " Unhandeled C++ exception error, application will exit! " ) ;
2012-01-28 16:40:14 +01:00
}
return iResult ;
}
}
int main ( int argc , char * argv [ ] )
{
if ( X264_DEBUG )
{
return _main ( argc , argv ) ;
}
else
{
__try
{
SetUnhandledExceptionFilter ( x264_exception_handler ) ;
_set_invalid_parameter_handler ( x264_invalid_param_handler ) ;
return _main ( argc , argv ) ;
}
__except ( 1 )
{
fflush ( stdout ) ;
fflush ( stderr ) ;
fprintf ( stderr , " \n GURU MEDITATION !!! \n \n Unhandeled structured exception error! [code: 0x%X] \n " , GetExceptionCode ( ) ) ;
2012-12-15 19:12:56 +01:00
x264_fatal_exit ( L " Unhandeled structured exception error, application will exit! " ) ;
2012-01-28 16:40:14 +01:00
}
}
}