[impl] Ability to start minimized
[impl] Allow only one application instance only [impl] Automatic start of browser with the right command line argument [chore] Update dependencies to conan
This commit is contained in:
parent
532090c877
commit
ab56776c37
@ -1,2 +1,31 @@
|
||||
IDI_ICON1 ICON DISCARDABLE "CCEngine.ico"
|
||||
|
||||
#include <windows.h>
|
||||
#include "src/version.h"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VER_FILEVERSION
|
||||
PRODUCTVERSION VER_PRODUCTVERSION
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", VER_COMPANYNAME_STR
|
||||
VALUE "FileDescription", VER_FILEDESCRIPTION_STR
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", VER_INTERNALNAME_STR
|
||||
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
|
||||
VALUE "LegalTrademarks1", VER_LEGALTRADEMARKS1_STR
|
||||
VALUE "LegalTrademarks2", VER_LEGALTRADEMARKS2_STR
|
||||
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
|
||||
VALUE "ProductName", VER_PRODUCTNAME_STR
|
||||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||
END
|
||||
END
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1252
|
||||
END
|
||||
END
|
||||
|
||||
@ -47,12 +47,10 @@
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="project-common.props" />
|
||||
<Import Project="..\qt-ui-debug.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="project-common.props" />
|
||||
<Import Project="..\qt-ui-release.props" />
|
||||
<Import Project="..\non-debugable.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
@ -70,18 +68,19 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;_SCL_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<QtMoc>
|
||||
<IncludePath>$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName)\.;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(CRYPTOPP_ROOT_DIR)include;$(LIBZIP_ROOT_DIR)include;$(ZLIB_ROOT_DIR)include;$(LIBCURL_ROOT_DIR)include;$(BOOST_ROOT_DIR)\.</IncludePath>
|
||||
<IncludePath>%(AdditionalIncludeDirectories)</IncludePath>
|
||||
<Define>_WIN32_WINNT=0x0601;WIN32;_SCL_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</Define>
|
||||
</QtMoc>
|
||||
</ItemDefinitionGroup>
|
||||
@ -93,7 +92,6 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;_SCL_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions);</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@ -104,10 +102,11 @@
|
||||
<AssemblyDebug>false</AssemblyDebug>
|
||||
<ProgramDatabaseFile />
|
||||
<FullProgramDatabaseFile>false</FullProgramDatabaseFile>
|
||||
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<QtMoc>
|
||||
<Define>_WIN32_WINNT=0x0601;WIN32;_SCL_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions);</Define>
|
||||
<IncludePath>$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName)\.;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(CRYPTOPP_ROOT_DIR)include;$(LIBZIP_ROOT_DIR)include;$(ZLIB_ROOT_DIR)include;$(LIBCURL_ROOT_DIR)include;$(BOOST_ROOT_DIR)\.</IncludePath>
|
||||
<IncludePath>%(AdditionalIncludeDirectories)</IncludePath>
|
||||
</QtMoc>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
@ -117,10 +116,23 @@
|
||||
<ClCompile Include="src\CCServerManager.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
<ClCompile Include="src\ProcessUtils.cpp" />
|
||||
<ClCompile Include="src\RunGuard.cpp" />
|
||||
<ClCompile Include="src\SingleAppGuard.cpp" />
|
||||
<ClCompile Include="src\SystemParamsDlg.cpp" />
|
||||
<ClCompile Include="src\SystemParamsModel.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\RunGuard.h" />
|
||||
<QtMoc Include="src\SingleAppGuard.h">
|
||||
<OutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</OutputFile>
|
||||
<ExecutionDescription Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc'ing %(Identity)...</ExecutionDescription>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;$(Conan-qt-Root)\include\QtWidgets;$(ProjectDir)..\..\thirdparty\SingleApplication;$(USERPROFILE)\.conan\data\libzip\1.5.1\bincrafters\stable\package\dbbcb700636ed4dcef87df041870679358161bfa\include;$(USERPROFILE)\.conan\data\libcurl\7.61.1\bincrafters\stable\package\ad2605af224ca43af0e946078f4647e97ed84168\include;C:\.conan\uahlbm22\1\include;$(USERPROFILE)\.conan\data\cryptopp\7.0.0\bincrafters\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\include;C:\.conan\hmd9bfi9\1\include;$(USERPROFILE)\.conan\data\bzip2\1.0.6\conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\include;$(USERPROFILE)\.conan\data\OpenSSL\1.0.2o\conan\stable\package\312b5f5b013b9686179e3082c71ec55f20aea297\include;$(USERPROFILE)\.conan\data\zlib\1.2.11\conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\include</IncludePath>
|
||||
<Define Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">_WIN32_WINNT=0x0601;WIN32;_SCL_SECURE_NO_WARNINGS;_DEBUG;QAPPLICATION_CLASS=QApplication;_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;BOOST_USE_STATIC_LIBS;BOOST_ALL_NO_LIB;CURL_STATICLIB=1;_MBCS</Define>
|
||||
<OutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</OutputFile>
|
||||
<ExecutionDescription Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Moc'ing %(Identity)...</ExecutionDescription>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;$(Conan-qt-Root)\include\QtWidgets;$(ProjectDir)..\..\thirdparty\SingleApplication;$(USERPROFILE)\.conan\data\libzip\1.5.1\bincrafters\stable\package\fc750fec580977876c697df1eba7f91b3923261b\include;$(USERPROFILE)\.conan\data\libcurl\7.61.1\bincrafters\stable\package\e37072ee7d8e70a6842093ddc8fc71f26526e91f\include;C:\.conan\4gwcmfvt\1\include;$(USERPROFILE)\.conan\data\cryptopp\7.0.0\bincrafters\stable\package\2bb76c9adac7b8cd7c5e3b377ac9f06934aba606\include;C:\.conan\btu8fxq0\1\include;$(USERPROFILE)\.conan\data\bzip2\1.0.6\conan\stable\package\2bb76c9adac7b8cd7c5e3b377ac9f06934aba606\include;$(USERPROFILE)\.conan\data\OpenSSL\1.0.2o\conan\stable\package\b02659d133a8131c5433777813f6385a05a7ae8a\include;$(USERPROFILE)\.conan\data\zlib\1.2.11\conan\stable\package\2bb76c9adac7b8cd7c5e3b377ac9f06934aba606\include</IncludePath>
|
||||
<Define Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">_WIN32_WINNT=0x0601;WIN32;_SCL_SECURE_NO_WARNINGS;NDEBUG;QAPPLICATION_CLASS=QApplication;_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;BOOST_USE_STATIC_LIBS;BOOST_ALL_NO_LIB;CURL_STATICLIB=1;_MBCS</Define>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\SystemParamsModel.h" />
|
||||
<QtMoc Include="src\SystemParamsDlg.h" />
|
||||
<QtMoc Include="src\CCEngine.h" />
|
||||
@ -148,6 +160,9 @@
|
||||
<Project>{b12702ad-abfb-343a-a199-8e24837244a3}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="CCEngine.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||
<Import Project="$(QtMsBuild)\qt.targets" />
|
||||
|
||||
@ -12,6 +12,11 @@
|
||||
<Filter Include="Form Files">
|
||||
<UniqueIdentifier>{60322e81-4907-489e-87af-66b7f5778503}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
<ParseFiles>true</ParseFiles>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\CCEngine.cpp">
|
||||
@ -38,6 +43,12 @@
|
||||
<ClCompile Include="src\CCLicenseController.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\RunGuard.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\SingleAppGuard.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\CCServer.h">
|
||||
@ -49,6 +60,9 @@
|
||||
<ClInclude Include="src\PlatformInit.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\RunGuard.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="CCEngine.rc">
|
||||
@ -84,5 +98,13 @@
|
||||
<QtMoc Include="src\CCLicenseController.h">
|
||||
<Filter>src</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\SingleAppGuard.h">
|
||||
<Filter>src</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="CCEngine.ico">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
28
CCEngine/conanfile.txt
Normal file
28
CCEngine/conanfile.txt
Normal file
@ -0,0 +1,28 @@
|
||||
[requires]
|
||||
libzip/1.5.1@bincrafters/stable
|
||||
libcurl/7.61.1@bincrafters/stable
|
||||
boost/1.69.0@conan/stable
|
||||
cryptopp/7.0.0@bincrafters/stable
|
||||
qt/5.12.0@bincrafters/stable
|
||||
|
||||
[generators]
|
||||
visual_studio
|
||||
|
||||
[options]
|
||||
libzip:shared=True
|
||||
libcurl:shared=False
|
||||
libcurl:with_openssl=False
|
||||
libcurl:with_winssl=True
|
||||
boost:shared=False
|
||||
cryptopp:shared=False
|
||||
qt:shared=True
|
||||
|
||||
[imports]
|
||||
bin, Qt5Cored.dll -> ./Debug @ root_package=qt
|
||||
bin, Qt5Guid.dll -> ./Debug @ root_package=qt
|
||||
bin, Qt5Widgetsd.dll -> ./Debug @ root_package=qt
|
||||
bin, Qt5Core.dll -> ./Release @ root_package=qt
|
||||
bin, Qt5Gui.dll -> ./Release @ root_package=qt
|
||||
bin, Qt5Widgets.dll -> ./Release @ root_package=qt
|
||||
plugins/platforms, qwindowsd.dll -> ./Debug/platforms @ root_package=qt
|
||||
plugins/platforms, qwindows.dll -> ./Release/platforms @ root_package=qt
|
||||
@ -1,17 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="..\..\thirdparty\boost-1.67.0\boost.props" />
|
||||
<Import Project="..\..\thirdparty\curl-7.58.0\curl-static.props" />
|
||||
<Import Project="..\..\thirdparty\zlib-1.2.11\zlib-static.props" />
|
||||
<Import Project="..\..\thirdparty\libzip-1.4.0\libzip-static.props" />
|
||||
<Import Project="..\..\thirdparty\cryptopp-6.1.0\cryptopp-static.props" />
|
||||
<Import Project="build\conanbuildinfo_multi.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\libLicenseClient\api;$(ProjectDir)GeneratedFiles;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
|
||||
@ -15,9 +15,11 @@
|
||||
CCEngine::CCEngine(
|
||||
const boost::filesystem::path& appPath,
|
||||
bool justUpdated,
|
||||
bool startBrowser,
|
||||
QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, m_appPath(appPath)
|
||||
, m_autoStartBrowser(startBrowser)
|
||||
{
|
||||
qRegisterMetaType<CCServerStatus>();
|
||||
qRegisterMetaType<ActivationStatus>();
|
||||
@ -92,6 +94,12 @@ void CCEngine::onCCServerStatusUpdate(CCServerStatus serverStatus)
|
||||
ui.lblHttpServerStatusVal->setText(textStatus);
|
||||
ui.lblHttpServerStatusVal->setStyleSheet(QString("QLabel { color: %1; }").arg(color));
|
||||
ui.btnOpenBrowser->setEnabled(dataBrowsable);
|
||||
|
||||
if (dataBrowsable && m_autoStartBrowser)
|
||||
{
|
||||
emit onOpenBrowser(true);
|
||||
m_autoStartBrowser = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CCEngine::onLoad()
|
||||
@ -159,6 +167,13 @@ void CCEngine::onInstallUpdates(bool)
|
||||
}
|
||||
}
|
||||
|
||||
void CCEngine::onShowInForeground()
|
||||
{
|
||||
showNormal();
|
||||
raise();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void CCEngine::onParamsLoaded(SystemParams hashedParams, SystemParams origParams)
|
||||
{
|
||||
|
||||
|
||||
@ -20,9 +20,10 @@ class CCEngine : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CCEngine(
|
||||
const boost::filesystem::path& appPath,
|
||||
bool justUpdated,
|
||||
CCEngine(
|
||||
const boost::filesystem::path& appPath,
|
||||
bool justUpdated,
|
||||
bool startBrowser,
|
||||
QWidget *parent = Q_NULLPTR);
|
||||
virtual ~CCEngine();
|
||||
|
||||
@ -39,6 +40,7 @@ private slots:
|
||||
void onOpenBrowser(bool);
|
||||
void onCheckForUpdates(bool);
|
||||
void onInstallUpdates(bool);
|
||||
void onShowInForeground();
|
||||
|
||||
// License controller signal handlers
|
||||
void onParamsLoaded(SystemParams hashedParams, SystemParams origParams);
|
||||
@ -69,4 +71,5 @@ private:
|
||||
CCLicenseController m_licenseController;
|
||||
CCServerManager m_ccServerManager;
|
||||
uint16_t m_port;
|
||||
bool m_autoStartBrowser;
|
||||
};
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include "HTTPClient.h"
|
||||
#include "IModuleDatabase.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include "CCServer.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
enum class CCServerStatus
|
||||
{
|
||||
|
||||
79
CCEngine/src/RunGuard.cpp
Normal file
79
CCEngine/src/RunGuard.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include "RunGuard.h"
|
||||
|
||||
#include <QtCore/QCryptographicHash>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
QString generateKeyHash( const QString& key, const QString& salt )
|
||||
{
|
||||
QByteArray data;
|
||||
|
||||
data.append( key.toUtf8() );
|
||||
data.append( salt.toUtf8() );
|
||||
data = QCryptographicHash::hash( data, QCryptographicHash::Sha1 ).toHex();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
RunGuard::RunGuard( const QString& key )
|
||||
: key( key )
|
||||
, memLockKey( generateKeyHash( key, "_memLockKey" ) )
|
||||
, sharedMemKey( generateKeyHash( key, "_sharedMemKey" ) )
|
||||
, sharedMem( sharedMemKey )
|
||||
, memLock( memLockKey, 1 )
|
||||
{
|
||||
memLock.acquire();
|
||||
{
|
||||
QSharedMemory fix( sharedMemKey ); // Fix for *nix: http://habrahabr.ru/post/173281/
|
||||
fix.attach();
|
||||
}
|
||||
memLock.release();
|
||||
}
|
||||
|
||||
RunGuard::~RunGuard()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
bool RunGuard::isAnotherRunning()
|
||||
{
|
||||
if ( sharedMem.isAttached() )
|
||||
return false;
|
||||
|
||||
memLock.acquire();
|
||||
const bool isRunning = sharedMem.attach();
|
||||
if ( isRunning )
|
||||
sharedMem.detach();
|
||||
memLock.release();
|
||||
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
bool RunGuard::tryToRun()
|
||||
{
|
||||
if ( isAnotherRunning() ) // Extra check
|
||||
return false;
|
||||
|
||||
memLock.acquire();
|
||||
const bool result = sharedMem.create( sizeof( quint64 ) );
|
||||
memLock.release();
|
||||
if ( !result )
|
||||
{
|
||||
release();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RunGuard::release()
|
||||
{
|
||||
memLock.acquire();
|
||||
if ( sharedMem.isAttached() )
|
||||
sharedMem.detach();
|
||||
memLock.release();
|
||||
}
|
||||
37
CCEngine/src/RunGuard.h
Normal file
37
CCEngine/src/RunGuard.h
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Code based on https://stackoverflow.com/a/28172162
|
||||
* @author Dmitry Sazonov
|
||||
*/
|
||||
|
||||
#ifndef RUNGUARD_H
|
||||
#define RUNGUARD_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSharedMemory>
|
||||
#include <QtCore/QSystemSemaphore>
|
||||
|
||||
|
||||
class RunGuard
|
||||
{
|
||||
|
||||
public:
|
||||
RunGuard( const QString& key );
|
||||
~RunGuard();
|
||||
|
||||
bool isAnotherRunning();
|
||||
bool tryToRun();
|
||||
void release();
|
||||
|
||||
private:
|
||||
const QString key;
|
||||
const QString memLockKey;
|
||||
const QString sharedMemKey;
|
||||
|
||||
QSharedMemory sharedMem;
|
||||
QSystemSemaphore memLock;
|
||||
|
||||
Q_DISABLE_COPY( RunGuard )
|
||||
};
|
||||
|
||||
|
||||
#endif // RUNGUARD_H
|
||||
69
CCEngine/src/SingleAppGuard.cpp
Normal file
69
CCEngine/src/SingleAppGuard.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include "SingleAppGuard.h"
|
||||
|
||||
#include "RunGuard.h"
|
||||
|
||||
#include <QtCore/QCryptographicHash>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
QString generateKeyHash(const QString& key, const QString& salt)
|
||||
{
|
||||
QByteArray data;
|
||||
|
||||
data.append(key.toUtf8());
|
||||
data.append(salt.toUtf8());
|
||||
data = QCryptographicHash::hash(data, QCryptographicHash::Sha1).toHex();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SingleAppGuard::SingleAppGuard(QString key)
|
||||
: uniqueAppKey(std::move(key))
|
||||
{}
|
||||
|
||||
SingleAppGuard::~SingleAppGuard()
|
||||
{
|
||||
exitRequested = true;
|
||||
if (m_appLock)
|
||||
{
|
||||
m_appLock->release();
|
||||
}
|
||||
if (m_workerThread.joinable())
|
||||
{
|
||||
m_workerThread.join();
|
||||
}
|
||||
}
|
||||
|
||||
bool SingleAppGuard::tryToRun()
|
||||
{
|
||||
auto keyHash = generateKeyHash(uniqueAppKey, "_appKey");
|
||||
m_runGuard = std::make_unique<RunGuard>( uniqueAppKey );
|
||||
if ( !m_runGuard->tryToRun() )
|
||||
{
|
||||
// just notify consumer and return
|
||||
QSystemSemaphore appLock(keyHash, 0);
|
||||
appLock.release();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// create consumer
|
||||
exitRequested = false;
|
||||
m_appLock = std::make_unique<QSystemSemaphore>(keyHash, 0, QSystemSemaphore::Create);
|
||||
m_workerThread = std::thread([this]()
|
||||
{
|
||||
while (!exitRequested && m_appLock->acquire())
|
||||
{
|
||||
if (exitRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
emit instanceStarted();
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
32
CCEngine/src/SingleAppGuard.h
Normal file
32
CCEngine/src/SingleAppGuard.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
class RunGuard;
|
||||
class QSystemSemaphore;
|
||||
|
||||
class SingleAppGuard : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit SingleAppGuard(QString key);
|
||||
virtual ~SingleAppGuard();
|
||||
|
||||
public:
|
||||
bool tryToRun();
|
||||
|
||||
public:
|
||||
signals:
|
||||
void instanceStarted();
|
||||
|
||||
private:
|
||||
QString uniqueAppKey;
|
||||
std::atomic<bool> exitRequested;
|
||||
std::thread m_workerThread;
|
||||
std::unique_ptr<RunGuard> m_runGuard;
|
||||
std::unique_ptr<QSystemSemaphore> m_appLock;
|
||||
};
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include "SystemParams.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QtCore/QAbstractTableModel>
|
||||
|
||||
#include <tuple>
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
#include "CCEngine.h"
|
||||
|
||||
#include "OSUtils.h"
|
||||
#include "SingleAppGuard.h"
|
||||
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
@ -15,6 +18,11 @@ namespace logging = boost::log;
|
||||
namespace expr = boost::log::expressions;
|
||||
namespace keywords = boost::log::keywords;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr char uniqueAppKey[] = "rE4ZDk0PsEG2K123lyharvJyQ9zeP9w";
|
||||
}
|
||||
|
||||
void initLogging()
|
||||
{
|
||||
auto logPath = ensureLogFolder("CCEngine");
|
||||
@ -35,6 +43,12 @@ void initLogging()
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SingleAppGuard guard( uniqueAppKey );
|
||||
if ( !guard.tryToRun() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
auto appDir = fs::system_complete(a.arguments().at(0).toStdString()).parent_path();
|
||||
@ -42,15 +56,33 @@ int main(int argc, char *argv[])
|
||||
initLogging();
|
||||
|
||||
bool justUpdated = false;
|
||||
bool minimized = false;
|
||||
bool startBrowser = false;
|
||||
for (int i = 1; i < a.arguments().size(); ++i)
|
||||
{
|
||||
if (a.arguments().at(i) == "--updated")
|
||||
{
|
||||
justUpdated = true;
|
||||
}
|
||||
if (a.arguments().at(i) == "--minimized")
|
||||
{
|
||||
minimized = true;
|
||||
}
|
||||
if (a.arguments().at(i) == "--start-browser")
|
||||
{
|
||||
startBrowser = true;
|
||||
}
|
||||
}
|
||||
|
||||
CCEngine w(appDir, justUpdated);
|
||||
w.show();
|
||||
CCEngine w(appDir, justUpdated, startBrowser);
|
||||
if (!minimized)
|
||||
{
|
||||
w.show();
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
&guard, SIGNAL(instanceStarted()),
|
||||
&w, SLOT(onShowInForeground()));
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
21
CCEngine/src/version.h
Normal file
21
CCEngine/src/version.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
#define VER_FILEVERSION 18,52,01
|
||||
#define VER_FILEVERSION_STR "185201\0"
|
||||
|
||||
#define VER_PRODUCTVERSION 18,52,01
|
||||
#define VER_PRODUCTVERSION_STR "185201\0"
|
||||
|
||||
#define VER_COMPANYNAME_STR "Apis spol. s r.o."
|
||||
#define VER_FILEDESCRIPTION_STR "Catalogue of Currencies Serving Engine"
|
||||
#define VER_INTERNALNAME_STR "CCEngine"
|
||||
#define VER_LEGALCOPYRIGHT_STR "Copyright (c) 2018 Apis spol. s r.o."
|
||||
#define VER_LEGALTRADEMARKS1_STR "All Rights Reserved"
|
||||
#define VER_LEGALTRADEMARKS2_STR VER_LEGALTRADEMARKS1_STR
|
||||
#define VER_ORIGINALFILENAME_STR "CCEngine.exe"
|
||||
#define VER_PRODUCTNAME_STR "CCEngine"
|
||||
|
||||
#define VER_COMPANYDOMAIN_STR "apis.sk"
|
||||
|
||||
#endif // VERSION_H
|
||||
@ -1,7 +1,7 @@
|
||||
#include "CCEngineLoader.h"
|
||||
|
||||
#include <QMovie>
|
||||
#include <QTimer>
|
||||
#include <QtGui/QMovie>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
CCEngineLoader::CCEngineLoader(
|
||||
const boost::filesystem::path& appPath,
|
||||
|
||||
@ -46,12 +46,10 @@
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="project-common.props" />
|
||||
<Import Project="..\qt-ui-debug.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="project-common.props" />
|
||||
<Import Project="..\qt-ui-release.props" />
|
||||
<Import Project="..\non-debugable.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
@ -69,18 +67,19 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\libLicenseClient\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<QtMoc>
|
||||
<IncludePath>$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName)\.;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(CRYPTOPP_ROOT_DIR)include;$(LIBZIP_ROOT_DIR)include;$(ZLIB_ROOT_DIR)include;$(LIBCURL_ROOT_DIR)include;$(BOOST_ROOT_DIR)\.</IncludePath>
|
||||
<IncludePath>%(AdditionalIncludeDirectories)</IncludePath>
|
||||
<Define>_WIN32_WINNT=0x0601;WIN32;_DEBUG;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;CURL_STATICLIB;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING;_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING;_MBCS</Define>
|
||||
</QtMoc>
|
||||
</ItemDefinitionGroup>
|
||||
@ -92,7 +91,6 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_WIN32_WINNT=0x0601;WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\libLicenseClient\api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@ -103,10 +101,11 @@
|
||||
<AssemblyDebug>false</AssemblyDebug>
|
||||
<ProgramDatabaseFile />
|
||||
<FullProgramDatabaseFile>false</FullProgramDatabaseFile>
|
||||
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<QtMoc>
|
||||
<Define>_WIN32_WINNT=0x0601;WIN32;NDEBUG;BOOST_EXCEPTION_DISABLE;QT_NO_DEBUG;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;CURL_STATICLIB;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING;_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING;_MBCS</Define>
|
||||
<IncludePath>$(ProjectDir)..\..\libLicenseClient\api;.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName)\.;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(CRYPTOPP_ROOT_DIR)include;$(LIBZIP_ROOT_DIR)include;$(ZLIB_ROOT_DIR)include;$(LIBCURL_ROOT_DIR)include;$(BOOST_ROOT_DIR)\.</IncludePath>
|
||||
<IncludePath>%(AdditionalIncludeDirectories)</IncludePath>
|
||||
</QtMoc>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <QThread>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
enum class UpdateStatus
|
||||
{
|
||||
|
||||
18
CCEngineLoader/conanfile.txt
Normal file
18
CCEngineLoader/conanfile.txt
Normal file
@ -0,0 +1,18 @@
|
||||
[requires]
|
||||
libzip/1.5.1@bincrafters/stable
|
||||
libcurl/7.61.1@bincrafters/stable
|
||||
boost/1.69.0@conan/stable
|
||||
cryptopp/7.0.0@bincrafters/stable
|
||||
qt/5.12.0@bincrafters/stable
|
||||
|
||||
[generators]
|
||||
visual_studio
|
||||
|
||||
[options]
|
||||
libzip:shared=True
|
||||
libcurl:shared=False
|
||||
libcurl:with_openssl=False
|
||||
libcurl:with_winssl=True
|
||||
boost:shared=False
|
||||
cryptopp:shared=False
|
||||
qt:shared=True
|
||||
@ -1,11 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="..\..\thirdparty\boost-1.67.0\boost.props" />
|
||||
<Import Project="..\..\thirdparty\curl-7.58.0\curl-static.props" />
|
||||
<Import Project="..\..\thirdparty\zlib-1.2.11\zlib-static.props" />
|
||||
<Import Project="..\..\thirdparty\libzip-1.4.0\libzip-static.props" />
|
||||
<Import Project="..\..\thirdparty\cryptopp-6.1.0\cryptopp-static.props" />
|
||||
<Import Project="build\conanbuildinfo_multi.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
|
||||
32
workspace.bat
Normal file
32
workspace.bat
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
setlocal
|
||||
|
||||
set GENERATOR=visual_studio_multi
|
||||
set CONAN=conan
|
||||
set ARCH=x86
|
||||
|
||||
SET SCRIPTDIR=%~dp0
|
||||
|
||||
mkdir %SCRIPTDIR%\CCEngine\build
|
||||
cd %SCRIPTDIR%\CCEngine\build
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Debug
|
||||
rem --build=libcurl
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Release
|
||||
rem --build=libcurl
|
||||
|
||||
mkdir %SCRIPTDIR%\CCEngineLoader\build
|
||||
cd %SCRIPTDIR%\CCEngineLoader\build
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Debug
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Release
|
||||
|
||||
mkdir %SCRIPTDIR%\..\libLicenseClient\build
|
||||
cd %SCRIPTDIR%\..\libLicenseClient\build
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Debug
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Release
|
||||
|
||||
mkdir %SCRIPTDIR%\..\libLicenseClient\test\build
|
||||
cd %SCRIPTDIR%\..\libLicenseClient\test\build
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Debug
|
||||
%CONAN% install .. -g %GENERATOR% -s arch=%ARCH% -s build_type=Release
|
||||
|
||||
endlocal
|
||||
Loading…
Reference in New Issue
Block a user