From fa58f69fe117640e29cefb1b699bede4d045bc2f Mon Sep 17 00:00:00 2001 From: aunsane Date: Sat, 3 Mar 2018 16:35:09 +0300 Subject: Tox: - updated toxcore due to release v0.2 - removed message correction - reworked nodes update --- protocols/Tox/src/tox_options.cpp | 44 ++++++++++----------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) (limited to 'protocols/Tox/src/tox_options.cpp') diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 119bce5a0d..f52202c1eb 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -439,42 +439,20 @@ void CToxOptionsNodeList::ReloadNodeList() int iItem = -1; - VARSW path(_A2W(TOX_JSON_PATH)); - if (CToxProto::IsFileExists(path)) { - ptrA json; - - FILE *hFile = _wfopen(path, L"r"); - if (hFile != nullptr) { - _fseeki64(hFile, 0, SEEK_END); - size_t size = _ftelli64(hFile); - json = (char*)mir_calloc(size); - rewind(hFile); - fread(json, sizeof(char), size, hFile); - fclose(hFile); - } - - if (json) { - JSONNode root = JSONNode::parse(json); - if (!root.empty()) { - JSONNode nodes = root.at("nodes").as_array(); - for (size_t i = 0; i < nodes.size(); i++) { - JSONNode node = nodes[i]; + JSONNode nodes = m_proto->ParseNodes(); + for (const auto &node : nodes) { + ptrW ipv4(mir_utf8decodeW(node.at("ipv4").as_string().c_str())); + iItem = m_nodes.AddItem(ipv4, -1, NULL, 0); - ptrW ipv4(mir_utf8decodeW(node.at("ipv4").as_string().c_str())); - iItem = m_nodes.AddItem(ipv4, -1, NULL, 0); + ptrW ipv6(mir_utf8decodeW(node.at("ipv6").as_string().c_str())); + if (mir_wstrcmp(ipv6, L"-")) + m_nodes.SetItem(iItem, 1, ipv6); - ptrW ipv6(mir_utf8decodeW(node.at("ipv6").as_string().c_str())); - if (mir_wstrcmp(ipv6, L"-")) - m_nodes.SetItem(iItem, 1, ipv6); + ptrW port(mir_utf8decodeW(node.at("port").as_string().c_str())); + m_nodes.SetItem(iItem, 2, port); - ptrW port(mir_utf8decodeW(node.at("port").as_string().c_str())); - m_nodes.SetItem(iItem, 2, port); - - ptrW pubKey(mir_utf8decodeW(node.at("public_key").as_string().c_str())); - m_nodes.SetItem(iItem, 3, pubKey); - } - } - } + ptrW pubKey(mir_utf8decodeW(node.at("public_key").as_string().c_str())); + m_nodes.SetItem(iItem, 3, pubKey); } char module[MAX_PATH], setting[MAX_PATH]; -- cgit v1.2.3