Added multi-instance handling to main() function.

This commit is contained in:
LoRd_MuldeR 2014-01-27 20:21:29 +01:00
parent 66883a749b
commit fa9b468f92
3 changed files with 76 additions and 3 deletions

View File

@ -2,4 +2,4 @@ Simple x264 Launcher was created from the scratch by LoRd_MuldeR <mulder2@gmx.de
The Qt GUI Toolkit is Copyright (C) 2012 Digia Finland Ltd and/or its subsidiary(-ies). You may use, distribute and copy the Qt GUI Toolkit under the terms of GNU General Public License version 3. The Qt GUI Toolkit is Copyright (C) 2012 Digia Finland Ltd and/or its subsidiary(-ies). You may use, distribute and copy the Qt GUI Toolkit under the terms of GNU General Public License version 3.
x264 is Copyright (C) 2003-2012 'x264 project' and is distributed under the terms of GNU General Public License. Avs2YUV was created by Loren Merritt and BugMaster. x264 is Copyright (C) 2003-2014 'x264 project' and is distributed under the terms of GNU General Public License. Avs2YUV was created by Loren Merritt and BugMaster.

View File

@ -21,6 +21,7 @@
#include "global.h" #include "global.h"
#include "win_main.h" #include "win_main.h"
#include "ipc.h"
#include "taskbar7.h" #include "taskbar7.h"
//Qt includes //Qt includes
@ -33,6 +34,9 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
//Forward declaration
void handleMultipleInstances(QStringList args, IPC *ipc);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Main function // Main function
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -71,6 +75,23 @@ static int x264_main(int argc, char* argv[])
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)); 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));
qDebug(" Number of CPU's : %d\n", cpuFeatures.count); qDebug(" Number of CPU's : %d\n", cpuFeatures.count);
//Initialize the IPC handler class
bool firstInstance = false;
IPC *ipc = new IPC();
if(!ipc->initialize(firstInstance))
{
if(!firstInstance)
{
handleMultipleInstances(arguments, ipc);
X264_DELETE(ipc);
return 0;
}
}
else
{
qWarning("IPC initialization has failed!");
}
//Initialize Qt //Initialize Qt
if(!x264_init_qt(argc, argv)) if(!x264_init_qt(argc, argv))
{ {
@ -106,6 +127,58 @@ static int x264_main(int argc, char* argv[])
return ret; return ret;
} }
///////////////////////////////////////////////////////////////////////////////
// Multi-instance handler
///////////////////////////////////////////////////////////////////////////////
void handleMultipleInstances(QStringList args, IPC *ipc)
{
bool commandSent = false;
//Process all command-line arguments
while(!args.isEmpty())
{
const QString current = args.takeFirst();
if((current.compare("--add", Qt::CaseInsensitive) == 0) || (current.compare("--add-file", Qt::CaseInsensitive) == 0))
{
if(!args.isEmpty())
{
commandSent = true;
if(!ipc->sendAsync(IPC::IPC_OPCODE_ADD_FILE, QStringList() << args.takeFirst()))
{
break;
}
}
else
{
qWarning("Argument for '--add-file' is missing!");
}
}
else if(current.compare("--add-job", Qt::CaseInsensitive) == 0)
{
if(args.size() >= 3)
{
commandSent = true;
if(!ipc->sendAsync(IPC::IPC_OPCODE_ADD_JOB, QStringList() << args.takeFirst() << args.takeFirst() << args.takeFirst()))
{
break;
}
}
else
{
qWarning("Argument(s) for '--add-job' are missing!");
args.clear();
}
}
}
//If no argument has been sent yet, send a ping!
if(!commandSent)
{
ipc->sendAsync(IPC::IPC_OPCODE_PING, QStringList());
}
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Applicaton entry point // Applicaton entry point
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -26,7 +26,7 @@
#define VER_X264_MAJOR 2 #define VER_X264_MAJOR 2
#define VER_X264_MINOR 2 #define VER_X264_MINOR 2
#define VER_X264_PATCH 9 #define VER_X264_PATCH 9
#define VER_X264_BUILD 726 #define VER_X264_BUILD 727
#define VER_X264_MINIMUM_REV 2363 #define VER_X264_MINIMUM_REV 2363
#define VER_X264_CURRENT_API 140 #define VER_X264_CURRENT_API 140