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)