diff --git a/CCEngine/conanfile.txt b/CCEngine/conanfile.txt
index 83b2bea..9e802ca 100644
--- a/CCEngine/conanfile.txt
+++ b/CCEngine/conanfile.txt
@@ -4,6 +4,7 @@ libcurl/7.61.1@bincrafters/stable
boost/1.69.0@conan/stable
cryptopp/7.0.0@bincrafters/stable
qt/5.12.0@bincrafters/stable
+yaml-cpp/0.6.2@bincrafters/stable
[generators]
visual_studio
diff --git a/CCEngine/project-common.props b/CCEngine/project-common.props
index 61fc50f..370b77c 100644
--- a/CCEngine/project-common.props
+++ b/CCEngine/project-common.props
@@ -8,7 +8,7 @@
$(ProjectDir)..\..\libLicenseClient\api;$(ProjectDir)GeneratedFiles;%(AdditionalIncludeDirectories)
%(AdditionalOptions)
- _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;%(PreprocessorDefinitions)
+ _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING;%(PreprocessorDefinitions)
%(AdditionalLibraryDirectories)
diff --git a/CCEngine/src/CCEngine.cpp b/CCEngine/src/CCEngine.cpp
index da10e0a..4baa1b0 100644
--- a/CCEngine/src/CCEngine.cpp
+++ b/CCEngine/src/CCEngine.cpp
@@ -3,6 +3,8 @@
#include "SystemParamsProvider.h"
#include "SystemParamsDlg.h"
+#include
+
#include
#include
#include
@@ -10,12 +12,66 @@
#include
#include
+#include
+
#include
+#include
+
+namespace detail
+{
+
+ class CCEngineConfig
+ {
+ public:
+ CCEngineConfig(const boost::filesystem::path& configFilePath)
+ : m_configFilePath(configFilePath)
+ {
+ try
+ {
+ std::ifstream fin(m_configFilePath.native());
+ if (!fin.fail())
+ {
+ m_yaml = YAML::Load(fin);
+ }
+ }
+ catch (const YAML::ParserException&)
+ {
+ BOOST_LOG_TRIVIAL(warning) << "The yaml configuration file is malformed. Ignoring.";
+ }
+ }
+
+ std::optional port() const
+ {
+ if (m_yaml["port"])
+ {
+ return m_yaml["port"].as();
+ }
+ return {};
+ }
+
+ void setPort(uint16_t port)
+ {
+ m_yaml["port"] = port;
+ }
+
+ void save()
+ {
+ std::ofstream fout(m_configFilePath.native());
+ fout << m_yaml;
+ }
+
+ private:
+ boost::filesystem::path m_configFilePath;
+ YAML::Node m_yaml;
+ };
+
+}
CCEngine::CCEngine(
const boost::filesystem::path& appPath,
bool justUpdated,
bool startBrowser,
+ std::optional port,
QWidget *parent)
: QMainWindow(parent)
, m_appPath(appPath)
@@ -42,6 +98,20 @@ CCEngine::CCEngine(
connect(timer, SIGNAL(timeout()), this, SLOT(onLoad()), Qt::ConnectionType::QueuedConnection);
timer->start(0);
+ m_config = std::make_unique(appPath / "CCEngine.yaml");
+
+ m_port = 8080;
+ if (port)
+ {
+ m_port = port.value();
+ }
+ else if (m_config->port())
+ {
+ m_port = m_config->port().value();
+ }
+
+ ui.txtPort->setText(QString::number(m_port));
+
// Connect UI
connect(ui.btnActivate, SIGNAL(clicked(bool)), this, SLOT(onActivate(bool)));
connect(ui.btnActivationDetail, SIGNAL(clicked(bool)), this, SLOT(onActivationDetail(bool)));
@@ -123,7 +193,13 @@ void CCEngine::onRestartServer(bool)
{
if (m_licenseController.isActivated())
{
- m_port = ui.txtPort->text().toUShort();
+ uint16_t port = ui.txtPort->text().toUShort();
+ if (port != m_port)
+ {
+ m_port = port;
+ m_config->setPort(port);
+ m_config->save();
+ }
m_ccServerManager.listen("127.0.0.1", m_port, (boost::filesystem::path(m_appPath) / "data").string(), 4);
}
}
diff --git a/CCEngine/src/CCEngine.h b/CCEngine/src/CCEngine.h
index d08dcb2..1f47d3d 100644
--- a/CCEngine/src/CCEngine.h
+++ b/CCEngine/src/CCEngine.h
@@ -15,15 +15,23 @@ struct UpdatesInfo
int updateCount;
};
+namespace detail
+{
+
+ class CCEngineConfig;
+}
+
+
class CCEngine : public QMainWindow
{
Q_OBJECT
public:
- CCEngine(
- const boost::filesystem::path& appPath,
- bool justUpdated,
- bool startBrowser,
+ CCEngine(
+ const boost::filesystem::path& appPath,
+ bool justUpdated,
+ bool startBrowser,
+ std::optional port,
QWidget *parent = Q_NULLPTR);
virtual ~CCEngine();
@@ -72,4 +80,5 @@ private:
CCServerManager m_ccServerManager;
uint16_t m_port;
bool m_autoStartBrowser;
+ std::unique_ptr m_config;
};
diff --git a/CCEngine/src/main.cpp b/CCEngine/src/main.cpp
index 5afa51e..33be215 100644
--- a/CCEngine/src/main.cpp
+++ b/CCEngine/src/main.cpp
@@ -58,6 +58,7 @@ int main(int argc, char *argv[])
bool justUpdated = false;
bool minimized = false;
bool startBrowser = false;
+ std::optional port;
for (int i = 1; i < a.arguments().size(); ++i)
{
if (a.arguments().at(i) == "--updated")
@@ -72,9 +73,13 @@ int main(int argc, char *argv[])
{
startBrowser = true;
}
+ if (a.arguments().at(i).startsWith("--port="))
+ {
+ port = a.arguments().at(i).mid(7).toUShort();
+ }
}
- CCEngine w(appDir, justUpdated, startBrowser);
+ CCEngine w(appDir, justUpdated, startBrowser, port);
if (!minimized)
{
w.show();