diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-04-28 13:14:07 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-04-28 13:14:07 +0000 |
commit | 71dc907c4f7bac0cb099a3006e14b88842065e9a (patch) | |
tree | c574a893a688e8c4b7603d7c1f197f83582ab204 /protocols/Tox/src/tox_options.cpp | |
parent | 57efb887b79a79dca57e940aa1976dbf9b2bde31 (diff) |
Tox: loading nodes from json
git-svn-id: http://svn.miranda-ng.org/main/trunk@16788 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_options.cpp')
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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);
|