From 71dc907c4f7bac0cb099a3006e14b88842065e9a Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 28 Apr 2016 13:14:07 +0000 Subject: Tox: loading nodes from json git-svn-id: http://svn.miranda-ng.org/main/trunk@16788 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_options.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (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 7b1a89ad16..db44e8f1af 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -450,6 +450,49 @@ void CToxOptionsNodeList::OnInitDialog() } } + ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH)))); + if (CToxProto::IsFileExists(path)) + { + char *json = NULL; + + FILE *hFile = _tfopen(path, L"r"); + if (hFile != NULL) + { + _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]; + + TCHAR *ipv4 = mir_utf8decodeT(node.at("ipv4").as_string().c_str()); + iItem = m_nodes.AddItem(ipv4, -1, NULL, 0); + + TCHAR *ipv6 = mir_utf8decodeT(node.at("ipv6").as_string().c_str()); + if (mir_tstrcmp(ipv6, _T("-"))) + m_nodes.SetItem(iItem, 1, ipv6); + + TCHAR *port = mir_utf8decodeT(node.at("port").as_string().c_str()); + m_nodes.SetItem(iItem, 2, port); + + TCHAR *pubKey = mir_utf8decodeT(node.at("public_key").as_string().c_str()); + m_nodes.SetItem(iItem, 3, pubKey); + } + } + } + } + char module[MAX_PATH], setting[MAX_PATH]; mir_snprintf(module, "%s_Nodes", m_proto->m_szModuleName); int nodeCount = db_get_w(NULL, module, TOX_SETTINGS_NODE_COUNT, 0); -- cgit v1.2.3