Move IPC sender to separate thread + implement kill IPC command + improve deployment script
This commit is contained in:
parent
9ce7dfc75f
commit
a7a637c412
@ -28,8 +28,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="copy "$(QTDIR)\plugins\imageformats\q???d4.dll" "$(TargetDir)\imageformats"
"
|
||||
Outputs=""$(TargetDir)\imageformats\qgifd4.dll""
|
||||
CommandLine=""
|
||||
Outputs=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
@ -92,6 +92,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Copy plugin DLL's"
|
||||
CommandLine="copy "$(QTDIR)\plugins\imageformats\q???d4.dll" "$(TargetDir)\imageformats""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
@ -106,8 +108,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="copy "$(QTDIR)\plugins\imageformats\q???4.dll" "$(TargetDir)\imageformats"
"
|
||||
Outputs=""$(TargetDir)\imageformats\qgif4.dll""
|
||||
CommandLine=""
|
||||
Outputs=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
@ -180,6 +182,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="Copy plugin DLL's"
|
||||
CommandLine="copy "$(QTDIR)\plugins\imageformats\q???4.dll" "$(TargetDir)\imageformats""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
@ -247,6 +251,10 @@
|
||||
RelativePath=".\src\Thread_MessageHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Thread_MessageProducer.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
@ -472,6 +480,30 @@
|
||||
<File
|
||||
RelativePath=".\src\Thread_MessageHandler.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="MOC "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
CommandLine=""$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp" "$(InputPath)"
"
|
||||
Outputs=""$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="MOC "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
CommandLine=""$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp" "$(InputPath)"
"
|
||||
Outputs=""$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Thread_MessageProducer.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
@ -535,6 +567,10 @@
|
||||
RelativePath=".\tmp\MOC_Thread_MessageHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tmp\MOC_Thread_MessageProducer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tmp\RCC_Icons.cpp"
|
||||
>
|
||||
|
@ -1,9 +1,31 @@
|
||||
@echo off
|
||||
call _paths.bat
|
||||
set "LAMEXP_BUILD_SUCCESS=NO"
|
||||
echo ----------------------------------------------------------------
|
||||
echo Solution File: %1
|
||||
echo Configuration: %~n2
|
||||
echo ----------------------------------------------------------------
|
||||
call _paths.bat
|
||||
call "%PATH_MSVC90%\VC\bin\vcvars32.bat"
|
||||
call "%PATH_QTMSVC%\bin\qtvars.bat"
|
||||
msbuild.exe /property:Configuration=%~n2 /target:Clean,Rebuild /verbosity:d %1
|
||||
REM -----------------------------------------------------------------
|
||||
msbuild.exe /property:Configuration=%~n2 /target:Clean /verbosity:d %1
|
||||
if exist "%~d1%~p1bin\%~n2\*.exe" (
|
||||
echo.
|
||||
echo CLEANUP HAS FAILED!
|
||||
echo.
|
||||
GOTO:EOF
|
||||
)
|
||||
if exist "%~d1%~p1obj\%~n2\*.obj" (
|
||||
echo.
|
||||
echo CLEANUP HAS FAILED!
|
||||
echo.
|
||||
GOTO:EOF
|
||||
)
|
||||
echo ----------------------------------------------------------------
|
||||
msbuild.exe /property:Configuration=%~n2 /target:Rebuild /verbosity:d %1
|
||||
echo ----------------------------------------------------------------
|
||||
if not exist "%~d1%~p1bin\%~n2\%~n1.exe" (
|
||||
echo BUILD HAS FAILED!
|
||||
exit
|
||||
)
|
||||
set "LAMEXP_BUILD_SUCCESS=YES"
|
||||
|
@ -1,5 +1,6 @@
|
||||
@echo off
|
||||
set "PATH_SEVENZ=E:\7-Zip\7z.exe"
|
||||
set "PATH_MPRESS=E:\MPress\mpress.exe"
|
||||
set "PATH_UPXBIN=E:\MPUI\installer\upx.exe"
|
||||
set "PATH_MSVC90=D:\Microsoft Visual Studio 9.0"
|
||||
set "PATH_QTMSVC=E:\Qt\MSVC\4.7.0"
|
||||
|
@ -16,7 +16,7 @@ if exist "%OUT_FILE%" (
|
||||
REM ------------------------------------------
|
||||
call _build.bat "..\..\LameXP.sln" Release
|
||||
REM ------------------------------------------
|
||||
if not exist "%OUT_PATH%\LameXP.exe" (
|
||||
if not "%LAMEXP_BUILD_SUCCESS%"=="YES" (
|
||||
echo.
|
||||
echo BUILD HAS FAILED !!!
|
||||
echo.
|
||||
@ -36,10 +36,10 @@ copy "%QTDIR%\bin\QtSvg4.dll" "%TEMP_DIR%"
|
||||
copy "%QTDIR%\plugins\imageformats\q???4.dll" "%TEMP_DIR%\imageformats"
|
||||
REM ------------------------------------------
|
||||
for %%f in ("%TEMP_DIR%\*.exe") do (
|
||||
"%PATH_MPRESS%" -s "%%f"
|
||||
"%PATH_UPXBIN%" --best --lzma "%%f"
|
||||
)
|
||||
for %%f in ("%TEMP_DIR%\*.dll") do (
|
||||
"%PATH_MPRESS%" -s "%%f"
|
||||
"%PATH_UPXBIN%" --best --lzma "%%f"
|
||||
)
|
||||
REM ------------------------------------------
|
||||
copy "..\Redist\*.*" "%TEMP_DIR%"
|
||||
|
@ -149,6 +149,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_delayedFileTimer = new QTimer();
|
||||
connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection);
|
||||
connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection);
|
||||
connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection);
|
||||
connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
|
||||
m_messageHandler->start();
|
||||
}
|
||||
@ -159,12 +160,18 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
MainWindow::~MainWindow(void)
|
||||
{
|
||||
while(m_messageHandler->isRunning())
|
||||
//Stop message handler thread
|
||||
if(m_messageHandler && m_messageHandler->isRunning())
|
||||
{
|
||||
m_messageHandler->stop();
|
||||
m_messageHandler->wait();
|
||||
if(!m_messageHandler->wait(10000))
|
||||
{
|
||||
m_messageHandler->terminate();
|
||||
m_messageHandler->wait();
|
||||
}
|
||||
}
|
||||
|
||||
//Free memory
|
||||
LAMEXP_DELETE(m_tabActionGroup);
|
||||
LAMEXP_DELETE(m_styleActionGroup);
|
||||
LAMEXP_DELETE(m_fileListModel);
|
||||
|
@ -332,7 +332,10 @@ void lamexp_ipc_send(unsigned int command, const char* message)
|
||||
lamexp_ipc_t *lamexp_ipc = new lamexp_ipc_t;
|
||||
memset(lamexp_ipc, 0, sizeof(lamexp_ipc_t));
|
||||
lamexp_ipc->command = command;
|
||||
strcpy_s(lamexp_ipc->parameter, 4096, message);
|
||||
if(message)
|
||||
{
|
||||
strcpy_s(lamexp_ipc->parameter, 4096, message);
|
||||
}
|
||||
|
||||
if(g_lamexp_semaphore_write_ptr->acquire())
|
||||
{
|
||||
@ -383,22 +386,7 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize)
|
||||
*/
|
||||
void lamexp_handle_multiple_instanced(void)
|
||||
{
|
||||
QStringList arguments = QApplication::arguments();
|
||||
bool bSentFiles = false;
|
||||
|
||||
for(int i = 0; i < arguments.count() - 1; i++)
|
||||
{
|
||||
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
|
||||
{
|
||||
lamexp_ipc_send(1, arguments[++i].toUtf8().constData());
|
||||
bSentFiles = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!bSentFiles)
|
||||
{
|
||||
lamexp_ipc_send(UINT_MAX, "Use running instance!");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
33
src/Main.cpp
33
src/Main.cpp
@ -24,6 +24,7 @@
|
||||
#include "Dialog_SplashScreen.h"
|
||||
#include "Dialog_MainWindow.h"
|
||||
#include "Thread_Initialization.h"
|
||||
#include "Thread_MessageProducer.h"
|
||||
|
||||
//Qt includes
|
||||
#include <QApplication>
|
||||
@ -36,6 +37,8 @@
|
||||
|
||||
int lamexp_main(int argc, char* argv[])
|
||||
{
|
||||
int iResult = -1;
|
||||
|
||||
//Init console
|
||||
lamexp_init_console(argc, argv);
|
||||
|
||||
@ -51,7 +54,7 @@ int lamexp_main(int argc, char* argv[])
|
||||
|
||||
//Print warning, if this is a "debug" build
|
||||
LAMEXP_CHECK_DEBUG_BUILD;
|
||||
|
||||
|
||||
//Initialize Qt
|
||||
lamexp_init_qt(argc, argv);
|
||||
|
||||
@ -69,16 +72,34 @@ int lamexp_main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
//Check for multiple instances of LameXP
|
||||
int iResult = lamexp_init_ipc();
|
||||
if(iResult > 0)
|
||||
if((iResult = lamexp_init_ipc()) != 0)
|
||||
{
|
||||
qDebug("LameXP is already running, connecting to running instance...");
|
||||
lamexp_handle_multiple_instanced();
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if(iResult < 0)
|
||||
|
||||
//Kill application?
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
return -1;
|
||||
if(!_stricmp("--kill", argv[i]) || !_stricmp("--force-kill", argv[i]))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Show splash screen
|
||||
|
@ -25,7 +25,7 @@
|
||||
#define VER_LAMEXP_MAJOR 4
|
||||
#define VER_LAMEXP_MINOR_HI 0
|
||||
#define VER_LAMEXP_MINOR_LO 0
|
||||
#define VER_LAMEXP_BUILD 7
|
||||
#define VER_LAMEXP_BUILD 8
|
||||
#define VER_LAMEXP_SUFFIX TechPreview
|
||||
|
||||
/*
|
||||
|
@ -60,6 +60,16 @@ void MessageHandlerThread::run()
|
||||
case 1:
|
||||
emit fileReceived(QString::fromUtf8(m_parameter));
|
||||
break;
|
||||
case 666:
|
||||
if(!_stricmp(m_parameter, "Force!"))
|
||||
{
|
||||
ExitProcess(-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit killSignalReceived();
|
||||
}
|
||||
break;
|
||||
case UINT_MAX:
|
||||
emit otherInstanceDetected();
|
||||
break;
|
||||
@ -77,7 +87,6 @@ void MessageHandlerThread::stop(void)
|
||||
m_aborted = true;
|
||||
lamexp_ipc_send(0, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -40,4 +40,5 @@ private:
|
||||
signals:
|
||||
void otherInstanceDetected(void);
|
||||
void fileReceived(const QString &filePath);
|
||||
void killSignalReceived(void);
|
||||
};
|
||||
|
82
src/Thread_MessageProducer.cpp
Normal file
82
src/Thread_MessageProducer.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Thread_MessageProducer.h"
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QApplication>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
MessageProducerThread::MessageProducerThread(void)
|
||||
{
|
||||
}
|
||||
|
||||
MessageProducerThread::~MessageProducerThread(void)
|
||||
{
|
||||
}
|
||||
|
||||
void MessageProducerThread::run()
|
||||
{
|
||||
setTerminationEnabled(true);
|
||||
bool bSentFiles = false;
|
||||
QStringList arguments = QApplication::arguments();
|
||||
|
||||
for(int i = 0; i < arguments.count(); i++)
|
||||
{
|
||||
if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
|
||||
{
|
||||
lamexp_ipc_send(666, NULL);
|
||||
return;
|
||||
}
|
||||
if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
||||
{
|
||||
lamexp_ipc_send(666, "Force!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < arguments.count() - 1; i++)
|
||||
{
|
||||
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
|
||||
{
|
||||
lamexp_ipc_send(1, arguments[++i].toUtf8().constData());
|
||||
bSentFiles = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!bSentFiles)
|
||||
{
|
||||
lamexp_ipc_send(UINT_MAX, "Use running instance!");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// EVENTS
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
/*NONE*/
|
34
src/Thread_MessageProducer.h
Normal file
34
src/Thread_MessageProducer.h
Normal file
@ -0,0 +1,34 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QThread>
|
||||
|
||||
class MessageProducerThread: public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MessageProducerThread(void);
|
||||
~MessageProducerThread(void);
|
||||
void run();
|
||||
};
|
Loading…
Reference in New Issue
Block a user