| | |
| | | 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(); |
| | |
| | | |
| | | void ConfigUtil::writeConfig(libconfig::Config& config) |
| | | { |
| | | config.writeFile("config.cfg"); |
| | | config.writeFile(getConfigPath().c_str()); |
| | | } |
| | | |
| | | int ConfigUtil::readIntConfig(const char* key) |
| | |
| | | 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; |
| | | } |
| | |
| | | |
| | | 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 (...) { |
| | | |
| | |
| | | return volumeList; |
| | | } |
| | | catch (...) { |
| | | |
| | | |
| | | } |
| | | return list<int>(); |
| | | } |
| | |
| | | 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(); |