admin
2024-10-25 0a678d4e8368730e60e17aafbb2f0d055888402a
FloatTrade/ConfigUtil.cpp
@@ -12,10 +12,35 @@
   return file.good(); // 如果文件成功打开,则返回 true
}
string ConfigUtil::getConfigPath()
{
   wchar_t* appDataPath = nullptr;
   CString path;
   // 获取APPData目录路径
   if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath))) {
      std::wcout << L"APPData目录路径: " << appDataPath << std::endl;
      path.Append(appDataPath);
      CoTaskMemFree(appDataPath);  // 释放内存
   }
   else {
      std::wcerr << L"无法获取APPData目录路径" << std::endl;
      return "config.cfg";
   }
   path.Append(L"\\悬浮盯盘");
   // 判断文件夹是否存在
   DWORD fileAttributes = GetFileAttributesW(path);
   if (fileAttributes == INVALID_FILE_ATTRIBUTES) {
      CreateDirectoryW(path, NULL);
   }
   string fpath = StringUtil::cstring2String(path);
   fpath.append("\\config.cfg");
   return  fpath.c_str();
}
void ConfigUtil::readConfig(libconfig::Config& config)
{
   string strConfPath = "config.cfg";
   string strConfPath = getConfigPath();
   if (!fileExists(strConfPath)) {
      std::ofstream file(strConfPath);
      file.is_open();
@@ -36,7 +61,7 @@
void ConfigUtil::writeConfig(libconfig::Config& config)
{
   config.writeFile("config.cfg");
   config.writeFile(getConfigPath().c_str());
}
int ConfigUtil::readIntConfig(const char* key)
@@ -167,11 +192,11 @@
   pos[0] = 0;
   pos[1] = 0;
   try {
      string str =   readStringConfig("sell_rule_show_pos");
      string str = readStringConfig("sell_rule_show_pos");
      // 分隔字符串
      int split_index = str.find(",");
      int x= stoi( str.substr(0, split_index));
      int y = stoi(str.substr(split_index + 1, str.length() - (split_index+1)));
      int x = stoi(str.substr(0, split_index));
      int y = stoi(str.substr(split_index + 1, str.length() - (split_index + 1)));
      pos[0] = x;
      pos[1] = y;
   }
@@ -208,12 +233,12 @@
MyPoint ConfigUtil::getWindowPos()
{
   // 页码位置
   try {
        string data =   readStringConfig("window_pos");
       rapidjson::Document root = JsonUtil::parseUTF8(data);
        return    MyPoint({ root[0].GetInt(), root[1].GetInt()});
      string data = readStringConfig("window_pos");
      rapidjson::Document root = JsonUtil::parseUTF8(data);
      return    MyPoint({ root[0].GetInt(), root[1].GetInt() });
   }
   catch (...) {
@@ -260,7 +285,7 @@
      return volumeList;
   }
   catch (...) {
   }
   return list<int>();
}
@@ -291,7 +316,7 @@
      string code = (*el).first;
      CString name = (*el).second;
      writer.Key(code.c_str());
      writer.String(StringUtil::cstring2String( name).c_str());
      writer.String(StringUtil::cstring2String(name).c_str());
   }
   writer.EndObject();
   const char* json_content = buf.GetString();