[impl] Implement support to preserve last configured port number
[impl] Allow port number to be overriden by command line argument
This commit is contained in:
parent
9e14321827
commit
e95c05351e
@ -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
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
<ClCompile>
|
||||
<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>
|
||||
<PreprocessorDefinitions>_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include "SystemParamsProvider.h"
|
||||
#include "SystemParamsDlg.h"
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include <QtWidgets/QMenu>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QtGui/QCloseEvent>
|
||||
@ -10,12 +12,66 @@
|
||||
#include <QtWidgets/QInputDialog>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include <future>
|
||||
#include <fstream>
|
||||
|
||||
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<uint16_t> port() const
|
||||
{
|
||||
if (m_yaml["port"])
|
||||
{
|
||||
return m_yaml["port"].as<uint16_t>();
|
||||
}
|
||||
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<uint16_t> 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<detail::CCEngineConfig>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<uint16_t> 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<detail::CCEngineConfig> m_config;
|
||||
};
|
||||
|
||||
@ -58,6 +58,7 @@ int main(int argc, char *argv[])
|
||||
bool justUpdated = false;
|
||||
bool minimized = false;
|
||||
bool startBrowser = false;
|
||||
std::optional<uint16_t> 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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user