From 8ea6d363df77de2dca288397da8d4f9c3d3a5c4d Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 18 十月 2024 18:41:57 +0800 Subject: [PATCH] '项目完善' --- FloatTrade/ConfigUtil.cpp | 128 +++++++++++++++++++++++++++++------------- 1 files changed, 88 insertions(+), 40 deletions(-) diff --git a/FloatTrade/ConfigUtil.cpp b/FloatTrade/ConfigUtil.cpp index ee39400..57f8929 100644 --- a/FloatTrade/ConfigUtil.cpp +++ b/FloatTrade/ConfigUtil.cpp @@ -4,6 +4,8 @@ #include <iostream> #include <fstream> #include "../common/JsonUtil.h" +#include "../common/TimeUtil.h" + bool fileExists(const std::string& filename) { std::ifstream file(filename); @@ -109,7 +111,8 @@ libconfig::Config mConfig; readConfig(mConfig); libconfig::Setting& root = mConfig.getRoot(); - root.remove(key); + root.remove(key.c_str()); + writeConfig(mConfig); } bool ConfigUtil::isTradeRefresh() @@ -203,19 +206,19 @@ setStringConfig("sell_rule_show_pos", pos); } -POINT ConfigUtil::getWindowPos() +MyPoint ConfigUtil::getWindowPos() { // 页码位置 try { string data = readStringConfig("window_pos"); rapidjson::Document root = JsonUtil::parseUTF8(data); - return POINT({ root[0].GetInt(), root[1].GetInt()}); + return MyPoint({ root[0].GetInt(), root[1].GetInt()}); } catch (...) { } - return POINT({ 0,0 }); + return MyPoint({ 0,0 }); @@ -244,57 +247,102 @@ setIntConfig("ths_auto_refresh_time_space", ms); } -std::list<POINT> ConfigUtil::getThsAutoClickPositions() +list<int> ConfigUtil::getVolumesSetting() { - std::list<POINT> posList; try { - string result = readStringConfig("ths_auto_click_positions"); - rapidjson::Document root = JsonUtil::parseUTF8(result); - for (rapidjson::SizeType i = 0; i < root.GetArray().Size(); i++) { - posList.push_back(POINT({ root.GetArray()[i].GetArray()[0].GetInt(),root.GetArray()[i].GetArray()[1].GetInt() })); + list<int> volumeList; + string result = readStringConfig("volume_settings"); + auto doc = JsonUtil::parseUTF8(result); + auto array = doc.GetArray(); + for (int i = 0; i < array.Size(); i++) { + volumeList.push_back(array[i].GetInt()); + } + return volumeList; + } + catch (...) { + + } + return list<int>(); +} + +void ConfigUtil::setVolumesSetting(list<int> volumes) +{ + string st = "["; + int index = 0; + for (list<int>::iterator e = volumes.begin(); e != volumes.end(); ++e) { + index++; + st.append(to_string(*e)); + if (index != volumes.size()) { + st.append(","); + } + } + st.append("]"); + setStringConfig("volume_settings", st); +} + + +void ConfigUtil::setCodeNames(map<string, CString> codeNameMap) +{ + // 将map转为json + rapidjson::StringBuffer buf; + rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf); + writer.StartObject(); + for (map<string, CString>::iterator el = codeNameMap.begin(); el != codeNameMap.end(); el++) { + string code = (*el).first; + CString name = (*el).second; + writer.Key(code.c_str()); + writer.String(StringUtil::cstring2String( name).c_str()); + } + writer.EndObject(); + const char* json_content = buf.GetString(); + string key = "code_name_map-"; + key.append(TimeUtil::getNowTime("%Y%m%d")); + setStringConfig(key.c_str(), json_content); + // 删除过期的代码数据 + list<string> kyes = getKeys(); + for (auto e = kyes.begin(); e != kyes.end(); ++e) { + string k = *e; + if (!k._Equal(key) && k.find("code_name_map-") == 0) { + delKey(k); + } + } +} + +map<string, CString> ConfigUtil::getCodeNames() +{ + map<string, CString> m; + try { + string key = "code_name_map-"; + key.append(TimeUtil::getNowTime("%Y%m%d")); + string result = readStringConfig(key.c_str()); + if (!result.empty()) { + auto doc = JsonUtil::parseUTF8(result); + auto root = doc.GetObjectW(); + for (auto e = root.MemberBegin(); e != root.MemberEnd(); ++e) { + string code = (*e).name.GetString(); + string name = (*e).value.GetString(); + m[code] = CString(name.c_str()); + } } } catch (...) { - } - - return posList; + return m; } -void ConfigUtil::setThsAutoClickPositions(std::list<POINT> posList) +void ConfigUtil::setBuyMoney(int money) { - string st = "["; - - rapidjson::StringBuffer buf; - rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf); - writer.StartArray(); - for (std::list<POINT>::iterator el = posList.begin(); el != posList.end(); el++) { - POINT p = *el; - writer.StartArray(); - writer.Int(p.x); - writer.Int(p.y); - writer.EndArray(); - } - writer.EndArray(); - const char* json_content = buf.GetString(); - setStringConfig("ths_auto_click_positions",string(json_content)); - + setIntConfig("buy_money", money); } - -int ConfigUtil::getThsAutoClickTimeSpace() +int ConfigUtil::getBuyMoney() { try { - return readIntConfig("ths_auto_click_time_space"); + return readIntConfig("buy_money"); } catch (...) { - + // 默认2w + return 20000; } - return 0; -} - -void ConfigUtil::setThsAutoClickTimeSpace(int ms) -{ - setIntConfig("ths_auto_click_time_space", ms); } -- Gitblit v1.8.0