summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-08-21 21:28:58 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-08-21 21:28:58 +0300
commit340910bcc3aaea0fb48a8679cf93e855b413fdc9 (patch)
tree552bfa28cf7ccc20573d0997f1e363daa541b5c0
parent43bc63255af474749234ee04dda76da8e136514b (diff)
Tox:
- fixes #898 (Tox: usability issues); - fixes #893 (Tox: failed to connect to DHT); - massive code cleaning;
-rw-r--r--protocols/Tox/src/tox_accounts.cpp6
-rw-r--r--protocols/Tox/src/tox_avatars.cpp64
-rw-r--r--protocols/Tox/src/tox_bootstrap.cpp57
-rw-r--r--protocols/Tox/src/tox_connection.cpp33
-rw-r--r--protocols/Tox/src/tox_contacts.cpp109
-rw-r--r--protocols/Tox/src/tox_core.cpp26
-rw-r--r--protocols/Tox/src/tox_events.cpp5
-rw-r--r--protocols/Tox/src/tox_icons.cpp2
-rw-r--r--protocols/Tox/src/tox_menus.cpp4
-rw-r--r--protocols/Tox/src/tox_messages.cpp26
-rw-r--r--protocols/Tox/src/tox_multimedia.cpp35
-rw-r--r--protocols/Tox/src/tox_options.cpp132
-rw-r--r--protocols/Tox/src/tox_profile.cpp39
-rw-r--r--protocols/Tox/src/tox_proto.cpp39
-rw-r--r--protocols/Tox/src/tox_proto.h2
-rw-r--r--protocols/Tox/src/tox_search.cpp38
-rw-r--r--protocols/Tox/src/tox_services.cpp3
-rw-r--r--protocols/Tox/src/tox_transfer.cpp87
-rw-r--r--protocols/Tox/src/tox_utils.cpp29
19 files changed, 254 insertions, 482 deletions
diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp
index f6e8f4ddd3..fa4120abfe 100644
--- a/protocols/Tox/src/tox_accounts.cpp
+++ b/protocols/Tox/src/tox_accounts.cpp
@@ -46,11 +46,9 @@ int CToxProto::OnAccountRenamed(WPARAM, LPARAM)
ptrW newPath(GetToxProfilePath());
wchar_t oldPath[MAX_PATH];
- mir_snwprintf(oldPath, MAX_PATH, L"%s\\%s.tox", VARSW(L"%miranda_userdata%"), accountName);
+ mir_snwprintf(oldPath, MAX_PATH, L"%s\\%s.tox", VARSW(L"%miranda_userdata%"), wszAccountName);
_wrename(oldPath, newPath);
- mir_free(accountName);
- accountName = mir_wstrdup(m_tszUserName);
-
+ wszAccountName = mir_wstrdup(m_tszUserName);
return 0;
}
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp
index 3c3bcbaaeb..871276e288 100644
--- a/protocols/Tox/src/tox_avatars.cpp
+++ b/protocols/Tox/src/tox_avatars.cpp
@@ -17,16 +17,15 @@ wchar_t* CToxProto::GetAvatarFilePath(MCONTACT hContact)
if (hContact && mir_wstrlen(address) > TOX_PUBLIC_KEY_SIZE * 2)
address[TOX_PUBLIC_KEY_SIZE * 2] = 0;
- mir_snwprintf(path, MAX_PATH, L"%s\\%s.png", path, address);
+ mir_snwprintf(path, MAX_PATH, L"%s\\%s.png", path, address);
return path;
}
void CToxProto::SetToxAvatar(const wchar_t* path)
{
FILE *hFile = _wfopen(path, L"rb");
- if (!hFile)
- {
+ if (!hFile) {
debugLogA(__FUNCTION__": failed to open avatar file");
return;
}
@@ -34,16 +33,14 @@ void CToxProto::SetToxAvatar(const wchar_t* path)
fseek(hFile, 0, SEEK_END);
size_t length = ftell(hFile);
rewind(hFile);
- if (length > TOX_MAX_AVATAR_SIZE)
- {
+ if (length > TOX_MAX_AVATAR_SIZE) {
fclose(hFile);
debugLogA(__FUNCTION__": new avatar size is excessive");
return;
}
uint8_t *data = (uint8_t*)mir_alloc(length);
- if (fread(data, sizeof(uint8_t), length, hFile) != length)
- {
+ if (fread(data, sizeof(uint8_t), length, hFile) != length) {
fclose(hFile);
debugLogA(__FUNCTION__": failed to read avatar file");
mir_free(data);
@@ -54,10 +51,8 @@ void CToxProto::SetToxAvatar(const wchar_t* path)
DBVARIANT dbv;
uint8_t hash[TOX_HASH_LENGTH];
tox_hash(hash, data, length);
- if (!db_get(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
- {
- if (memcmp(hash, dbv.pbVal, TOX_HASH_LENGTH) == 0)
- {
+ if (!db_get(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv)) {
+ if (memcmp(hash, dbv.pbVal, TOX_HASH_LENGTH) == 0) {
db_free(&dbv);
mir_free(data);
debugLogA(__FUNCTION__": new avatar is same with old");
@@ -68,16 +63,13 @@ void CToxProto::SetToxAvatar(const wchar_t* path)
db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH);
- if (IsOnline())
- {
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
- {
+ if (IsOnline()) {
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
continue;
int32_t friendNumber = GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
+ if (friendNumber == UINT32_MAX) {
mir_free(data);
return;
}
@@ -86,8 +78,7 @@ void CToxProto::SetToxAvatar(const wchar_t* path)
TOX_ERR_FILE_SEND error;
uint32_t fileNumber = tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error);
- if (error != TOX_ERR_FILE_SEND_OK)
- {
+ if (error != TOX_ERR_FILE_SEND_OK) {
mir_free(data);
debugLogA(__FUNCTION__": failed to set new avatar (%d)", error);
return;
@@ -107,8 +98,7 @@ void CToxProto::SetToxAvatar(const wchar_t* path)
INT_PTR CToxProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam)
{
- switch (wParam)
- {
+ switch (wParam) {
case AF_ENABLED:
return 1;
@@ -132,11 +122,9 @@ INT_PTR CToxProto::GetAvatarInfo(WPARAM, LPARAM lParam)
PROTO_AVATAR_INFORMATION *pai = (PROTO_AVATAR_INFORMATION *)lParam;
ptrA address(getStringA(pai->hContact, TOX_SETTINGS_ID));
- if (address != NULL)
- {
+ if (address != NULL) {
ptrW path(GetAvatarFilePath(pai->hContact));
- if (IsFileExists(path))
- {
+ if (IsFileExists(path)) {
mir_wstrncpy(pai->filename, path, _countof(pai->filename));
pai->format = PA_FORMAT_PNG;
@@ -161,11 +149,9 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
debugLogA(__FUNCTION__": setting avatar");
wchar_t *path = (wchar_t*)lParam;
ptrW avatarPath(GetAvatarFilePath());
- if (path != NULL)
- {
+ if (path != NULL) {
debugLogA(__FUNCTION__": copy new avatar");
- if (!CopyFile(path, avatarPath, FALSE))
- {
+ if (!CopyFile(path, avatarPath, FALSE)) {
debugLogA(__FUNCTION__": failed to copy new avatar to avatar cache");
return 0;
}
@@ -175,10 +161,8 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
return 0;
}
- if (IsOnline())
- {
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
- {
+ if (IsOnline()) {
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
continue;
@@ -190,8 +174,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
TOX_ERR_FILE_SEND error;
tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error);
- if (error != TOX_ERR_FILE_SEND_OK)
- {
+ if (error != TOX_ERR_FILE_SEND_OK) {
debugLogA(__FUNCTION__": failed to unset avatar (%d)", error);
return 0;
}
@@ -208,8 +191,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
void CToxProto::OnGotFriendAvatarInfo(AvatarTransferParam *transfer)
{
- if (transfer->pfts.totalBytes == 0)
- {
+ if (transfer->pfts.totalBytes == 0) {
MCONTACT hConact = transfer->pfts.hContact;
ptrW path(GetAvatarFilePath(hConact));
if (IsFileExists(path))
@@ -222,10 +204,8 @@ void CToxProto::OnGotFriendAvatarInfo(AvatarTransferParam *transfer)
}
DBVARIANT dbv;
- if (!db_get(transfer->pfts.hContact, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
- {
- if (memcmp(transfer->hash, dbv.pbVal, TOX_HASH_LENGTH) == 0)
- {
+ if (!db_get(transfer->pfts.hContact, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv)) {
+ if (memcmp(transfer->hash, dbv.pbVal, TOX_HASH_LENGTH) == 0) {
db_free(&dbv);
CancelTransfer(transfer->pfts.hContact, transfer);
return;
@@ -252,4 +232,4 @@ void CToxProto::OnGotFriendAvatarData(AvatarTransferParam *transfer)
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&ai, 0);
transfers.Remove(transfer);
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_bootstrap.cpp b/protocols/Tox/src/tox_bootstrap.cpp
index 50ff219ab0..49ae5da94b 100644
--- a/protocols/Tox/src/tox_bootstrap.cpp
+++ b/protocols/Tox/src/tox_bootstrap.cpp
@@ -15,7 +15,7 @@ void CToxProto::BootstrapUdpNode(Tox *tox, const char *address, int port, const
}
void CToxProto::BootstrapTcpRelay(Tox *tox, const char *address, int port, const char *hexKey)
-{
+{
if (!toxThread)
return;
@@ -33,11 +33,9 @@ void CToxProto::BootstrapNodesFromDb(Tox *tox, bool isIPv6)
char module[MAX_PATH];
mir_snprintf(module, "%s_Nodes", m_szModuleName);
int nodeCount = db_get_w(NULL, module, TOX_SETTINGS_NODE_COUNT, 0);
- if (nodeCount > 0)
- {
+ if (nodeCount > 0) {
char setting[MAX_PATH];
- for (int i = 0; i < nodeCount; i++)
- {
+ for (int i = 0; i < nodeCount; i++) {
mir_snprintf(setting, TOX_SETTINGS_NODE_IPV4, i);
ptrA address(db_get_sa(NULL, module, setting));
mir_snprintf(setting, TOX_SETTINGS_NODE_PORT, i);
@@ -46,8 +44,7 @@ void CToxProto::BootstrapNodesFromDb(Tox *tox, bool isIPv6)
ptrA pubKey(db_get_sa(NULL, module, setting));
BootstrapUdpNode(tox, address, port, pubKey);
BootstrapTcpRelay(tox, address, port, pubKey);
- if (isIPv6)
- {
+ if (isIPv6) {
mir_snprintf(setting, TOX_SETTINGS_NODE_IPV6, i);
address = db_get_sa(NULL, module, setting);
BootstrapUdpNode(tox, address, port, pubKey);
@@ -66,11 +63,9 @@ void CToxProto::BootstrapNodesFromJson(Tox *tox, bool isIPv6)
if (!IsFileExists(path))
UpdateNodes();
- if (IsFileExists(path))
- {
+ if (IsFileExists(path)) {
FILE *hFile = _wfopen(path, L"r");
- if (hFile != NULL)
- {
+ if (hFile != NULL) {
_fseeki64(hFile, 0, SEEK_END);
size_t size = _ftelli64(hFile);
json = (char*)mir_calloc(size);
@@ -80,39 +75,30 @@ void CToxProto::BootstrapNodesFromJson(Tox *tox, bool isIPv6)
}
}
- if (json)
- {
+ if (json) {
JSONNode root = JSONNode::parse(json);
- if (!root.empty())
- {
+ if (!root.empty()) {
JSONNode nodes = root.at("nodes").as_array();
- for (size_t i = 0; i < nodes.size(); i++)
- {
+ for (size_t i = 0; i < nodes.size(); i++) {
JSONNode node = nodes[i];
-
JSONNode address = node.at("ipv4");
JSONNode pubKey = node.at("public_key");
- if (node.at("status_udp").as_bool())
- {
+ if (node.at("status_udp").as_bool()) {
int port = node.at("port").as_int();
BootstrapUdpNode(tox, address.as_string().c_str(), port, pubKey.as_string().c_str());
- if (isIPv6)
- {
+ if (isIPv6) {
address = node.at("ipv6");
BootstrapUdpNode(tox, address.as_string().c_str(), port, pubKey.as_string().c_str());
}
}
- if (node.at("status_tcp").as_bool())
- {
+ if (node.at("status_tcp").as_bool()) {
JSONNode tcpPorts = node.at("tcp_ports").as_array();
- for (size_t k = 0; k < tcpPorts.size(); k++)
- {
+ for (size_t k = 0; k < tcpPorts.size(); k++) {
int port = tcpPorts[k].as_int();
BootstrapTcpRelay(tox, address.as_string().c_str(), port, pubKey.as_string().c_str());
- if (isIPv6)
- {
+ if (isIPv6) {
address = node.at("ipv6");
BootstrapTcpRelay(tox, address.as_string().c_str(), port, pubKey.as_string().c_str());
}
@@ -136,15 +122,13 @@ void CToxProto::UpdateNodes()
{
HttpRequest request(REQUEST_GET, "https://nodes.tox.chat/json");
NLHR_PTR response(request.Send(m_hNetlibUser));
- if (!response || response->resultCode != HTTP_CODE_OK || !response->pData)
- {
+ if (!response || response->resultCode != HTTP_CODE_OK || !response->pData) {
debugLogA(__FUNCTION__": failed to dowload tox.json");
return;
}
JSONNode root = JSONNode::parse(response->pData);
- if (root.empty())
- {
+ if (root.empty()) {
debugLogA(__FUNCTION__": failed to dowload tox.json");
return;
}
@@ -154,11 +138,9 @@ void CToxProto::UpdateNodes()
return;
ptrW path(mir_wstrdup((wchar_t*)VARSW(_A2W(TOX_JSON_PATH))));
- if (!IsFileExists(path))
- {
+ if (!IsFileExists(path)) {
HANDLE hProfile = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hProfile == NULL)
- {
+ if (hProfile == NULL) {
debugLogA(__FUNCTION__": failed to create tox.json");
return;
}
@@ -166,8 +148,7 @@ void CToxProto::UpdateNodes()
}
FILE *hFile = _wfopen(path, L"w");
- if (!hFile)
- {
+ if (!hFile) {
debugLogA(__FUNCTION__": failed to open tox.json");
return;
}
diff --git a/protocols/Tox/src/tox_connection.cpp b/protocols/Tox/src/tox_connection.cpp
index 39b9474225..d01879f065 100644
--- a/protocols/Tox/src/tox_connection.cpp
+++ b/protocols/Tox/src/tox_connection.cpp
@@ -8,8 +8,7 @@ bool CToxProto::IsOnline()
void CToxProto::TryConnect(Tox *tox)
{
TOX_CONNECTION connectionStatus = tox_self_get_connection_status(tox);
- if (connectionStatus != TOX_CONNECTION_NONE)
- {
+ if (connectionStatus != TOX_CONNECTION_NONE) {
debugLogA(__FUNCTION__": successfuly connected to DHT");
m_iStatus = m_iDesiredStatus;
@@ -23,8 +22,7 @@ void CToxProto::TryConnect(Tox *tox)
}
int maxConnectRetries = getByte("MaxConnectRetries", TOX_MAX_CONNECT_RETRIES);
- if (m_iStatus++ > maxConnectRetries)
- {
+ if (m_iStatus++ > maxConnectRetries) {
SetStatus(ID_STATUS_OFFLINE);
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NONETWORK);
debugLogA(__FUNCTION__": failed to connect to DHT");
@@ -36,23 +34,18 @@ void CToxProto::CheckConnection(Tox *tox, int &retriesCount)
{
int maxReconnectRetries = getByte("MaxReconnectRetries", TOX_MAX_RECONNECT_RETRIES);
TOX_CONNECTION connectionStatus = tox_self_get_connection_status(tox);
- if (connectionStatus != TOX_CONNECTION_NONE)
- {
- if (retriesCount < maxReconnectRetries)
- {
+ if (connectionStatus != TOX_CONNECTION_NONE) {
+ if (retriesCount < maxReconnectRetries) {
debugLogA(__FUNCTION__": restored connection with DHT");
retriesCount = maxReconnectRetries;
}
}
- else
- {
- if (retriesCount == maxReconnectRetries)
- {
+ else {
+ if (retriesCount == maxReconnectRetries) {
retriesCount--;
debugLogA(__FUNCTION__": lost connection with DHT");
}
- else if (!(--retriesCount))
- {
+ else if (!(--retriesCount)) {
debugLogA(__FUNCTION__": disconnected from DHT");
SetStatus(ID_STATUS_OFFLINE);
return;
@@ -68,8 +61,7 @@ void CToxProto::CheckingThread(void *arg)
Tox *tox = (Tox*)arg;
int retriesCount = getByte("MaxReconnectRetries", TOX_MAX_RECONNECT_RETRIES);
- while (!isTerminated)
- {
+ while (!isTerminated) {
if (m_iStatus < ID_STATUS_ONLINE)
TryConnect(tox);
else
@@ -88,8 +80,7 @@ void CToxProto::PollingThread(void*)
debugLogA(__FUNCTION__": entering");
Tox_Options *options = GetToxOptions();
- if (!options)
- {
+ if (!options) {
SetStatus(ID_STATUS_OFFLINE);
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL);
debugLogA(__FUNCTION__": leaving");
@@ -98,8 +89,7 @@ void CToxProto::PollingThread(void*)
TOX_ERR_NEW error;
CToxThread toxThread(options, &error);
- if (error != TOX_ERR_NEW_OK)
- {
+ if (error != TOX_ERR_NEW_OK) {
SetStatus(ID_STATUS_OFFLINE);
debugLogA(__FUNCTION__": failed to initialize tox core (%d)", error);
ShowNotification(TranslateT("Unable to initialize Tox core"), ToxErrorToString(error), MB_ICONERROR);
@@ -114,8 +104,7 @@ void CToxProto::PollingThread(void*)
BootstrapNodes(toxThread.Tox());
ForkThread(&CToxProto::CheckingThread, toxThread.Tox());
- while (!isTerminated)
- {
+ while (!isTerminated) {
tox_iterate(toxThread.Tox(), this);
uint32_t interval = tox_iteration_interval(toxThread.Tox());
interval = interval ? interval : 50;
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 604f4259f5..80caaf0a00 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -44,8 +44,7 @@ MCONTACT CToxProto::GetContact(const Tox *tox, const int friendNumber)
uint8_t data[TOX_PUBLIC_KEY_SIZE];
TOX_ERR_FRIEND_GET_PUBLIC_KEY error;
- if (!tox_friend_get_public_key(tox, friendNumber, data, &error))
- {
+ if (!tox_friend_get_public_key(tox, friendNumber, data, &error)) {
debugLogA(__FUNCTION__": failed to get friend (%d) public key (%d)", friendNumber, error);
return NULL;
}
@@ -56,8 +55,7 @@ MCONTACT CToxProto::GetContact(const Tox *tox, const int friendNumber)
MCONTACT CToxProto::GetContact(const char *pubKey)
{
MCONTACT hContact = NULL;
- for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
- {
+ for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
ptrA contactPubKey(getStringA(hContact, TOX_SETTINGS_ID));
// check only public key part of address
if (mir_strncmpi(pubKey, contactPubKey, TOX_PUBLIC_KEY_SIZE) == 0)
@@ -73,8 +71,7 @@ ToxHexAddress CToxProto::GetContactPublicKey(const Tox *tox, const int friendNum
uint8_t data[TOX_PUBLIC_KEY_SIZE];
TOX_ERR_FRIEND_GET_PUBLIC_KEY error;
- if (!tox_friend_get_public_key(tox, friendNumber, data, &error))
- {
+ if (!tox_friend_get_public_key(tox, friendNumber, data, &error)) {
debugLogA(__FUNCTION__": failed to get friend (%d) public key (%d)", friendNumber, error);
return ToxHexAddress::Empty();
}
@@ -99,12 +96,8 @@ MCONTACT CToxProto::AddContact(const char *address, const char *nick, const char
if (mir_strlen(dnsId))
setWString(hContact, TOX_SETTINGS_DNS, ptrW(mir_utf8decodeW(dnsId)));
- DBVARIANT dbv;
- if (!getWString(TOX_SETTINGS_GROUP, &dbv))
- {
- db_set_ws(hContact, "CList", "Group", dbv.ptszVal);
- db_free(&dbv);
- }
+ if (wszGroup)
+ db_set_ws(hContact, "CList", "Group", wszGroup);
setByte(hContact, "Auth", 1);
setByte(hContact, "Grant", 1);
@@ -128,13 +121,11 @@ uint32_t CToxProto::GetToxFriendNumber(MCONTACT hContact)
void CToxProto::LoadFriendList(Tox *tox)
{
size_t count = tox_self_get_friend_list_size(tox);
- if (count > 0)
- {
+ if (count > 0) {
uint32_t *friends = (uint32_t*)mir_alloc(count * sizeof(uint32_t));
tox_self_get_friend_list(toxThread->Tox(), friends);
- for (size_t i = 0; i < count; i++)
- {
+ for (size_t i = 0; i < count; i++) {
uint32_t friendNumber = friends[i];
ToxHexAddress pubKey = GetContactPublicKey(tox, friendNumber);
@@ -142,8 +133,7 @@ void CToxProto::LoadFriendList(Tox *tox)
continue;
MCONTACT hContact = AddContact(pubKey);
- if (hContact)
- {
+ if (hContact) {
delSetting(hContact, "Auth");
delSetting(hContact, "Grant");
@@ -177,8 +167,7 @@ INT_PTR CToxProto::OnRequestAuth(WPARAM hContact, LPARAM lParam)
TOX_ERR_FRIEND_ADD addFriendResult;
int32_t friendNumber = tox_friend_add(toxThread->Tox(), address, (uint8_t*)reason, length, &addFriendResult);
- if (addFriendResult != TOX_ERR_FRIEND_ADD_OK)
- {
+ if (addFriendResult != TOX_ERR_FRIEND_ADD_OK) {
debugLogA(__FUNCTION__": failed to request auth(%d)", addFriendResult);
return addFriendResult;
}
@@ -204,8 +193,7 @@ INT_PTR CToxProto::OnGrantAuth(WPARAM hContact, LPARAM)
ToxBinAddress pubKey(ptrA(getStringA(hContact, TOX_SETTINGS_ID)));
TOX_ERR_FRIEND_ADD error;
tox_friend_add_norequest(toxThread->Tox(), pubKey, &error);
- if (error != TOX_ERR_FRIEND_ADD_OK)
- {
+ if (error != TOX_ERR_FRIEND_ADD_OK) {
debugLogA(__FUNCTION__": failed to grant auth (%d)", error);
return error;
}
@@ -223,12 +211,10 @@ int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM)
if (!IsOnline())
return 0;
- if (!isChatRoom(hContact))
- {
+ if (!isChatRoom(hContact)) {
int32_t friendNumber = GetToxFriendNumber(hContact);
TOX_ERR_FRIEND_DELETE error;
- if (!tox_friend_delete(toxThread->Tox(), friendNumber, &error))
- {
+ if (!tox_friend_delete(toxThread->Tox(), friendNumber, &error)) {
debugLogA(__FUNCTION__": failed to delete friend (%d)", error);
return error;
}
@@ -247,14 +233,13 @@ int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM)
return 0;
}
-void CToxProto::OnFriendRequest(Tox*, const uint8_t *pubKey, const uint8_t *message, size_t length, void *arg)
+void CToxProto::OnFriendRequest(Tox*, const uint8_t *pubKey, const uint8_t *message, size_t /* length */, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
ToxHexAddress address(pubKey);
MCONTACT hContact = proto->AddContact(address);
- if (!hContact)
- {
+ if (!hContact) {
Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to create contact");
return;
}
@@ -274,8 +259,7 @@ void CToxProto::OnFriendNameChange(Tox *tox, uint32_t friendNumber, const uint8_
{
CToxProto *proto = (CToxProto*)arg;
- if (MCONTACT hContact = proto->GetContact(tox, friendNumber))
- {
+ if (MCONTACT hContact = proto->GetContact(tox, friendNumber)) {
ptrA rawName((char*)mir_alloc(length + 1));
memcpy(rawName, name, length);
rawName[length] = 0;
@@ -289,8 +273,7 @@ void CToxProto::OnStatusMessageChanged(Tox *tox, uint32_t friendNumber, const ui
{
CToxProto *proto = (CToxProto*)arg;
- if (MCONTACT hContact = proto->GetContact(tox, friendNumber))
- {
+ if (MCONTACT hContact = proto->GetContact(tox, friendNumber)) {
ptrA rawMessage((char*)mir_alloc(length + 1));
memcpy(rawMessage, message, length);
rawMessage[length] = 0;
@@ -305,8 +288,7 @@ void CToxProto::OnUserStatusChanged(Tox *tox, uint32_t friendNumber, TOX_USER_ST
CToxProto *proto = (CToxProto*)arg;
MCONTACT hContact = proto->GetContact(tox, friendNumber);
- if (hContact)
- {
+ if (hContact) {
int status = proto->ToxToMirandaStatus(userstatus);
proto->SetContactStatus(hContact, status);
}
@@ -320,8 +302,7 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, uint32_t friendNumber, TOX_C
if (!hContact)
return;
- if (status == TOX_CONNECTION_NONE)
- {
+ if (status == TOX_CONNECTION_NONE) {
proto->SetContactStatus(hContact, ID_STATUS_OFFLINE);
return;
}
@@ -337,11 +318,9 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, uint32_t friendNumber, TOX_C
// update avatar
ptrW avatarPath(proto->GetAvatarFilePath());
- if (IsFileExists(avatarPath))
- {
+ if (IsFileExists(avatarPath)) {
FILE *hFile = _wfopen(avatarPath, L"rb");
- if (!hFile)
- {
+ if (!hFile) {
proto->debugLogA(__FUNCTION__": failed to open avatar file");
return;
}
@@ -352,8 +331,7 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, uint32_t friendNumber, TOX_C
uint8_t hash[TOX_HASH_LENGTH];
DBVARIANT dbv;
- if (!db_get(NULL, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
- {
+ if (!db_get(NULL, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv)) {
memcpy(hash, dbv.pbVal, TOX_HASH_LENGTH);
db_free(&dbv);
}
@@ -362,8 +340,7 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, uint32_t friendNumber, TOX_C
TOX_ERR_FILE_SEND error;
uint32_t fileNumber = tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error);
- if (error != TOX_ERR_FILE_SEND_OK)
- {
+ if (error != TOX_ERR_FILE_SEND_OK) {
Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to set new avatar");
fclose(hFile);
return;
@@ -376,8 +353,7 @@ void CToxProto::OnConnectionStatusChanged(Tox *tox, uint32_t friendNumber, TOX_C
transfer->hFile = hFile;
proto->transfers.Add(transfer);
}
- else
- {
+ else {
proto->debugLogA(__FUNCTION__": unset avatar for friend (%d)", friendNumber);
tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, NULL);
}
@@ -390,8 +366,7 @@ int CToxProto::OnUserInfoInit(WPARAM wParam, LPARAM lParam)
MCONTACT hContact = lParam;
char *szProto = GetContactProto(hContact);
- if (szProto != NULL && !mir_strcmp(szProto, m_szModuleName))
- {
+ if (szProto != NULL && !mir_strcmp(szProto, m_szModuleName)) {
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.flags = ODPF_UNICODE | ODPF_DONTTRANSLATE;
odp.hInstance = g_hInstance;
@@ -411,34 +386,25 @@ INT_PTR CToxProto::UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
{
CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- switch (uMsg)
- {
+ switch (uMsg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwnd);
- {
- proto = (CToxProto*)lParam;
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- }
+ proto = (CToxProto*)lParam;
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
break;
case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom)
- {
+ switch (((LPNMHDR)lParam)->idFrom) {
case 0:
- switch (((LPNMHDR)lParam)->code)
- {
+ switch (((LPNMHDR)lParam)->code) {
case PSN_INFOCHANGED:
- {
- MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
- char *szProto = (hContact == NULL) ? proto->m_szModuleName : GetContactProto(hContact);
- if (szProto == NULL)
{
- break;
+ MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
+ char *szProto = (hContact == NULL) ? proto->m_szModuleName : GetContactProto(hContact);
+ if (szProto != nullptr)
+ SetDlgItemText(hwnd, IDC_DNS_ID, ptrW(proto->getWStringA(hContact, TOX_SETTINGS_DNS)));
}
-
- SetDlgItemText(hwnd, IDC_DNS_ID, ptrW(proto->getWStringA(hContact, TOX_SETTINGS_DNS)));
- }
- break;
+ break;
case PSN_PARAMCHANGED:
SetWindowLongPtr(hwnd, GWLP_USERDATA, ((PSHNOTIFY*)lParam)->lParam);
@@ -448,9 +414,8 @@ INT_PTR CToxProto::UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
char *szProto = (hContact == NULL) ? proto->m_szModuleName : GetContactProto(hContact);
if (szProto == NULL)
- {
break;
- }
+
wchar_t dnsId[MAX_PATH];
GetDlgItemText(hwnd, IDC_DNS_ID, dnsId, MAX_PATH);
proto->setWString(hContact, TOX_SETTINGS_DNS, dnsId);
@@ -462,11 +427,9 @@ INT_PTR CToxProto::UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar
case WM_COMMAND:
if ((HWND)lParam == GetFocus() && HIWORD(wParam) == EN_CHANGE)
- {
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- }
break;
}
return FALSE;
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp
index c040fa3426..9a2abf7e0f 100644
--- a/protocols/Tox/src/tox_core.cpp
+++ b/protocols/Tox/src/tox_core.cpp
@@ -4,32 +4,27 @@ Tox_Options* CToxProto::GetToxOptions()
{
TOX_ERR_OPTIONS_NEW error;
Tox_Options *options = tox_options_new(&error);
- if (error != TOX_ERR_OPTIONS_NEW_OK)
- {
+ if (error != TOX_ERR_OPTIONS_NEW_OK) {
debugLogA(__FUNCTION__": failed to initialize tox options (%d)", error);
- return NULL;
+ return nullptr;
}
options->udp_enabled = getBool("EnableUDP", 1);
options->ipv6_enabled = getBool("EnableIPv6", 0);
- if (m_hNetlibUser != NULL)
- {
+ if (m_hNetlibUser != nullptr) {
NETLIBUSERSETTINGS nlus = { sizeof(nlus) };
Netlib_GetUserSettings(m_hNetlibUser, &nlus);
- if (nlus.useProxy)
- {
- if (nlus.proxyType == PROXYTYPE_HTTP || nlus.proxyType == PROXYTYPE_HTTPS)
- {
+ if (nlus.useProxy) {
+ if (nlus.proxyType == PROXYTYPE_HTTP || nlus.proxyType == PROXYTYPE_HTTPS) {
debugLogA(__FUNCTION__": setting http user proxy config");
options->proxy_type = TOX_PROXY_TYPE_HTTP;
mir_strcpy((char*)&options->proxy_host[0], nlus.szProxyServer);
options->proxy_port = nlus.wProxyPort;
}
- if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5)
- {
+ if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5) {
debugLogA(__FUNCTION__": setting socks user proxy config");
options->proxy_type = TOX_PROXY_TYPE_SOCKS5;
mir_strcpy((char*)&options->proxy_host[0], nlus.szProxyServer);
@@ -39,13 +34,10 @@ Tox_Options* CToxProto::GetToxOptions()
}
if (LoadToxProfile(options))
- {
return options;
- }
-
+
tox_options_free(options);
-
- return NULL;
+ return nullptr;
}
void CToxProto::InitToxCore(Tox *tox)
@@ -113,4 +105,4 @@ void CToxProto::UninitToxCore(Tox *tox)
{
CancelAllTransfers(tox);
SaveToxProfile(tox);
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp
index 9454085f55..f0afe46dbd 100644
--- a/protocols/Tox/src/tox_events.cpp
+++ b/protocols/Tox/src/tox_events.cpp
@@ -7,8 +7,7 @@ int CToxProto::OnModulesLoaded(WPARAM, LPARAM)
hProfileFolderPath = FoldersRegisterCustomPathT("Tox", "ProfilesFolder", MIRANDA_USERDATAT, TranslateT("Profiles folder"));
- if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE))
- {
+ if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE)) {
CreateServiceFunction(MODULE "/ParseUri", CToxProto::ParseToxUri);
AssocMgr_AddNewUrlTypeT("tox:", TranslateT("Tox URI scheme"), g_hInstance, IDI_TOX, MODULE "/ParseUri", 0);
}
@@ -30,4 +29,4 @@ void CToxProto::InitCustomDbEvents()
dbEventType.descr = Translate("Call");
dbEventType.eventIcon = GetIconHandle(IDI_AUDIO_START);
DbEvent_RegisterType(&dbEventType);
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_icons.cpp b/protocols/Tox/src/tox_icons.cpp
index 0faaf9a295..87ebdaa925 100644
--- a/protocols/Tox/src/tox_icons.cpp
+++ b/protocols/Tox/src/tox_icons.cpp
@@ -21,4 +21,4 @@ HANDLE CToxProto::GetIconHandle(int iconId)
return Icons[i].hIcolib;
return NULL;
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_menus.cpp b/protocols/Tox/src/tox_menus.cpp
index 61b3801928..ed70ad8a7b 100644
--- a/protocols/Tox/src/tox_menus.cpp
+++ b/protocols/Tox/src/tox_menus.cpp
@@ -82,7 +82,7 @@ int CToxProto::OnInitStatusMenu()
mi.name.w = LPGENW("Copy Tox ID");
mi.position = SMI_POSITION + SMI_TOXID_COPY;
Menu_AddProtoMenuItem(&mi, m_szModuleName);
-
+
// Create group chat command
/*
mi.pszService = "/CreateChatRoom";
@@ -93,4 +93,4 @@ int CToxProto::OnInitStatusMenu()
HGENMENU hCreateChatRoom = Menu_AddProtoMenuItem(&mi, m_szModuleName);*/
return 0;
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp
index 471db3b23f..9ed494e289 100644
--- a/protocols/Tox/src/tox_messages.cpp
+++ b/protocols/Tox/src/tox_messages.cpp
@@ -13,8 +13,7 @@ void CToxProto::OnFriendMessage(Tox *tox, uint32_t friendNumber, TOX_MESSAGE_TYP
char *rawMessage = (char*)mir_alloc(length + 1);
// old api support
- if (message[0] == 0 && length > 0)
- {
+ if (message[0] == 0 && length > 0) {
length -= 3;
mir_strncpy(rawMessage, (const char*)&message[4], length);
}
@@ -53,16 +52,14 @@ void CToxProto::SendMessageAsync(void *arg)
size_t msgLen = mir_strlen(param->message);
uint8_t *msg = (uint8_t*)param->message;
TOX_MESSAGE_TYPE type = TOX_MESSAGE_TYPE_NORMAL;
- if (strncmp(param->message, "/me ", 4) == 0)
- {
+ if (strncmp(param->message, "/me ", 4) == 0) {
msg += 4; msgLen -= 4;
type = TOX_MESSAGE_TYPE_ACTION;
}
TOX_ERR_FRIEND_SEND_MESSAGE sendError;
int messageNumber = tox_friend_send_message(toxThread->Tox(), friendNumber, type, msg, msgLen, &sendError);
- if (sendError != TOX_ERR_FRIEND_SEND_MESSAGE_OK)
- {
+ if (sendError != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
debugLogA(__FUNCTION__": failed to send message for %d (%d)", friendNumber, sendError);
ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)param->hMessage, (LPARAM)_T2A(ToxErrorToString(sendError)));
}
@@ -75,8 +72,7 @@ void CToxProto::SendMessageAsync(void *arg)
int CToxProto::OnSendMessage(MCONTACT hContact, const char *szMessage)
{
- if (!IsOnline())
- {
+ if (!IsOnline()) {
ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)Translate("You cannot send when you are offline."));
return 0;
}
@@ -136,24 +132,21 @@ void CToxProto::GetStatusMessageAsync(void* arg)
MCONTACT hContact = (UINT_PTR)arg;
int32_t friendNumber = GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
+ if (friendNumber == UINT32_MAX) {
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
return;
}
TOX_ERR_FRIEND_QUERY error;
size_t size = tox_friend_get_status_message_size(toxThread->Tox(), friendNumber, &error);
- if (error != TOX_ERR_FRIEND_QUERY::TOX_ERR_FRIEND_QUERY_OK)
- {
+ if (error != TOX_ERR_FRIEND_QUERY::TOX_ERR_FRIEND_QUERY_OK) {
debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
return;
}
ptrA statusMessage((char*)mir_calloc(size + 1));
- if (!tox_friend_get_status_message(toxThread->Tox(), friendNumber, (uint8_t*)(char*)statusMessage, &error))
- {
+ if (!tox_friend_get_status_message(toxThread->Tox(), friendNumber, (uint8_t*)(char*)statusMessage, &error)) {
debugLogA(__FUNCTION__": failed to get status message for (%d) (%d)", friendNumber, error);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_FAILED, (HANDLE)hContact, 0);
return;
@@ -181,9 +174,8 @@ void CToxProto::OnTypingChanged(Tox *tox, uint32_t friendNumber, bool isTyping,
{
CToxProto *proto = (CToxProto*)arg;
- if (MCONTACT hContact = proto->GetContact(tox, friendNumber))
- {
+ if (MCONTACT hContact = proto->GetContact(tox, friendNumber)) {
int typingStatus = (isTyping ? PROTOTYPE_CONTACTTYPING_INFINITE : PROTOTYPE_CONTACTTYPING_OFF);
CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)typingStatus);
}
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_multimedia.cpp b/protocols/Tox/src/tox_multimedia.cpp
index c5c42ac79d..cb8f17fdb9 100644
--- a/protocols/Tox/src/tox_multimedia.cpp
+++ b/protocols/Tox/src/tox_multimedia.cpp
@@ -2,8 +2,7 @@
CToxCallDlgBase::CToxCallDlgBase(CToxProto *proto, int idDialog, MCONTACT hContact) :
CToxDlgBase(proto, idDialog, false), hContact(hContact)
-{
-}
+{}
void CToxCallDlgBase::OnInitDialog()
{
@@ -74,16 +73,14 @@ void CToxIncomingCall::OnAnswer(CCtrlBase*)
return;*/
int friendNumber = m_proto->GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
+ if (friendNumber == UINT32_MAX) {
//mir_free(cSettings);
Close();
return;
}
TOXAV_ERR_ANSWER error;
- if (!toxav_answer(m_proto->toxThread->ToxAV(), friendNumber, 0, 0, &error))
- {
+ if (!toxav_answer(m_proto->toxThread->ToxAV(), friendNumber, 0, 0, &error)) {
m_proto->debugLogA(__FUNCTION__": failed to answer the call (%d)", error);
Close();
}
@@ -130,16 +127,14 @@ void CToxOutgoingCall::OnCall(CCtrlBase*)
}*/
int friendNumber = m_proto->GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
+ if (friendNumber == UINT32_MAX) {
//mir_free(cSettings);
Close();
return;
}
TOXAV_ERR_CALL error;
- if (!toxav_call(m_proto->toxThread->ToxAV(), friendNumber, 0, 0, &error))
- {
+ if (!toxav_call(m_proto->toxThread->ToxAV(), friendNumber, 0, 0, &error)) {
//mir_free(cSettings);
m_proto->debugLogA(__FUNCTION__": failed to make a call (%d)", error);
return;
@@ -161,8 +156,7 @@ void CToxOutgoingCall::OnCall(CCtrlBase*)
void CToxOutgoingCall::OnCancel(CCtrlBase*)
{
int friendNumber = m_proto->GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
+ if (friendNumber == UINT32_MAX) {
//mir_free(cSettings);
Close();
return;
@@ -176,8 +170,7 @@ void CToxOutgoingCall::OnCancel(CCtrlBase*)
CToxCallDialog::CToxCallDialog(CToxProto *proto, MCONTACT hContact) :
CToxCallDlgBase(proto, IDD_CALL, hContact), end(this, IDCANCEL)
-{
-}
+{}
void CToxCallDialog::OnInitDialog()
{
@@ -189,8 +182,7 @@ void CToxCallDialog::OnInitDialog()
void CToxCallDialog::OnClose()
{
int friendNumber = m_proto->GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
+ if (friendNumber == UINT32_MAX) {
//mir_free(cSettings);
Close();
return;
@@ -327,12 +319,10 @@ void CToxProto::OnFriendCall(ToxAV *toxAV, uint32_t friend_number, bool audio_en
}
void CToxProto::OnFriendCallState(ToxAV *toxAV, uint32_t friend_number, uint32_t state, void *user_data)
-{
-}
+{}
void CToxProto::OnBitrateChanged(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, void *arg)
-{
-}
+{}
// save event to db
INT_PTR CToxProto::OnRecvAudioCall(WPARAM hContact, LPARAM lParam)
@@ -469,8 +459,7 @@ void CToxProto::OnAvCallTimeout(void*, int32_t callId, void *arg)
static void CALLBACK WaveOutCallback(HWAVEOUT hOutDevice, UINT uMsg, DWORD/* dwInstance*/, DWORD dwParam1, DWORD/* dwParam2*/)
{
- if (uMsg == WOM_DONE)
- {
+ if (uMsg == WOM_DONE) {
WAVEHDR *header = (WAVEHDR*)dwParam1;
if (header->dwFlags & WHDR_PREPARED)
waveOutUnprepareHeader(hOutDevice, header, sizeof(WAVEHDR));
@@ -634,4 +623,4 @@ void CToxProto::OnFriendAudioFrame(ToxAV *toxAV, uint32_t friend_number, const i
proto->debugLogA(__FUNCTION__": failed to play audio samples (%d)", error);
return;
}*/
-} \ No newline at end of file
+}
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index 87cb0b77e5..07cb3b2f31 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -16,8 +16,11 @@ CToxOptionsMain::CToxOptionsMain(CToxProto *proto, int idDialog)
CreateLink(m_group, TOX_SETTINGS_GROUP, L"Tox");
CreateLink(m_enableUdp, "EnableUDP", DBVT_BYTE, TRUE);
CreateLink(m_enableIPv6, "EnableIPv6", DBVT_BYTE, FALSE);
- CreateLink(m_maxConnectRetries, "MaxConnectRetries", DBVT_BYTE, TOX_MAX_CONNECT_RETRIES);
- CreateLink(m_maxReconnectRetries, "MaxReconnectRetries", DBVT_BYTE, TOX_MAX_RECONNECT_RETRIES);
+
+ if (idDialog == IDD_OPTIONS_MAIN) {
+ CreateLink(m_maxConnectRetries, "MaxConnectRetries", DBVT_BYTE, TOX_MAX_CONNECT_RETRIES);
+ CreateLink(m_maxReconnectRetries, "MaxReconnectRetries", DBVT_BYTE, TOX_MAX_RECONNECT_RETRIES);
+ }
m_toxAddressCopy.OnClick = Callback(this, &CToxOptionsMain::ToxAddressCopy_OnClick);
m_profileCreate.OnClick = Callback(this, &CToxOptionsMain::ProfileCreate_OnClick);
@@ -30,8 +33,7 @@ void CToxOptionsMain::OnInitDialog()
CToxDlgBase::OnInitDialog();
ptrW profilePath(m_proto->GetToxProfilePath());
- if (CToxProto::IsFileExists(profilePath))
- {
+ if (CToxProto::IsFileExists(profilePath)) {
m_toxAddress.Enable();
ShowWindow(m_profileCreate.GetHwnd(), FALSE);
@@ -56,8 +58,7 @@ void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*)
{
char *toxAddress = m_toxAddress.GetTextA();
size_t toxAddressLength = mir_strlen(toxAddress) + 1;
- if (OpenClipboard(m_toxAddress.GetHwnd()))
- {
+ if (OpenClipboard(m_toxAddress.GetHwnd())) {
EmptyClipboard();
HGLOBAL hMemory = GlobalAlloc(GMEM_FIXED, toxAddressLength);
memcpy(GlobalLock(hMemory), toxAddress, toxAddressLength);
@@ -76,11 +77,9 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
tox_options_free(options);
ptrW profilePath(m_proto->GetToxProfilePath());
- if (!m_proto->IsFileExists(profilePath))
- {
+ if (!m_proto->IsFileExists(profilePath)) {
HANDLE hProfile = CreateFile(profilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hProfile == NULL)
- {
+ if (hProfile == NULL) {
m_proto->debugLogA(__FUNCTION__": failed to create tox profile");
return;
}
@@ -88,11 +87,6 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
}
m_proto->InitToxCore(tox);
-
- ptrW group(m_group.GetText());
- if (mir_wstrlen(group) > 0 && Clist_GroupExists(group))
- Clist_GroupCreate(0, group);
-
m_proto->UninitToxCore(tox);
tox_kill(tox);
@@ -101,7 +95,6 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
m_nickname.SetText(ptrW(m_proto->getWStringA("Nick")));
m_password.SetText(ptrW(m_proto->getWStringA("Password")));
- m_group.SetText(ptrW(m_proto->getWStringA(TOX_SETTINGS_GROUP)));
ShowWindow(m_profileCreate.GetHwnd(), FALSE);
ShowWindow(m_profileImport.GetHwnd(), FALSE);
@@ -136,15 +129,14 @@ void CToxOptionsMain::ProfileImport_OnClick(CCtrlButton*)
CopyFile(profilePath, defaultProfilePath, FALSE);
Tox_Options *options = tox_options_new(NULL);
- if (m_proto->LoadToxProfile(options))
- {
+ if (m_proto->LoadToxProfile(options)) {
CToxThread toxThread(options);
uint8_t data[TOX_ADDRESS_SIZE];
tox_self_get_address(toxThread.Tox(), data);
ToxHexAddress address(data);
m_proto->setString(TOX_SETTINGS_ID, address);
-
+
m_toxAddress.Enable();
m_toxAddress.SetTextA(address);
@@ -197,11 +189,12 @@ void CToxOptionsMain::ProfileExport_OnClick(CCtrlButton*)
void CToxOptionsMain::OnApply()
{
ptrW group(m_group.GetText());
- if (mir_wstrlen(group) > 0 && Clist_GroupExists(group))
+ if (mir_wstrcmp(group, m_proto->wszGroup)) {
+ m_proto->wszGroup = mir_wstrdup(group);
Clist_GroupCreate(0, group);
+ }
- if (m_proto->IsOnline())
- {
+ if (m_proto->IsOnline()) {
CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_UNICODE, (LPARAM)ptrW(m_nickname.GetText()));
// todo: add checkbox
@@ -217,21 +210,18 @@ CToxOptionsMultimedia::CToxOptionsMultimedia(CToxProto *proto)
: CToxDlgBase(proto, IDD_OPTIONS_MULTIMEDIA, false),
m_audioInput(this, IDC_AUDIOINPUT),
m_audioOutput(this, IDC_AUDIOOUTPUT)
-{
-}
+{}
void CToxOptionsMultimedia::EnumDevices(CCtrlCombo &combo, IMMDeviceEnumerator *pEnumerator, EDataFlow dataFlow, const char* setting)
{
LPWSTR pwszDefID = NULL;
ptrW wszDefID(m_proto->getWStringA(setting));
- if (wszDefID != NULL)
- {
+ if (wszDefID != NULL) {
size_t len = mir_wstrlen(wszDefID) + 1;
- pwszDefID = (LPWSTR)CoTaskMemAlloc(len*2);
+ pwszDefID = (LPWSTR)CoTaskMemAlloc(len * 2);
mir_wstrncpy(pwszDefID, wszDefID, len);
}
- else
- {
+ else {
CComPtr<IMMDevice> pDevice = NULL;
if (FAILED(pEnumerator->GetDefaultAudioEndpoint(dataFlow, eConsole, &pDevice))) return;
if (FAILED(pDevice->GetId(&pwszDefID))) return;
@@ -243,8 +233,7 @@ void CToxOptionsMultimedia::EnumDevices(CCtrlCombo &combo, IMMDeviceEnumerator *
UINT count;
EXIT_ON_ERROR(pDevices->GetCount(&count));
- for (UINT i = 0; i < count; i++)
- {
+ for (UINT i = 0; i < count; i++) {
CComPtr<IMMDevice> pDevice = NULL;
EXIT_ON_ERROR(pDevices->Item(i, &pDevice));
@@ -286,8 +275,7 @@ void CToxOptionsMultimedia::OnApply()
int i = m_audioInput.GetCurSel();
if (i == -1)
m_proto->delSetting("AudioInputDeviceID");
- else
- {
+ else {
wchar_t* data = (wchar_t*)m_audioInput.GetItemData(i);
m_proto->setWString("AudioInputDeviceID", data);
}
@@ -295,8 +283,7 @@ void CToxOptionsMultimedia::OnApply()
i = m_audioOutput.GetCurSel();
if (i == -1)
m_proto->delSetting("AudioOutputDeviceID");
- else
- {
+ else {
wchar_t* data = (wchar_t*)m_audioOutput.GetItemData(i);
m_proto->setWString("AudioOutputDeviceID", data);
}
@@ -305,16 +292,14 @@ void CToxOptionsMultimedia::OnApply()
void CToxOptionsMultimedia::OnDestroy()
{
int count = m_audioInput.GetCount();
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
wchar_t* data = (wchar_t*)m_audioInput.GetItemData(i);
mir_free(data);
}
count = m_audioOutput.GetCount();
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
wchar_t* data = (wchar_t*)m_audioOutput.GetItemData(i);
mir_free(data);
@@ -338,8 +323,7 @@ void CToxNodeEditor::OnInitDialog()
{
SetWindowText(m_hwnd, m_iItem == -1 ? TranslateT("Add node") : TranslateT("Change node"));
- if (m_iItem > -1)
- {
+ if (m_iItem > -1) {
LVITEM lvi = { 0 };
lvi.mask = LVIF_TEXT;
lvi.iItem = m_iItem;
@@ -369,28 +353,24 @@ void CToxNodeEditor::OnInitDialog()
void CToxNodeEditor::OnOk(CCtrlBase*)
{
ptrW ipv4(m_ipv4.GetText());
- if (!ipv4)
- {
+ if (!ipv4) {
MessageBox(m_hwnd, TranslateT("Enter IPv4"), TranslateT("Error"), MB_OK);
return;
}
ptrW port(m_port.GetText());
- if (!port)
- {
+ if (!port) {
MessageBox(m_hwnd, TranslateT("Enter port"), TranslateT("Error"), MB_OK);
return;
}
ptrW pubKey(m_pkey.GetText());
- if (!pubKey)
- {
+ if (!pubKey) {
MessageBox(m_hwnd, TranslateT("Enter public key"), TranslateT("Error"), MB_OK);
return;
}
- if (m_iItem == -1)
- {
+ if (m_iItem == -1) {
m_iItem = m_list->AddItem(ipv4, -1, NULL, 1);
m_list->SetItemState(m_iItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F);
m_list->EnsureVisible(m_iItem, TRUE);
@@ -416,13 +396,11 @@ void CToxNodeEditor::OnClose()
CCtrlNodeList::CCtrlNodeList(CDlgBase* dlg, int ctrlId)
: CCtrlListView(dlg, ctrlId)
-{
-}
+{}
BOOL CCtrlNodeList::OnNotify(int idCtrl, NMHDR *pnmh)
{
- if (pnmh->code == NM_CLICK)
- {
+ if (pnmh->code == NM_CLICK) {
TEventInfo evt = { this, pnmh };
OnClick(&evt);
return TRUE;
@@ -490,8 +468,7 @@ void CToxOptionsNodeList::OnNodeListDoubleClick(CCtrlBase*)
lvi.iItem = iItem;
lvi.mask = LVIF_GROUPID;
m_nodes.GetItem(&lvi);
- if (lvi.iGroupId || (lvi.iGroupId == 0 && lvi.iItem == -1))
- {
+ if (lvi.iGroupId || (lvi.iGroupId == 0 && lvi.iItem == -1)) {
CToxNodeEditor nodeEditor(lvi.iItem, &m_nodes);
if (nodeEditor.DoModal())
NotifyChange();
@@ -505,16 +482,13 @@ void CToxOptionsNodeList::OnNodeListClick(CCtrlListView::TEventInfo *evt)
lvi.mask = LVIF_GROUPID;
m_nodes.GetItem(&lvi);
lvi.iSubItem = evt->nmlvia->iSubItem;
- if (lvi.iGroupId && lvi.iSubItem == 4)
- {
+ if (lvi.iGroupId && lvi.iSubItem == 4) {
CToxNodeEditor nodeEditor(lvi.iItem, &m_nodes);
if (nodeEditor.DoModal())
NotifyChange();
}
- else if (lvi.iGroupId && lvi.iSubItem == 5)
- {
- if (MessageBox(m_hwnd, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
- {
+ 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);
NotifyChange();
}
@@ -528,10 +502,8 @@ void CToxOptionsNodeList::OnNodeListKeyDown(CCtrlListView::TEventInfo *evt)
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)
- {
+ 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);
NotifyChange();
}
@@ -545,13 +517,11 @@ void CToxOptionsNodeList::ReloadNodeList()
int iItem = -1;
VARSW path(_A2W(TOX_JSON_PATH));
- if (CToxProto::IsFileExists(path))
- {
+ if (CToxProto::IsFileExists(path)) {
ptrA json;
FILE *hFile = _wfopen(path, L"r");
- if (hFile != NULL)
- {
+ if (hFile != NULL) {
_fseeki64(hFile, 0, SEEK_END);
size_t size = _ftelli64(hFile);
json = (char*)mir_calloc(size);
@@ -560,14 +530,11 @@ void CToxOptionsNodeList::ReloadNodeList()
fclose(hFile);
}
- if (json)
- {
+ if (json) {
JSONNode root = JSONNode::parse(json);
- if (!root.empty())
- {
+ if (!root.empty()) {
JSONNode nodes = root.at("nodes").as_array();
- for (size_t i = 0; i < nodes.size(); i++)
- {
+ for (size_t i = 0; i < nodes.size(); i++) {
JSONNode node = nodes[i];
ptrW ipv4(mir_utf8decodeW(node.at("ipv4").as_string().c_str()));
@@ -590,8 +557,7 @@ void CToxOptionsNodeList::ReloadNodeList()
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);
- for (int i = 0; i < nodeCount; i++)
- {
+ for (int i = 0; i < nodeCount; i++) {
mir_snprintf(setting, TOX_SETTINGS_NODE_IPV4, i);
ptrW value(db_get_wsa(NULL, module, setting));
iItem = m_nodes.AddItem(value, -1, NULL, 1);
@@ -602,8 +568,7 @@ void CToxOptionsNodeList::ReloadNodeList()
mir_snprintf(setting, TOX_SETTINGS_NODE_PORT, i);
int port = db_get_w(NULL, module, setting, 0);
- if (port > 0)
- {
+ if (port > 0) {
char portNum[10];
itoa(port, portNum, 10);
m_nodes.SetItem(iItem, 2, mir_a2u(portNum));
@@ -632,14 +597,12 @@ void CToxOptionsNodeList::OnApply()
int iItem = 0;
int itemCount = m_nodes.GetItemCount();
- for (int i = 0; i < itemCount; i++)
- {
+ for (int i = 0; i < itemCount; i++) {
lvi.iItem = i;
lvi.iGroupId = 0;
lvi.mask = LVIF_GROUPID;
m_nodes.GetItem(&lvi);
- if (lvi.iGroupId == 0)
- {
+ if (lvi.iGroupId == 0) {
continue;
}
@@ -668,8 +631,7 @@ void CToxOptionsNodeList::OnApply()
}
itemCount = iItem;
int nodeCount = db_get_b(NULL, module, TOX_SETTINGS_NODE_COUNT, 0);
- for (iItem = itemCount; iItem < nodeCount; iItem++)
- {
+ for (iItem = itemCount; iItem < nodeCount; iItem++) {
mir_snprintf(setting, TOX_SETTINGS_NODE_IPV4, iItem);
db_unset(NULL, module, setting);
mir_snprintf(setting, TOX_SETTINGS_NODE_IPV6, iItem);
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp
index 49ff8a0a64..b74ff2bd07 100644
--- a/protocols/Tox/src/tox_profile.cpp
+++ b/protocols/Tox/src/tox_profile.cpp
@@ -21,14 +21,13 @@ bool CToxProto::LoadToxProfile(Tox_Options *options)
debugLogA(__FUNCTION__": loading tox profile");
mir_cslock locker(profileLock);
-
+
ptrW profilePath(GetToxProfilePath());
if (!IsFileExists(profilePath))
return false;
FILE *profile = _wfopen(profilePath, L"rb");
- if (profile == NULL)
- {
+ if (profile == NULL) {
ShowNotification(TranslateT("Unable to open Tox profile"), MB_ICONERROR);
debugLogA(__FUNCTION__": failed to open tox profile");
return false;
@@ -37,21 +36,18 @@ bool CToxProto::LoadToxProfile(Tox_Options *options)
fseek(profile, 0, SEEK_END);
long size = ftell(profile);
rewind(profile);
- if (size < 0)
- {
+ if (size < 0) {
fclose(profile);
return false;
}
-
- if (size == 0)
- {
+
+ if (size == 0) {
fclose(profile);
return true;
}
uint8_t *data = (uint8_t*)mir_calloc(size);
- if (fread((char*)data, sizeof(char), size, profile) != (size_t)size)
- {
+ if (fread((char*)data, sizeof(char), size, profile) != (size_t)size) {
fclose(profile);
ShowNotification(TranslateT("Unable to read Tox profile"), MB_ICONERROR);
debugLogA(__FUNCTION__": failed to read tox profile");
@@ -60,22 +56,18 @@ bool CToxProto::LoadToxProfile(Tox_Options *options)
}
fclose(profile);
- if (tox_is_data_encrypted(data))
- {
+ if (tox_is_data_encrypted(data)) {
pass_ptrA password(mir_utf8encodeW(pass_ptrT(getWStringA("Password"))));
- if (password == NULL || mir_strlen(password) == 0)
- {
+ if (password == NULL || mir_strlen(password) == 0) {
CToxPasswordEditor passwordEditor(this);
- if (!passwordEditor.DoModal())
- {
+ if (!passwordEditor.DoModal()) {
mir_free(data);
return false;
}
}
uint8_t *encryptedData = (uint8_t*)mir_calloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
TOX_ERR_DECRYPTION coreDecryptError;
- if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreDecryptError))
- {
+ if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreDecryptError)) {
ShowNotification(TranslateT("Unable to decrypt Tox profile"), MB_ICONERROR);
debugLogA(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError);
mir_free(data);
@@ -86,8 +78,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options)
size -= TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
}
- if (data)
- {
+ if (data) {
options->savedata_data = data;
options->savedata_length = size;
options->savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE;
@@ -123,8 +114,7 @@ void CToxProto::SaveToxProfile(Tox *tox)
ptrW profilePath(GetToxProfilePath());
FILE *profile = _wfopen(profilePath, L"wb");
- if (profile == NULL)
- {
+ if (profile == NULL) {
debugLogA(__FUNCTION__": failed to open tox profile");
mir_free(data);
return;
@@ -132,9 +122,7 @@ void CToxProto::SaveToxProfile(Tox *tox)
size_t written = fwrite(data, sizeof(char), size, profile);
if (size != written)
- {
debugLogA(__FUNCTION__": failed to write tox profile");
- }
fclose(profile);
mir_free(data);
@@ -144,8 +132,7 @@ INT_PTR CToxProto::OnCopyToxID(WPARAM, LPARAM)
{
ptrA address(getStringA(TOX_SETTINGS_ID));
size_t length = mir_strlen(address) + 1;
- if (OpenClipboard(NULL))
- {
+ if (OpenClipboard(NULL)) {
EmptyClipboard();
HGLOBAL hMemory = GlobalAlloc(GMEM_FIXED, length);
memcpy(GlobalLock(hMemory), address, length);
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index 2e67a88055..0134ccfa58 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -8,7 +8,11 @@ CToxProto::CToxProto(const char* protoName, const wchar_t* userName)
{
InitNetlib();
- accountName = mir_wstrdup(userName);
+ wszAccountName = mir_wstrdup(userName);
+ wszGroup = getWStringA(TOX_SETTINGS_GROUP);
+ if (wszGroup == nullptr)
+ wszGroup = mir_wstrdup(L"Tox");
+ Clist_GroupCreate(0, wszGroup);
CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
@@ -27,7 +31,7 @@ CToxProto::CToxProto(const char* protoName, const wchar_t* userName)
// nick
CreateProtoService(PS_SETMYNICKNAME, &CToxProto::SetMyNickname);
- //hAudioDialogs = WindowList_Create();
+ // hAudioDialogs = WindowList_Create();
hTerminateEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}
@@ -36,14 +40,12 @@ CToxProto::~CToxProto()
{
WindowList_Destroy(hAudioDialogs);
- mir_free(accountName);
UninitNetlib();
}
DWORD_PTR CToxProto::GetCaps(int type, MCONTACT)
{
- switch (type)
- {
+ switch (type) {
case PFLAGNUM_1:
return PF1_IM | PF1_FILE | PF1_AUTHREQ | PF1_MODEMSG | PF1_EXTSEARCH | PF1_SERVERCLIST;
case PFLAGNUM_2:
@@ -66,13 +68,11 @@ DWORD_PTR CToxProto::GetCaps(int type, MCONTACT)
MCONTACT CToxProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
{
ptrA myAddress(getStringA(NULL, TOX_SETTINGS_ID));
- if (strnicmp(psr->id.a, myAddress, TOX_PUBLIC_KEY_SIZE) == 0)
- {
+ if (strnicmp(psr->id.a, myAddress, TOX_PUBLIC_KEY_SIZE) == 0) {
ShowNotification(TranslateT("You cannot add yourself to your contact list"), 0);
return NULL;
}
- if (MCONTACT hContact = GetContact(psr->id.a))
- {
+ if (MCONTACT hContact = GetContact(psr->id.a)) {
ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact);
return NULL;
}
@@ -151,14 +151,12 @@ int CToxProto::SetStatus(int iNewStatus)
int old_status = m_iStatus;
m_iDesiredStatus = iNewStatus;
- if (iNewStatus == ID_STATUS_OFFLINE)
- {
+ if (iNewStatus == ID_STATUS_OFFLINE) {
// logout
isTerminated = true;
SetEvent(hTerminateEvent);
- if (!Miranda_IsTerminated())
- {
+ if (!Miranda_IsTerminated()) {
SetAllContactsStatus(ID_STATUS_OFFLINE);
//CloseAllChatChatSessions();
}
@@ -171,15 +169,13 @@ int CToxProto::SetStatus(int iNewStatus)
if (old_status >= ID_STATUS_CONNECTING && old_status < ID_STATUS_OFFLINE)
return 0;
- if (old_status == ID_STATUS_OFFLINE && !IsOnline())
- {
+ if (old_status == ID_STATUS_OFFLINE && !IsOnline()) {
// login
isTerminated = false;
m_iStatus = ID_STATUS_CONNECTING;
hPollingThread = ForkThreadEx(&CToxProto::PollingThread, NULL, NULL);
}
- else
- {
+ else {
// set tox status
m_iStatus = iNewStatus;
tox_self_set_status(toxThread->Tox(), MirandaToToxStatus(iNewStatus));
@@ -191,8 +187,7 @@ int CToxProto::SetStatus(int iNewStatus)
HANDLE CToxProto::GetAwayMsg(MCONTACT hContact)
{
- if (IsOnline())
- {
+ if (IsOnline()) {
ForkThread(&CToxProto::GetStatusMessageAsync, (void*)hContact);
return (HANDLE)hContact;
}
@@ -202,8 +197,7 @@ HANDLE CToxProto::GetAwayMsg(MCONTACT hContact)
int CToxProto::SetAwayMsg(int, const wchar_t *msg)
{
- if (IsOnline())
- {
+ if (IsOnline()) {
T2Utf statusMessage(msg);
TOX_ERR_SET_INFO error;
if (!tox_self_set_status_message(toxThread->Tox(), (uint8_t*)(char*)statusMessage, min(TOX_MAX_STATUS_MESSAGE_LENGTH, mir_strlen(statusMessage)), &error))
@@ -220,8 +214,7 @@ int CToxProto::UserIsTyping(MCONTACT hContact, int type)
int CToxProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam)
{
- switch (iEventType)
- {
+ switch (iEventType) {
case EV_PROTO_ONLOAD:
return OnAccountLoaded(wParam, lParam);
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index dea979efc0..810479ab30 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -71,7 +71,7 @@ public:
private:
CToxThread *toxThread;
mir_cs profileLock;
- wchar_t *accountName;
+ ptrW wszAccountName, wszGroup;
CTransferList transfers;
ULONG hMessageProcess;
diff --git a/protocols/Tox/src/tox_search.cpp b/protocols/Tox/src/tox_search.cpp
index 41c63b85a1..81724f482f 100644
--- a/protocols/Tox/src/tox_search.cpp
+++ b/protocols/Tox/src/tox_search.cpp
@@ -24,12 +24,10 @@ ToxHexAddress ResolveToxAddressFromDnsRecordV3(void *dns, uint32_t requestId, co
{
std::smatch match;
std::regex regex("^v=tox3;id=([a-z0-5.]+)$");
- if (std::regex_search(dnsRecord, match, regex))
- {
+ if (std::regex_search(dnsRecord, match, regex)) {
std::string id = match[1];
uint8_t data[TOX_ADDRESS_SIZE];
- if (tox_decrypt_dns3_TXT(dns, data, (uint8_t*)id.c_str(), (uint32_t)id.length(), requestId) != TOX_ERROR)
- {
+ if (tox_decrypt_dns3_TXT(dns, data, (uint8_t*)id.c_str(), (uint32_t)id.length(), requestId) != TOX_ERROR) {
return ToxHexAddress(data, TOX_ADDRESS_SIZE);
}
}
@@ -42,11 +40,9 @@ ToxHexAddress ResolveToxAddressFromDns(const char *dnsQuery)
DNS_RECORDA *record = NULL;
DNS_STATUS status = DnsQuery_A(dnsQuery, DNS_TYPE_TEXT, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD*)&record, NULL);
- while (status == ERROR_SUCCESS && record)
- {
+ while (status == ERROR_SUCCESS && record) {
DNS_TXT_DATAA *txt = &record->Data.Txt;
- if (record->wType == DNS_TYPE_TEXT && txt->dwStringCount)
- {
+ if (record->wType == DNS_TYPE_TEXT && txt->dwStringCount) {
address = ResolveToxAddressFromDnsRecordV1(txt->pStringArray[0]);
break;
}
@@ -166,13 +162,12 @@ void CToxProto::SearchByNameAsync(void *arg)
}*/
ToxHexAddress address = ResolveToxAddressFromToxme(m_hNetlibUser, query);
- if (!address.IsEmpty())
- {
+ if (!address.IsEmpty()) {
PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) };
psr.flags = PSR_UTF8;
psr.id.a = mir_strdup(address);
psr.nick.a = mir_strdup(name);
-
+
char email[MAX_PATH];
mir_snprintf(email, "%s@toxme.io", name);
psr.email.a = mir_strdup(email);
@@ -194,8 +189,7 @@ INT_PTR CToxProto::SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM, LPARAM lParam)
{
CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- switch (uMsg)
- {
+ switch (uMsg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwnd);
{
@@ -214,8 +208,7 @@ INT_PTR CToxProto::SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM, LPARAM lParam)
HWND CToxProto::OnSearchAdvanced(HWND owner)
{
- if (!IsOnline())
- {
+ if (!IsOnline()) {
// we cannot add someone to friend list while tox is offline
return NULL;
}
@@ -227,8 +220,7 @@ HWND CToxProto::OnSearchAdvanced(HWND owner)
GetDlgItemText(owner, IDC_SEARCH, text, _countof(text));
const std::string query = T2Utf(text).str();
- if (std::regex_search(query, match, regex))
- {
+ if (std::regex_search(query, match, regex)) {
std::string address = match[1];
PROTOSEARCHRESULT psr = { sizeof(psr) };
@@ -243,8 +235,7 @@ HWND CToxProto::OnSearchAdvanced(HWND owner)
ForkThread(&CToxProto::SearchFailedAsync, NULL);
}
- else
- {
+ else {
regex = "^\\s*(([^ @/:;()\"']+)(@[A-Za-z]+.[A-Za-z]{2,6})?)\\s*$";
if (std::regex_search(query, match, regex))
ForkThread(&CToxProto::SearchByNameAsync, mir_strdup(query.c_str()));
@@ -256,10 +247,5 @@ HWND CToxProto::OnSearchAdvanced(HWND owner)
HWND CToxProto::OnCreateExtendedSearchUI(HWND owner)
{
- return CreateDialogParam(
- g_hInstance,
- MAKEINTRESOURCE(IDD_SEARCH),
- owner,
- SearchDlgProc,
- (LPARAM)this);
-} \ No newline at end of file
+ return CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_SEARCH), owner, SearchDlgProc, (LPARAM)this);
+}
diff --git a/protocols/Tox/src/tox_services.cpp b/protocols/Tox/src/tox_services.cpp
index 5f3db0ac89..532eef79d7 100644
--- a/protocols/Tox/src/tox_services.cpp
+++ b/protocols/Tox/src/tox_services.cpp
@@ -5,8 +5,7 @@ INT_PTR CToxProto::SetMyNickname(WPARAM wParam, LPARAM lParam)
ptrW nickname((wParam & SMNN_UNICODE) ? mir_wstrdup((wchar_t*)lParam) : mir_a2u((char*)lParam));
setWString("Nick", nickname);
- if (IsOnline())
- {
+ if (IsOnline()) {
T2Utf szNick8(nickname);
TOX_ERR_SET_INFO error;
if (!tox_self_set_name(toxThread->Tox(), szNick8, mir_strlen(szNick8), &error))
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index 38caa0ffbb..055be5d330 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -10,10 +10,8 @@ void CToxProto::OnFriendFile(Tox *tox, uint32_t friendNumber, uint32_t fileNumbe
ToxHexAddress pubKey = proto->GetContactPublicKey(tox, friendNumber);
MCONTACT hContact = proto->GetContact(tox, friendNumber);
- if (hContact)
- {
- switch (kind)
- {
+ if (hContact) {
+ switch (kind) {
case TOX_FILE_KIND_AVATAR:
{
proto->debugLogA(__FUNCTION__": incoming avatar (%d) from %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
@@ -29,8 +27,7 @@ void CToxProto::OnFriendFile(Tox *tox, uint32_t friendNumber, uint32_t fileNumbe
TOX_ERR_FILE_GET error;
tox_file_get_file_id(tox, friendNumber, fileNumber, transfer->hash, &error);
- if (error != TOX_ERR_FILE_GET_OK)
- {
+ if (error != TOX_ERR_FILE_GET_OK) {
Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": unable to get avatar hash (%d) from %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, error);
memset(transfer->hash, 0, TOX_HASH_LENGTH);
}
@@ -81,8 +78,7 @@ HANDLE CToxProto::OnFileAllow(MCONTACT hContact, HANDLE hTransfer, const wchar_t
mir_snwprintf(fullPath, L"%s\\%s", transfer->pfts.tszWorkingDir, transfer->pfts.tszCurrentFile);
transfer->ChangeName(fullPath);
- if (!ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, (HANDLE)transfer, (LPARAM)&transfer->pfts))
- {
+ if (!ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, (HANDLE)transfer, (LPARAM)&transfer->pfts)) {
int action = FILERESUME_OVERWRITE;
const wchar_t **szFilename = (const wchar_t**)mir_alloc(sizeof(wchar_t*) * 2);
szFilename[0] = fullPath;
@@ -99,8 +95,7 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const wchar_t **szFil
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
- if (*action == FILERESUME_SKIP)
- {
+ if (*action == FILERESUME_SKIP) {
tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
return 0;
@@ -112,8 +107,7 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const wchar_t **szFil
ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), transfer->friendNumber);
wchar_t *mode = *action == FILERESUME_OVERWRITE ? L"wb" : L"ab";
- if (!transfer->OpenFile(mode))
- {
+ if (!transfer->OpenFile(mode)) {
debugLogA(__FUNCTION__": failed to open file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
@@ -122,8 +116,7 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const wchar_t **szFil
TOX_ERR_FILE_CONTROL error;
debugLogA(__FUNCTION__": start receiving file (%d) from %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
- if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
- {
+ if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) {
debugLogA(__FUNCTION__": failed to start receiving of file(%d) from %s(%d) cause (%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
@@ -142,8 +135,7 @@ void CToxProto::OnTransferCompleted(FileTransferParam *transfer)
if (!isFileFullyTransfered)
debugLogA(__FUNCTION__": file (%d) from %s(%d) is transferred not completely", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
- if (transfer->transferType == TOX_FILE_KIND_AVATAR)
- {
+ if (transfer->transferType == TOX_FILE_KIND_AVATAR) {
OnGotFriendAvatarData((AvatarTransferParam*)transfer);
return;
}
@@ -160,22 +152,19 @@ void CToxProto::OnDataReceiving(Tox *tox, uint32_t friendNumber, uint32_t fileNu
ToxHexAddress pubKey = proto->GetContactPublicKey(tox, friendNumber);
FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
- if (transfer == NULL)
- {
+ if (transfer == NULL) {
Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to find transfer (%d) from %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
return;
}
//receiving is finished
- if (length == 0 || position == UINT64_MAX)
- {
+ if (length == 0 || position == UINT64_MAX) {
proto->OnTransferCompleted(transfer);
return;
}
MCONTACT hContact = proto->GetContact(tox, friendNumber);
- if (hContact == NULL)
- {
+ if (hContact == NULL) {
Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": cannot find contact %s(%d)", (const char*)pubKey, friendNumber);
tox_file_control(tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
@@ -185,8 +174,7 @@ void CToxProto::OnDataReceiving(Tox *tox, uint32_t friendNumber, uint32_t fileNu
if (filePos != position)
_fseeki64(transfer->hFile, position, SEEK_SET);
- if (fwrite(data, sizeof(uint8_t), length, transfer->hFile) != length)
- {
+ if (fwrite(data, sizeof(uint8_t), length, transfer->hFile) != length) {
proto->debugLogA(__FUNCTION__": failed write to file (%d)", fileNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(proto->toxThread->Tox(), friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
@@ -207,8 +195,7 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const wchar_t*, wchar_t **ppszFi
return NULL;
FILE *hFile = _wfopen(ppszFiles[0], L"rb");
- if (hFile == NULL)
- {
+ if (hFile == NULL) {
debugLogA(__FUNCTION__": cannot open file %s", ppszFiles[0]);
return NULL;
}
@@ -228,8 +215,7 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const wchar_t*, wchar_t **ppszFi
char *name = mir_utf8encodeW(fileName);
TOX_ERR_FILE_SEND sendError;
uint32_t fileNumber = tox_file_send(toxThread->Tox(), friendNumber, TOX_FILE_KIND_DATA, fileSize, NULL, (uint8_t*)name, mir_strlen(name), &sendError);
- if (sendError != TOX_ERR_FILE_SEND_OK)
- {
+ if (sendError != TOX_ERR_FILE_SEND_OK) {
debugLogA(__FUNCTION__": failed to send file (%d) to %s(%d) cause (%d)", fileNumber, (const char*)pubKey, friendNumber, sendError);
mir_free(fileDir);
mir_free(name);
@@ -255,15 +241,13 @@ void CToxProto::OnFileSendData(Tox *tox, uint32_t friendNumber, uint32_t fileNum
ToxHexAddress pubKey = proto->GetContactPublicKey(tox, friendNumber);
FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
- if (!transfer)
- {
+ if (!transfer) {
proto->debugLogA(__FUNCTION__": failed to find transfer (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
tox_file_control(tox, friendNumber, fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
return;
}
- if (length == 0)
- {
+ if (length == 0) {
// file sending is finished
proto->debugLogA(__FUNCTION__": finised the transfer of file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
bool isFileFullyTransfered = transfer->pfts.currentFileProgress == transfer->pfts.currentFileSize;
@@ -279,8 +263,7 @@ void CToxProto::OnFileSendData(Tox *tox, uint32_t friendNumber, uint32_t fileNum
_fseeki64(transfer->hFile, position, SEEK_SET);
uint8_t *data = (uint8_t*)mir_alloc(length);
- if (fread(data, sizeof(uint8_t), length, transfer->hFile) != length)
- {
+ if (fread(data, sizeof(uint8_t), length, transfer->hFile) != length) {
proto->debugLogA(__FUNCTION__": failed to read from file (%d) to %s(%d)", fileNumber, (const char*)pubKey, friendNumber);
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0);
tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
@@ -289,10 +272,8 @@ void CToxProto::OnFileSendData(Tox *tox, uint32_t friendNumber, uint32_t fileNum
}
TOX_ERR_FILE_SEND_CHUNK error;
- if (!tox_file_send_chunk(proto->toxThread->Tox(), friendNumber, fileNumber, position, data, length, &error))
- {
- if (error == TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_CONNECTED)
- {
+ if (!tox_file_send_chunk(proto->toxThread->Tox(), friendNumber, fileNumber, position, data, length, &error)) {
+ if (error == TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_CONNECTED) {
mir_free(data);
return;
}
@@ -323,18 +304,15 @@ int CToxProto::CancelTransfer(MCONTACT, HANDLE hTransfer)
void CToxProto::PauseOutgoingTransfers(uint32_t friendNumber)
{
- for (size_t i = 0; i < transfers.Count(); i++)
- {
+ for (size_t i = 0; i < transfers.Count(); i++) {
// only for sending
FileTransferParam *transfer = transfers.GetAt(i);
- if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 0)
- {
+ if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 0) {
ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), friendNumber);
debugLogA(__FUNCTION__": sending ask to pause the transfer of file (%d) to %s(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
TOX_ERR_FILE_CONTROL error;
- if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_PAUSE, &error))
- {
+ if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_PAUSE, &error)) {
debugLogA(__FUNCTION__": failed to pause the transfer (%d) to %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
}
@@ -344,18 +322,15 @@ void CToxProto::PauseOutgoingTransfers(uint32_t friendNumber)
void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber)
{
- for (size_t i = 0; i < transfers.Count(); i++)
- {
+ for (size_t i = 0; i < transfers.Count(); i++) {
// only for receiving
FileTransferParam *transfer = transfers.GetAt(i);
- if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 1)
- {
+ if (transfer->friendNumber == friendNumber && transfer->GetDirection() == 1) {
ToxHexAddress pubKey = GetContactPublicKey(toxThread->Tox(), friendNumber);
debugLogA(__FUNCTION__": sending ask to resume the transfer of file (%d) from %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber);
TOX_ERR_FILE_CONTROL error;
- if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error))
- {
+ if (!tox_file_control(toxThread->Tox(), transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_RESUME, &error)) {
debugLogA(__FUNCTION__": failed to resume the transfer (%d) from %s(%d) cause(%d)", transfer->fileNumber, (const char*)pubKey, transfer->friendNumber, error);
CancelTransfer(NULL, transfer);
}
@@ -365,8 +340,7 @@ void CToxProto::ResumeIncomingTransfers(uint32_t friendNumber)
void CToxProto::CancelAllTransfers(Tox *tox)
{
- for (size_t i = 0; i < transfers.Count(); i++)
- {
+ for (size_t i = 0; i < transfers.Count(); i++) {
FileTransferParam *transfer = transfers.GetAt(i);
tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)transfer, 0);
@@ -379,17 +353,14 @@ void CToxProto::OnFileRequest(Tox *tox, uint32_t friendNumber, uint32_t fileNumb
CToxProto *proto = (CToxProto*)arg;
MCONTACT hContact = proto->GetContact(tox, friendNumber);
- if (hContact)
- {
+ if (hContact) {
FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
- if (transfer == NULL)
- {
+ if (transfer == NULL) {
proto->debugLogA(__FUNCTION__": failed to find transfer (%d)", fileNumber);
return;
}
- switch (control)
- {
+ switch (control) {
case TOX_FILE_CONTROL_PAUSE:
break;
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index 77b4f0ad84..f90c927004 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -2,8 +2,7 @@
int CToxProto::MapStatus(int status)
{
- switch (status)
- {
+ switch (status) {
case ID_STATUS_FREECHAT:
case ID_STATUS_ONTHEPHONE:
status = ID_STATUS_ONLINE;
@@ -25,8 +24,7 @@ int CToxProto::MapStatus(int status)
TOX_USER_STATUS CToxProto::MirandaToToxStatus(int status)
{
TOX_USER_STATUS userstatus = TOX_USER_STATUS_NONE;
- switch (status)
- {
+ switch (status) {
case ID_STATUS_AWAY:
userstatus = TOX_USER_STATUS_AWAY;
break;
@@ -40,8 +38,7 @@ TOX_USER_STATUS CToxProto::MirandaToToxStatus(int status)
int CToxProto::ToxToMirandaStatus(TOX_USER_STATUS userstatus)
{
int status = ID_STATUS_OFFLINE;
- switch (userstatus)
- {
+ switch (userstatus) {
case TOX_USER_STATUS_NONE:
status = ID_STATUS_ONLINE;
break;
@@ -57,8 +54,7 @@ int CToxProto::ToxToMirandaStatus(TOX_USER_STATUS userstatus)
wchar_t* CToxProto::ToxErrorToString(TOX_ERR_NEW error)
{
- switch (error)
- {
+ switch (error) {
case TOX_ERR_NEW_NULL:
return TranslateT("One of the arguments is missing");
case TOX_ERR_NEW_MALLOC:
@@ -84,8 +80,7 @@ wchar_t* CToxProto::ToxErrorToString(TOX_ERR_NEW error)
wchar_t* CToxProto::ToxErrorToString(TOX_ERR_FRIEND_SEND_MESSAGE error)
{
- switch (error)
- {
+ switch (error) {
case TOX_ERR_FRIEND_SEND_MESSAGE_NULL:
return TranslateT("One of the arguments is missing");
case TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND:
@@ -105,13 +100,11 @@ wchar_t* CToxProto::ToxErrorToString(TOX_ERR_FRIEND_SEND_MESSAGE error)
void CToxProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact)
{
- if (Miranda_IsTerminated())
- {
+ if (Miranda_IsTerminated()) {
return;
}
- if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1))
- {
+ if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) {
POPUPDATAT ppd = { 0 };
ppd.lchContact = hContact;
wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
@@ -157,10 +150,8 @@ INT_PTR CToxProto::ParseToxUri(WPARAM, LPARAM lParam)
return 1;
CToxProto *proto = NULL;
- for (int i = 0; i < Accounts.getCount(); i++)
- {
- if (Accounts[i]->IsOnline())
- {
+ for (int i = 0; i < Accounts.getCount(); i++) {
+ if (Accounts[i]->IsOnline()) {
proto = Accounts[i];
break;
}
@@ -181,4 +172,4 @@ INT_PTR CToxProto::ParseToxUri(WPARAM, LPARAM lParam)
CallService(MS_ADDCONTACT_SHOW, 0, (LPARAM)&acs);
return 0;
-} \ No newline at end of file
+}