diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-04-28 16:42:53 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-04-28 16:42:53 +0000 |
commit | 9fa8edc73b6687bbc0f43743b872af83d4d06759 (patch) | |
tree | 148f4807922cf6e3d2814df0747494b3cece6f87 /protocols/Tox | |
parent | cdd6bf525f77553ed7b30794f24b37dc42f0e434 (diff) |
Tox: updating tox nodes from https://nodes.tox.chat/json
git-svn-id: http://svn.miranda-ng.org/main/trunk@16790 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r-- | protocols/Tox/Tox.vcxproj | 8 | ||||
-rw-r--r-- | protocols/Tox/docs/tox.ini | 103 | ||||
-rw-r--r-- | protocols/Tox/res/resource.rc | 5 | ||||
-rw-r--r-- | protocols/Tox/src/http_request.h | 151 | ||||
-rw-r--r-- | protocols/Tox/src/resource.h | 3 | ||||
-rw-r--r-- | protocols/Tox/src/stdafx.h | 3 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 66 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 166 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.h | 4 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 4 | ||||
-rw-r--r-- | protocols/Tox/src/version.h | 2 |
11 files changed, 277 insertions, 238 deletions
diff --git a/protocols/Tox/Tox.vcxproj b/protocols/Tox/Tox.vcxproj index 15182d3eac..7be529f35b 100644 --- a/protocols/Tox/Tox.vcxproj +++ b/protocols/Tox/Tox.vcxproj @@ -33,12 +33,10 @@ <AdditionalDependencies>Winmm.lib;dnsapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent Condition="'$(Platform)'=='Win32'">
- <Command>xcopy bin\x86\libtox.* "$(SolutionDir)$(Configuration)\Libs\libtox.*" /y
-copy docs\tox.ini "$(SolutionDir)$(Configuration)\Plugins" /y</Command>
+ <Command>xcopy bin\x86\libtox.* "$(SolutionDir)$(Configuration)\Libs\libtox.*" /y</Command>
</PostBuildEvent>
<PostBuildEvent Condition="'$(Platform)'=='x64'">
- <Command>xcopy bin\x64\libtox.* "$(SolutionDir)$(Configuration)64\Libs\libtox.*" /y
-copy docs\tox.ini "$(SolutionDir)$(Configuration)64\Plugins" /y</Command>
+ <Command>xcopy bin\x64\libtox.* "$(SolutionDir)$(Configuration)64\Libs\libtox.*" /y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
@@ -50,4 +48,4 @@ copy docs\tox.ini "$(SolutionDir)$(Configuration)64\Plugins" /y</Command> <ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
</ItemDefinitionGroup>
-</Project>
\ No newline at end of file +</Project>
diff --git a/protocols/Tox/docs/tox.ini b/protocols/Tox/docs/tox.ini deleted file mode 100644 index 12c57eccf0..0000000000 --- a/protocols/Tox/docs/tox.ini +++ /dev/null @@ -1,103 +0,0 @@ -[Dns_toxme.io]
-Domain=toxme.io
-PubKey=1A39E7A5D5FA9CF155C751570A32E625698A60A55F6D88028F949F66144F4F25
-
-[Dns_utox.org]
-Domain=utox.org
-PubKey=D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12
-
-[Node_sonOfRa]
-IPv4=144.76.60.215
-IPv6=2a01:4f8:191:64d6::1
-PubKey=04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F
-Port=33445
-
-[Node_stal]
-IPv4=23.226.230.47
-IPv6=2604:180:1::3ded:b280
-PubKey=A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074
-Port=33445
-
-[Node_SylvieLorxu]
-IPv4=178.21.112.187
-IPv6=2a02:2308::216:3eff:fe82:eaef
-PubKey=4B2C19E924972CB9B57732FB172F8A8604DE13EEDA2A6234E348983344B23057
-Port=33445
-
-[Node_Munrek]
-IPv4=195.154.119.113
-IPv6=2001:bc8:3698:101::1
-PubKey=E398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354
-Port=33445
-
-[Node_nurupo]
-IPv4=192.210.149.121
-PubKey=F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67
-Port=33445
-
-[Node_MartinSchroder]
-IPv4=46.38.239.179
-PubKey=F5A1A38EFB6BD3C2C8AF8B10D85F0F89E931704D349F1D0720C3C4059AF2440A
-Port=33445
-
-[Node_Impyy]
-IPv4=178.62.250.138
-IPv6=2a03:b0c0:2:d0::16:1
-PubKey=788236D34978D1D5BD822F0A5BEBD2C53C64CC31CD3149350EE27D4D9A2F9B6B
-Port=33445
-
-[Node_Manolis]
-IPv4=130.133.110.14
-IPv6=2001:6f8:1c3c:babe::14:1
-PubKey=461FA3776EF0FA655F1A05477DF1B3B614F7D6B124F7DB1DD4FE3C08B03B640F
-Port=33445
-
-[Node_noisykeyboard]
-IPv4=104.167.101.29
-PubKey=5918AC3C06955962A75AD7DF4F80A5D7C34F7DB9E1498D2E0495DE35B3FE8A57
-Port=33445
-
-[Node_Busindre]
-IPv4=205.185.116.116
-PubKey=A179B09749AC826FF01F37A9613F6B57118AE014D4196A0E1105A98F93A54702
-Port=33445
-
-[Node_Busindre]
-IPv4=198.98.51.198
-IPv6=2605:6400:1:fed5:22:45af:ec10:f329
-PubKey=1D5A5F2F5D6233058BF0259B09622FB40B482E4FA0931EB8FD3AB8E7BF7DAF6F
-Port=33445
-
-[Node_fUNKIAM]
-IPv4=80.232.246.79
-PubKey=0B8DCEAA7BDDC44BB11173F987CAE3566A2D7057D8DD3CC642BD472B9391002A
-Port=33445
-
-[Node_ray65536]
-IPv4=108.61.165.198
-PubKey=8E7D0B859922EF569298B4D261A8CCB5FEA14FB91ED412A7603A585A25698832
-Port=33445
-
-[Node_Kr9r0x]
-IPv4=212.71.252.109
-IPv6=2a01:7e00::f03c:91ff:fe69:9912
-PubKey=C4CEB8C7AC607C6B374E2E782B3C00EA3A63B80D4910B8649CCACDD19F260819
-Port=33445
-
-[Node_fluke571]
-IPv4=194.249.212.109
-IPv6=2001:1470:fbfe::109
-PubKey=3CEE1F054081E7A011234883BC4FC39F661A55B73637A5AC293DDF1251D9432B
-Port=33445
-
-[Node_MAH69K]
-IPv4=185.25.116.107
-IPv6=2a00:7a60:0:746b::3
-PubKey=DA4E4ED4B697F2E9B000EEFE3A34B554ACD3F45F5C96EAEA2516DD7FF9AF7B43
-Port=33445
-
-[Node_WIeschie]
-IPv4=192.99.168.140
-IPv6=2607:5300:100:200::::667
-PubKey=6A4D0607A296838434A6A7DDF99F50EF9D60A2C510BBF31FE538A25CB6B4652F
-Port=33445
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc index 151a9163f6..77d0bd1bef 100644 --- a/protocols/Tox/res/resource.rc +++ b/protocols/Tox/res/resource.rc @@ -154,6 +154,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN
CONTROL "",IDC_NODESLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,8,7,295,201
PUSHBUTTON "Add",IDC_ADDNODE,253,213,50,14
+ PUSHBUTTON "Update",IDC_UPDATENODES,8,213,50,14
END
IDD_NODE_EDITOR DIALOGEX 0, 0, 213, 118
@@ -359,9 +360,9 @@ END // AFX_DIALOG_LAYOUT
//
-IDD_OPTIONS_MULTIMEDIA AFX_DIALOG_LAYOUT
+IDD_OPTIONS_MULTIMEDIA AFX_DIALOG_LAYOUT
BEGIN
- 0
+ 0x0000
END
#endif // English resources
diff --git a/protocols/Tox/src/http_request.h b/protocols/Tox/src/http_request.h new file mode 100644 index 0000000000..e52de2c179 --- /dev/null +++ b/protocols/Tox/src/http_request.h @@ -0,0 +1,151 @@ +#ifndef _HTTP_REQUEST_H_
+#define _HTTP_REQUEST_H_
+
+class HttpRequestException
+{
+ CMStringA message;
+
+public:
+ HttpRequestException(const char *message) :
+ message(message)
+ {
+ }
+
+ const char* what() const throw()
+ {
+ return message.c_str();
+ }
+};
+
+class HttpRequest : protected NETLIBHTTPREQUEST
+{
+private:
+ CMStringA m_szUrl;
+
+ void Init(int type)
+ {
+ cbSize = sizeof(NETLIBHTTPREQUEST);
+ requestType = type;
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
+ szUrl = NULL;
+ headers = NULL;
+ headersCount = 0;
+ pData = NULL;
+ dataLength = 0;
+ resultCode = 0;
+ szResultDescr = NULL;
+ nlc = NULL;
+ timeout = 0;
+ }
+
+protected:
+ enum HttpRequestUrlFormat { FORMAT };
+
+ void AddHeader(LPCSTR szName, LPCSTR szValue)
+ {
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
+ headers[headersCount].szName = mir_strdup(szName);
+ headers[headersCount].szValue = mir_strdup(szValue);
+ headersCount++;
+ }
+
+ void AddBasicAuthHeader(LPCSTR szLogin, LPCSTR szPassword)
+ {
+ char cPair[128];
+ mir_snprintf(
+ cPair,
+ _countof(cPair),
+ "%s:%s",
+ szLogin,
+ szPassword);
+
+ char *ePair = (char *)mir_base64_encode((BYTE*)cPair, (UINT)mir_strlen(cPair));
+
+ char value[128];
+ mir_snprintf(
+ value,
+ _countof(value),
+ "Basic %s",
+ ePair);
+
+ mir_free(ePair);
+
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
+ headers[headersCount].szName = mir_strdup("Authorization");
+ headers[headersCount].szValue = mir_strdup(value);
+ headersCount++;
+ }
+
+ void AddBearerAuthHeader(LPCSTR szValue)
+ {
+ char value[128];
+ mir_snprintf(
+ value,
+ _countof(value),
+ "Bearer %s",
+ szValue);
+
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
+ headers[headersCount].szName = mir_strdup("Authorization");
+ headers[headersCount].szValue = mir_strdup(value);
+ headersCount++;
+ }
+
+ void AddUrlParameter(const char *urlFormat, ...)
+ {
+ va_list urlArgs;
+ va_start(urlArgs, urlFormat);
+ m_szUrl += m_szUrl.Find('?') == -1 ? '?' : '&';
+ m_szUrl.AppendFormatV(urlFormat, urlArgs);
+ va_end(urlArgs);
+ }
+
+ void SetData(const char *data, size_t size)
+ {
+ if (pData != NULL)
+ mir_free(pData);
+
+ dataLength = (int)size;
+ pData = (char*)mir_alloc(size);
+ memcpy(pData, data, size);
+ }
+
+public:
+ HttpRequest(int type, LPCSTR url)
+ {
+ Init(type);
+
+ m_szUrl = url;
+ }
+
+ HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...)
+ {
+ Init(type);
+
+ va_list formatArgs;
+ va_start(formatArgs, urlFormat);
+ m_szUrl.AppendFormatV(urlFormat, formatArgs);
+ va_end(formatArgs);
+ }
+
+ ~HttpRequest()
+ {
+ for (int i = 0; i < headersCount; i++)
+ {
+ mir_free(headers[i].szName);
+ mir_free(headers[i].szValue);
+ }
+ mir_free(headers);
+ if (pData)
+ mir_free(pData);
+ }
+
+ NETLIBHTTPREQUEST* Send(HANDLE hNetlibConnection)
+ {
+ m_szUrl.Replace('\\', '/');
+ szUrl = m_szUrl.GetBuffer();
+ return (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibConnection, (LPARAM)this);
+ }
+};
+
+#endif //_HTTP_REQUEST_H_
\ No newline at end of file diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h index 5f21b0905b..ae4158d754 100644 --- a/protocols/Tox/src/resource.h +++ b/protocols/Tox/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by w:\miranda-ng\protocols\Tox\res\resource.rc
+// Used by D:\Projects\MirandaNG\protocols\Tox\res\resource.rc
//
#define IDI_TOX 100
#define IDD_USER_INFO 101
@@ -42,6 +42,7 @@ #define IDC_NODESLIST 1015
#define IDC_ADDNODE 1016
#define IDC_IPV4 1017
+#define IDC_UPDATENODES 1081
#define IDC_IPV6 1018
#define IDC_PORT 1019
#define IDC_PKEY 1020
diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h index 21a3f7fa2a..12dfcc7845 100644 --- a/protocols/Tox/src/stdafx.h +++ b/protocols/Tox/src/stdafx.h @@ -42,6 +42,7 @@ DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0 #include <m_folders.h>
#include <m_assocmgr.h>
#include <m_json.h>
+#include <m_http.h>
#include <tox.h>
#include <ToxAV.h>
@@ -78,7 +79,7 @@ extern HINSTANCE g_hInstance; #define TOX_MAX_CALLS 1
#define TOX_INI_PATH "%miranda_path%\\Plugins\\tox.ini"
-#define TOX_JSON_PATH "%miranda_path%\\Plugins\\tox.json"
+#define TOX_JSON_PATH "%miranda_userdata%\\tox.json"
#define TOX_SETTINGS_ID "ToxID"
#define TOX_SETTINGS_DNS "DnsID"
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 65934e533a..1090b75e0c 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -45,44 +45,14 @@ void CToxProto::BootstrapNodesFromDb(bool isIPv6) }
}
-void CToxProto::BootstrapNodesFromIni(bool isIPv6)
-{
- if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH))))
- {
- char fileName[MAX_PATH];
- mir_strcpy(fileName, VARS(TOX_INI_PATH));
-
- char *section, sections[MAX_PATH], value[MAX_PATH];
- GetPrivateProfileSectionNamesA(sections, _countof(sections), fileName);
- section = sections;
- while (*section != NULL)
- {
- if (strstr(section, TOX_SETTINGS_NODE_PREFIX) == section)
- {
- GetPrivateProfileStringA(section, "IPv4", NULL, value, _countof(value), fileName);
- ptrA address(mir_strdup(value));
- int port = GetPrivateProfileIntA(section, "Port", 33445, fileName);
- GetPrivateProfileStringA(section, "PubKey", NULL, value, _countof(value), fileName);
- ptrA pubKey(mir_strdup(value));
- BootstrapNode(address, port, pubKey);
- if (isIPv6)
- {
- GetPrivateProfileStringA(section, "IPv6", NULL, value, _countof(value), fileName);
- address = mir_strdup(value);
- BootstrapNode(address, port, pubKey);
- }
- }
- section += mir_strlen(section) + 1;
- }
- }
-}
-
void CToxProto::BootstrapNodesFromJson(bool isIPv6)
{
char *json = NULL;
ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH))));
- // todo: download from https://nodes.tox.chat/json
+
+ if (!IsFileExists(path))
+ UpdateNodes();
if (IsFileExists(path))
{
@@ -127,10 +97,38 @@ void CToxProto::BootstrapNodes() logger->Log(__FUNCTION__": bootstraping DHT");
bool isIPv6 = getBool("EnableIPv6", 0);
BootstrapNodesFromDb(isIPv6);
- BootstrapNodesFromIni(isIPv6);
BootstrapNodesFromJson(isIPv6);
}
+void CToxProto::UpdateNodes()
+{
+ ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH))));
+
+ if (!IsFileExists(path))
+ {
+ HANDLE hProfile = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (hProfile == NULL)
+ {
+ logger->Log(__FUNCTION__": failed to create tox.json");
+ return;
+ }
+ CloseHandle(hProfile);
+ }
+
+ HttpRequest request(REQUEST_GET, "https://nodes.tox.chat/json");
+ NLHR_PTR response(request.Send(hNetlib));
+
+ if (response->resultCode == 200 && response->pData)
+ {
+ FILE *hFile = _tfopen(path, _T("w"));
+ if (hFile)
+ {
+ fwrite(response->pData, sizeof(char), response->dataLength, hFile);
+ fclose(hFile);
+ }
+ }
+}
+
void CToxProto::TryConnect()
{
if (toxThread != NULL)
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index db44e8f1af..8eb0b05026 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -389,9 +389,11 @@ BOOL CCtrlNodeList::OnNotify(int idCtrl, NMHDR *pnmh) CToxOptionsNodeList::CToxOptionsNodeList(CToxProto *proto)
: CSuper(proto, IDD_OPTIONS_NODES, false),
- m_nodes(this, IDC_NODESLIST), m_addNode(this, IDC_ADDNODE)
+ m_nodes(this, IDC_NODESLIST), m_addNode(this, IDC_ADDNODE),
+ m_updateNodes(this, IDC_UPDATENODES)
{
m_addNode.OnClick = Callback(this, &CToxOptionsNodeList::OnAddNode);
+ m_updateNodes.OnClick = Callback(this, &CToxOptionsNodeList::OnUpdateNodes);
m_nodes.OnClick = Callback(this, &CToxOptionsNodeList::OnNodeListClick);
m_nodes.OnDoubleClick = Callback(this, &CToxOptionsNodeList::OnNodeListDoubleClick);
m_nodes.OnKeyDown = Callback(this, &CToxOptionsNodeList::OnNodeListKeyDown);
@@ -418,37 +420,88 @@ void CToxOptionsNodeList::OnInitDialog() m_nodes.AddGroup(0, TranslateT("Common nodes"));
m_nodes.AddGroup(1, TranslateT("User nodes"));
- ////////////////////////////////////////
+ ReloadNodeList();
+}
- int iItem = -1;
+void CToxOptionsNodeList::OnAddNode(CCtrlBase*)
+{
+ CToxNodeEditor nodeEditor(-1, &m_nodes);
+ if (nodeEditor.DoModal())
+ SendMessage(GetParent(m_hwnd), PSM_CHANGED, 0, 0);
+}
+
+void CToxOptionsNodeList::OnUpdateNodes(CCtrlBase*)
+{
+ m_proto->UpdateNodes();
+
+ ReloadNodeList();
+}
- if (CToxProto::IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH))))
+void CToxOptionsNodeList::OnNodeListDoubleClick(CCtrlBase*)
+{
+ int iItem = m_nodes.GetNextItem(-1, LVNI_SELECTED);
+
+ LVITEM lvi = { 0 };
+ lvi.iItem = iItem;
+ lvi.mask = LVIF_GROUPID;
+ m_nodes.GetItem(&lvi);
+ if (lvi.iGroupId || (lvi.iGroupId == 0 && lvi.iItem == -1))
{
- char fileName[MAX_PATH];
- mir_strcpy(fileName, VARS(TOX_INI_PATH));
+ CToxNodeEditor nodeEditor(lvi.iItem, &m_nodes);
+ if (nodeEditor.DoModal())
+ SendMessage(GetParent(m_hwnd), PSM_CHANGED, 0, 0);
+ }
+}
- char *section, sections[MAX_PATH], value[MAX_PATH];
- GetPrivateProfileSectionNamesA(sections, _countof(sections), fileName);
- section = sections;
- while (*section != NULL)
+void CToxOptionsNodeList::OnNodeListClick(CCtrlListView::TEventInfo *evt)
+{
+ LVITEM lvi = { 0 };
+ lvi.iItem = evt->nmlvia->iItem;
+ lvi.mask = LVIF_GROUPID;
+ m_nodes.GetItem(&lvi);
+ lvi.iSubItem = evt->nmlvia->iSubItem;
+ if (lvi.iGroupId && lvi.iSubItem == 4)
+ {
+ CToxNodeEditor nodeEditor(lvi.iItem, &m_nodes);
+ if (nodeEditor.DoModal())
+ SendMessage(GetParent(GetParent(m_hwnd)), PSM_CHANGED, 0, 0);
+ }
+ else if (lvi.iGroupId && lvi.iSubItem == 5)
+ {
+ if (MessageBox(m_hwnd, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
{
- if (strstr(section, TOX_SETTINGS_NODE_PREFIX) == section)
- {
- GetPrivateProfileStringA(section, "IPv4", NULL, value, _countof(value), fileName);
- iItem = m_nodes.AddItem(mir_a2t(value), -1, NULL, 0);
-
- GetPrivateProfileStringA(section, "IPv6", NULL, value, _countof(value), fileName);
- m_nodes.SetItem(iItem, 1, mir_a2t(value));
+ m_nodes.DeleteItem(lvi.iItem);
+ SendMessage(GetParent(GetParent(m_hwnd)), PSM_CHANGED, 0, 0);
+ }
+ }
+}
- GetPrivateProfileStringA(section, "Port", NULL, value, _countof(value), fileName);
- m_nodes.SetItem(iItem, 2, mir_a2t(value));
+void CToxOptionsNodeList::OnNodeListKeyDown(CCtrlListView::TEventInfo *evt)
+{
+ LVITEM lvi = { 0 };
+ lvi.iItem = m_nodes.GetSelectionMark();
+ lvi.mask = LVIF_GROUPID;
+ m_nodes.GetItem(&lvi);
- GetPrivateProfileStringA(section, "PubKey", NULL, value, _countof(value), fileName);
- m_nodes.SetItem(iItem, 3, mir_a2t(value));
- }
- section += mir_strlen(section) + 1;
+ if (lvi.iGroupId && lvi.iItem != -1 && (evt->nmlvkey)->wVKey == VK_DELETE)
+ {
+ if (MessageBox(
+ GetParent(m_hwnd),
+ TranslateT("Are you sure?"),
+ TranslateT("Node deleting"),
+ MB_YESNO | MB_ICONWARNING) == IDYES)
+ {
+ m_nodes.DeleteItem(lvi.iItem);
+ SendMessage(GetParent(GetParent(m_hwnd)), PSM_CHANGED, 0, 0);
}
}
+}
+
+void CToxOptionsNodeList::ReloadNodeList()
+{
+ m_nodes.DeleteAllItems();
+
+ int iItem = -1;
ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH))));
if (CToxProto::IsFileExists(path))
@@ -524,73 +577,6 @@ void CToxOptionsNodeList::OnInitDialog() }
}
-void CToxOptionsNodeList::OnAddNode(CCtrlBase*)
-{
- CToxNodeEditor nodeEditor(-1, &m_nodes);
- if (nodeEditor.DoModal())
- SendMessage(GetParent(m_hwnd), PSM_CHANGED, 0, 0);
-}
-
-void CToxOptionsNodeList::OnNodeListDoubleClick(CCtrlBase*)
-{
- int iItem = m_nodes.GetNextItem(-1, LVNI_SELECTED);
-
- LVITEM lvi = { 0 };
- lvi.iItem = iItem;
- lvi.mask = LVIF_GROUPID;
- m_nodes.GetItem(&lvi);
- if (lvi.iGroupId || (lvi.iGroupId == 0 && lvi.iItem == -1))
- {
- CToxNodeEditor nodeEditor(lvi.iItem, &m_nodes);
- if (nodeEditor.DoModal())
- SendMessage(GetParent(m_hwnd), PSM_CHANGED, 0, 0);
- }
-}
-
-void CToxOptionsNodeList::OnNodeListClick(CCtrlListView::TEventInfo *evt)
-{
- LVITEM lvi = { 0 };
- lvi.iItem = evt->nmlvia->iItem;
- lvi.mask = LVIF_GROUPID;
- m_nodes.GetItem(&lvi);
- lvi.iSubItem = evt->nmlvia->iSubItem;
- if (lvi.iGroupId && lvi.iSubItem == 4)
- {
- CToxNodeEditor nodeEditor(lvi.iItem, &m_nodes);
- if (nodeEditor.DoModal())
- SendMessage(GetParent(GetParent(m_hwnd)), PSM_CHANGED, 0, 0);
- }
- else if (lvi.iGroupId && lvi.iSubItem == 5)
- {
- if (MessageBox(m_hwnd, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
- {
- m_nodes.DeleteItem(lvi.iItem);
- SendMessage(GetParent(GetParent(m_hwnd)), PSM_CHANGED, 0, 0);
- }
- }
-}
-
-void CToxOptionsNodeList::OnNodeListKeyDown(CCtrlListView::TEventInfo *evt)
-{
- LVITEM lvi = { 0 };
- lvi.iItem = m_nodes.GetSelectionMark();
- lvi.mask = LVIF_GROUPID;
- m_nodes.GetItem(&lvi);
-
- if (lvi.iGroupId && lvi.iItem != -1 && (evt->nmlvkey)->wVKey == VK_DELETE)
- {
- if (MessageBox(
- GetParent(m_hwnd),
- TranslateT("Are you sure?"),
- TranslateT("Node deleting"),
- MB_YESNO | MB_ICONWARNING) == IDYES)
- {
- m_nodes.DeleteItem(lvi.iItem);
- SendMessage(GetParent(GetParent(m_hwnd)), PSM_CHANGED, 0, 0);
- }
- }
-}
-
void CToxOptionsNodeList::OnApply()
{
char setting[MAX_PATH];
diff --git a/protocols/Tox/src/tox_options.h b/protocols/Tox/src/tox_options.h index a3550bf454..675d9a2294 100644 --- a/protocols/Tox/src/tox_options.h +++ b/protocols/Tox/src/tox_options.h @@ -117,12 +117,16 @@ private: CCtrlNodeList m_nodes;
CCtrlButton m_addNode;
+ CCtrlButton m_updateNodes;
protected:
void OnInitDialog();
void OnApply();
+ void ReloadNodeList();
+
void OnAddNode(CCtrlBase*);
+ void OnUpdateNodes(CCtrlBase*);
void OnNodeListDoubleClick(CCtrlBase*);
void OnNodeListClick(CCtrlListView::TEventInfo *evt);
void OnNodeListKeyDown(CCtrlListView::TEventInfo *evt);
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index fa138d3c23..996c34a681 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -95,9 +95,11 @@ private: void BootstrapNode(const char *address, int port, const char *pubKey);
void BootstrapNodesFromDb(bool isIPv6);
- void BootstrapNodesFromIni(bool isIPv6);
void BootstrapNodesFromJson(bool isIPv6);
void BootstrapNodes();
+
+ void UpdateNodes();
+
void TryConnect();
void CheckConnection(int &retriesCount);
diff --git a/protocols/Tox/src/version.h b/protocols/Tox/src/version.h index 4ab90defe2..c78311d2b6 100644 --- a/protocols/Tox/src/version.h +++ b/protocols/Tox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 1
-#define __BUILD_NUM 20
+#define __BUILD_NUM 21
#include <stdver.h>
|