| 12345678910111213141516171819202122232425262728293031323334353637 |
- #include "RcfConfig.h"
- #include <yaml-cpp/yaml.h>
- #include <fstream>
- using namespace std;
- #pragma comment(lib,"libyaml-cppmd-mt.lib")
- #define YAMLCONFIGFILEPATH "RcfConfig.yml"
- RcfConfig::RcfConfig()
- {
- try
- {
- YAML::Node node = YAML::LoadFile(YAMLCONFIGFILEPATH);
- if (node["Rcf"])
- {
- this->m_RcfIp = node["Rcf"]["IP"].as<string>();
- this->m_RcfPort = node["Rcf"]["PORT"].as<int>();
- }
- }
- catch (const std::exception&)
- {
- // 配置文件 读取异常,重新初始化配置文件
- YAML::Node node;
- std::ofstream fout(YAMLCONFIGFILEPATH);
- node["Rcf"]["IP"] = "127.0.0.1";
- node["Rcf"]["PORT"] = 8821;
-
- fout << node;
- fout.close();
- this->m_RcfIp = node["ACD"]["IP"].as<string>();
- this->m_RcfPort = node["ACD"]["PORT"].as<int>();
- }
- }
- RcfConfig RcfConfig::instance;
|