| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "stdafx.h"
- #include "YamlConfig.h"
- YamlConfig::YamlConfig()
- {
- try
- {
- YAML::Node node = YAML::LoadFile(YAMLCONFIGFILEPATH);
- if (node["WsServer"])
- {
- this->wsServerIP = node["WsServer"]["IP"].as<string>();
- this->wsServerPort = node["WsServer"]["PORT"].as<int>();
- }
- if (node["ACD"])
- {
- this->acdIP = node["ACD"]["IP"].as<string>();
- this->acdPort = node["ACD"]["PORT"].as<int>();
- }
- if (node["HttpServer"])
- {
- this->httpIP = node["HttpServer"]["IP"].as<string>();
- this->httpPort = node["HttpServer"]["PORT"].as<int>();
- }
- if (node["Wss"])
- {
- this->sslFilePath = node["Wss"]["SSL"].as<string>();
- this->sslPwd = node["Wss"]["PWD"].as<string>();
- this->wssPort = node["Wss"]["PORT"].as<int>();
- }
- }
- catch (const std::exception&)
- {
- // 配置文件 读取异常,重新初始化配置文件
- YAML::Node node;
- std::ofstream fout(YAMLCONFIGFILEPATH);
- node["WsServer"]["IP"] = "127.0.0.1";
- node["WsServer"]["PORT"] = 8811;
- node["ACD"]["IP"] = "127.0.0.1";
- node["ACD"]["PORT"] = 8821;
- node["HttpServer"]["IP"] = "0.0.0.0";
- node["HttpServer"]["PORT"] = "8081";
- node["Wss"]["SSL"] = "server.pem";
- node["Wss"]["PWD"] = "123456";
- node["Wss"]["PORT"] = 8082;
- fout << node;
- fout.close();
- this->wsServerIP = node["WsServer"]["IP"].as<string>();
- this->wsServerPort = node["WsServer"]["PORT"].as<int>();
- this->acdIP = node["ACD"]["IP"].as<string>();
- this->acdPort = node["ACD"]["PORT"].as<int>();
- this->httpIP = node["HttpServer"]["IP"].as<string>();
- this->httpPort = node["HttpServer"]["PORT"].as<int>();
- this->sslFilePath = node["Wss"]["SSL"].as<string>();
- this->sslPwd = node["Wss"]["PWD"].as<string>();
- this->wssPort = node["Wss"]["PORT"].as<int>();
- }
- }
- YamlConfig::~YamlConfig()
- {
- }
- YamlConfig YamlConfig::sp;
|