#include "stdafx.h" #include "YamlConfig.h" YamlConfig::YamlConfig() { try { YAML::Node node = YAML::LoadFile(YAMLCONFIGFILEPATH); if (node["WsServer"]) { this->wsServerIP = node["WsServer"]["IP"].as(); this->wsServerPort = node["WsServer"]["PORT"].as(); } if (node["ACD"]) { this->acdIP = node["ACD"]["IP"].as(); this->acdPort = node["ACD"]["PORT"].as(); } if (node["HttpServer"]) { this->httpIP = node["HttpServer"]["IP"].as(); this->httpPort = node["HttpServer"]["PORT"].as(); } if (node["Wss"]) { this->sslFilePath = node["Wss"]["SSL"].as(); this->sslPwd = node["Wss"]["PWD"].as(); this->wssPort = node["Wss"]["PORT"].as(); } } 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(); this->wsServerPort = node["WsServer"]["PORT"].as(); this->acdIP = node["ACD"]["IP"].as(); this->acdPort = node["ACD"]["PORT"].as(); this->httpIP = node["HttpServer"]["IP"].as(); this->httpPort = node["HttpServer"]["PORT"].as(); this->sslFilePath = node["Wss"]["SSL"].as(); this->sslPwd = node["Wss"]["PWD"].as(); this->wssPort = node["Wss"]["PORT"].as(); } } YamlConfig::~YamlConfig() { } YamlConfig YamlConfig::sp;