2010-11-09 22:06:11 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2015-01-01 18:06:21 +01:00
|
|
|
// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-09 22:06:11 +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-09 22:06:11 +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
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Thread_MessageProducer.h"
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//Internal
|
2010-11-09 22:06:11 +01:00
|
|
|
#include "Global.h"
|
2014-12-14 19:33:28 +01:00
|
|
|
#include "IPCCommands.h"
|
2010-11-09 22:06:11 +01:00
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Global.h>
|
2014-12-13 23:27:47 +01:00
|
|
|
#include <MUtils/IPCChannel.h>
|
2014-11-25 22:34:20 +01:00
|
|
|
#include <MUtils/OSSupport.h>
|
2014-11-25 02:14:42 +01:00
|
|
|
|
|
|
|
//Qt
|
2010-11-09 22:06:11 +01:00
|
|
|
#include <QStringList>
|
|
|
|
#include <QApplication>
|
2010-11-13 02:11:15 +01:00
|
|
|
#include <QFileInfo>
|
2011-06-11 17:18:30 +02:00
|
|
|
#include <QDir>
|
2010-11-09 22:06:11 +01:00
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//CRT
|
2010-11-09 22:06:11 +01:00
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-13 23:27:47 +01:00
|
|
|
MessageProducerThread::MessageProducerThread(MUtils::IPCChannel *const ipcChannel)
|
|
|
|
:
|
|
|
|
m_ipcChannel(ipcChannel)
|
2010-11-09 22:06:11 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageProducerThread::~MessageProducerThread(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageProducerThread::run()
|
|
|
|
{
|
|
|
|
setTerminationEnabled(true);
|
|
|
|
bool bSentFiles = false;
|
2014-11-25 22:34:20 +01:00
|
|
|
const QStringList &arguments = MUtils::OS::arguments();
|
2010-11-09 22:06:11 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < arguments.count(); i++)
|
|
|
|
{
|
|
|
|
if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE, NULL))
|
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2010-11-09 22:06:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE, NULL))
|
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2010-11-09 22:06:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < arguments.count() - 1; i++)
|
|
|
|
{
|
|
|
|
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
|
|
|
|
{
|
2011-06-11 17:18:30 +02:00
|
|
|
QFileInfo file = QFileInfo(arguments[++i]);
|
|
|
|
if(file.exists() && file.isFile())
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, MUTILS_UTF8(file.canonicalFilePath())))
|
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2011-06-11 17:18:30 +02:00
|
|
|
}
|
|
|
|
bSentFiles = true;
|
|
|
|
}
|
|
|
|
if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
QDir dir = QDir(arguments[++i]);
|
|
|
|
if(dir.exists())
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, MUTILS_UTF8(dir.canonicalPath())))
|
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2011-06-11 17:18:30 +02:00
|
|
|
}
|
|
|
|
bSentFiles = true;
|
|
|
|
}
|
|
|
|
if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
QDir dir = QDir(arguments[++i]);
|
|
|
|
if(dir.exists())
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, MUTILS_UTF8(dir.canonicalPath())))
|
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2011-06-11 17:18:30 +02:00
|
|
|
}
|
2010-11-09 22:06:11 +01:00
|
|
|
bSentFiles = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!bSentFiles)
|
|
|
|
{
|
2014-12-14 19:33:28 +01:00
|
|
|
if(!m_ipcChannel->send(IPC_CMD_PING, IPC_FLAG_NONE, "Use running instance!"))
|
|
|
|
{
|
|
|
|
qWarning("Failed to send IPC message!");
|
|
|
|
}
|
2010-11-09 22:06:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// EVENTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*NONE*/
|