summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-09-27 10:19:26 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-09-27 10:19:26 +0000
commit22b35cdc0d13336366efe44b57d682d5be6bae52 (patch)
treedc4fb01f13f4b11391c2c1c704d10b4ecc9c66b8
parent93467b8c3702be5fc9f9b60c3ff6863cb37ccd8d (diff)
Tox:
- password field temporary disables - some changes git-svn-id: http://svn.miranda-ng.org/main/trunk@10613 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/Tox/res/resource.rc8
-rw-r--r--protocols/Tox/src/tox_account.cpp12
-rw-r--r--protocols/Tox/src/tox_accounts.cpp3
-rw-r--r--protocols/Tox/src/tox_avatars.cpp12
-rw-r--r--protocols/Tox/src/tox_options.cpp35
-rw-r--r--protocols/Tox/src/tox_profile.cpp10
-rw-r--r--protocols/Tox/src/tox_proto.cpp3
-rw-r--r--protocols/Tox/src/tox_proto.h7
-rw-r--r--protocols/Tox/src/tox_utils.cpp50
9 files changed, 81 insertions, 59 deletions
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc
index 581e186747..593576dbb8 100644
--- a/protocols/Tox/res/resource.rc
+++ b/protocols/Tox/res/resource.rc
@@ -91,8 +91,8 @@ BEGIN
LTEXT "Default group:",IDC_STATIC,12,40,54,12
EDITTEXT IDC_GROUP,66,39,120,12,ES_AUTOHSCROLL
PUSHBUTTON "C",IDC_CLIPBOARD,170,22,16,13
- LTEXT "Password:",IDC_STATIC,12,56,35,8
- EDITTEXT IDC_PASSWORD,67,54,119,14,ES_PASSWORD | ES_AUTOHSCROLL
+ LTEXT "Password:",IDC_STATIC,12,56,35,8,NOT WS_VISIBLE
+ EDITTEXT IDC_PASSWORD,67,54,119,14,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE
END
IDD_OPTIONS_MAIN DIALOGEX 0, 0, 312, 234
@@ -112,8 +112,8 @@ BEGIN
LTEXT "Default group:",IDC_STATIC,12,53,60,12
EDITTEXT IDC_GROUP,81,51,219,12,ES_AUTOHSCROLL
PUSHBUTTON "C",IDC_CLIPBOARD,284,35,16,13
- LTEXT "Passowrd:",IDC_STATIC,12,68,35,8
- EDITTEXT IDC_PASSWORD,81,66,219,14,ES_PASSWORD | ES_AUTOHSCROLL
+ LTEXT "Passowrd:",IDC_STATIC,12,68,35,8,NOT WS_VISIBLE
+ EDITTEXT IDC_PASSWORD,81,66,219,14,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE
END
IDD_PROFILE_MANAGER DIALOGEX 0, 0, 235, 111
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp
index ebb246c6f4..bc9255ad36 100644
--- a/protocols/Tox/src/tox_account.cpp
+++ b/protocols/Tox/src/tox_account.cpp
@@ -20,6 +20,11 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM)
void CToxProto::InitToxCore()
{
+ if (ptrA(this->getStringA("ToxID")) == NULL)
+ {
+ return;
+ }
+
Tox_Options options = { 0 };
options.udp_disabled = getByte("DisableUDP", 0);
options.ipv6enabled = !getByte("DisableIPv6", 0);
@@ -72,7 +77,7 @@ void CToxProto::InitToxCore()
std::string address = DataToHexString(pubKey);
setString(NULL, TOX_SETTINGS_ID, address.c_str());
- std::tstring avatarPath = GetContactAvatarFilePath(NULL);
+ std::tstring avatarPath = GetAvatarFilePath();
if (IsFileExists(avatarPath))
{
SetToxAvatar(avatarPath);
@@ -81,6 +86,11 @@ void CToxProto::InitToxCore()
void CToxProto::UninitToxCore()
{
+ if (ptrA(this->getStringA("ToxID")) == NULL)
+ {
+ return;
+ }
+
SaveToxData();
tox_kill(tox);
}
diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp
index acab9db206..95b7284e93 100644
--- a/protocols/Tox/src/tox_accounts.cpp
+++ b/protocols/Tox/src/tox_accounts.cpp
@@ -32,8 +32,7 @@ int CToxProto::OnAccountListChanged(WPARAM wParam, LPARAM lParam)
switch (wParam)
{
case PRAC_ADDED:
- if (this->getStringA("ToxID"))
- UninitToxCore();
+ UninitToxCore();
DialogBoxParam(
g_hInstance,
MAKEINTRESOURCE(IDD_PROFILE_MANAGER),
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp
index ef4810e520..714ee76473 100644
--- a/protocols/Tox/src/tox_avatars.cpp
+++ b/protocols/Tox/src/tox_avatars.cpp
@@ -1,6 +1,6 @@
#include "common.h"
-std::tstring CToxProto::GetContactAvatarFilePath(MCONTACT hContact)
+std::tstring CToxProto::GetAvatarFilePath(MCONTACT hContact)
{
TCHAR path[MAX_PATH];
mir_sntprintf(path, SIZEOF(path), _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName);
@@ -117,7 +117,7 @@ INT_PTR CToxProto::GetAvatarInfo(WPARAM, LPARAM lParam)
ptrA id(getStringA(pai->hContact, TOX_SETTINGS_ID));
if (id != NULL)
{
- std::tstring path = GetContactAvatarFilePath(pai->hContact);
+ std::tstring path = GetAvatarFilePath(pai->hContact);
if (IsFileExists(path))
{
_tcsncpy(pai->filename, path.c_str(), SIZEOF(pai->filename));
@@ -137,7 +137,7 @@ INT_PTR CToxProto::GetMyAvatar(WPARAM wParam, LPARAM lParam)
return -2;
}
- std::tstring path(GetContactAvatarFilePath(NULL));
+ std::tstring path(GetAvatarFilePath());
if (IsFileExists(path))
{
_tcsncpy((TCHAR*)wParam, path.c_str(), (int)lParam);
@@ -151,7 +151,7 @@ INT_PTR CToxProto::GetMyAvatar(WPARAM wParam, LPARAM lParam)
INT_PTR CToxProto::SetMyAvatar(WPARAM wParam, LPARAM lParam)
{
TCHAR *path = (TCHAR*)lParam;
- std::tstring avatarPath = GetContactAvatarFilePath(NULL);
+ std::tstring avatarPath = GetAvatarFilePath();
if (path != NULL)
{
if (!CopyFile(path, avatarPath.c_str(), FALSE))
@@ -188,7 +188,7 @@ void CToxProto::OnGotFriendAvatarInfo(Tox *tox, int32_t number, uint8_t format,
MCONTACT hContact = proto->FindContact(number);
if (hContact)
{
- std::tstring path = proto->GetContactAvatarFilePath(hContact);
+ std::tstring path = proto->GetAvatarFilePath(hContact);
if (format == TOX_AVATAR_FORMAT_NONE)
{
proto->delSetting(hContact, TOX_SETTINGS_AVATAR_HASH);
@@ -226,7 +226,7 @@ void CToxProto::OnGotFriendAvatarData(Tox *tox, int32_t number, uint8_t format,
{
db_set_blob(hContact, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, hash, TOX_HASH_LENGTH);
- std::tstring path = proto->GetContactAvatarFilePath(hContact);
+ std::tstring path = proto->GetAvatarFilePath(hContact);
FILE *hFile = _tfopen(path.c_str(), L"wb");
if (hFile)
{
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index d811569175..0b24416308 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -12,16 +12,16 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
proto = (CToxProto*)lParam;
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- ptrW nick(proto->getTStringA("Nick"));
+ ptrT nick(proto->getTStringA("Nick"));
SetDlgItemText(hwnd, IDC_NAME, nick);
- ptrW pass(proto->getTStringA("Password"));
+ ptrT pass(proto->getTStringA("Password"));
SetDlgItemText(hwnd, IDC_PASSWORD, pass);
std::string address = proto->getStringA(NULL, TOX_SETTINGS_ID);
SetDlgItemTextA(hwnd, IDC_TOXID, address.c_str());
- ptrW group(proto->getTStringA(TOX_SETTINGS_GROUP));
+ ptrT group(proto->getTStringA(TOX_SETTINGS_GROUP));
SetDlgItemText(hwnd, IDC_GROUP, group);
SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0);
@@ -35,6 +35,8 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
switch (LOWORD(wParam))
{
case IDC_NAME:
+ case IDC_GROUP:
+ case IDC_PASSWORD:
if ((HWND)lParam == GetFocus())
{
if (HIWORD(wParam) != EN_CHANGE) return 0;
@@ -42,13 +44,11 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
}
break;
- case IDC_PASSWORD:
- if ((HWND)lParam == GetFocus())
- {
- if (HIWORD(wParam) != EN_CHANGE) return 0;
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- }
+ case IDC_DISABLE_UDP:
+ case IDC_DISABLE_IPV6:
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
break;
+ }
case IDC_CLIPBOARD:
{
@@ -65,21 +65,6 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
}
}
break;
-
- case IDC_GROUP:
- if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
- return 0;
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_DISABLE_UDP:
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
-
- case IDC_DISABLE_IPV6:
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
- }
}
break;
@@ -108,6 +93,8 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
proto->delSetting(NULL, TOX_SETTINGS_GROUP);
}
+ proto->SaveToxData();
+
return TRUE;
}
break;
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp
index 1a23b85051..13f801ebb9 100644
--- a/protocols/Tox/src/tox_profile.cpp
+++ b/protocols/Tox/src/tox_profile.cpp
@@ -1,5 +1,15 @@
#include "common.h"
+std::tstring CToxProto::GetToxProfilePath()
+{
+ std::tstring profilePath;
+ TCHAR defaultPath[MAX_PATH];
+ mir_sntprintf(defaultPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), m_tszUserName);
+ profilePath = defaultPath;
+
+ return profilePath;
+}
+
INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index 0d3ab920f6..3016a400ee 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -5,8 +5,7 @@ PROTO<CToxProto>(protoName, userName)
{
accountName = mir_tstrdup(userName);
- if (this->getStringA("ToxID"))
- InitToxCore();
+ InitToxCore();
CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 182bc4bb3f..13ca949b93 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -124,6 +124,8 @@ private:
void __cdecl PollingThread(void*);
// tox profile
+ std::tstring GetToxProfilePath();
+
static INT_PTR CALLBACK ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// accounts
@@ -140,7 +142,6 @@ private:
bool IsOnline();
int __cdecl OnAccountLoaded(WPARAM, LPARAM);
-
// events
int __cdecl OnPreShutdown(WPARAM, LPARAM);
int __cdecl OnSettingsChanged(WPARAM wParam, LPARAM lParam);
@@ -198,7 +199,7 @@ private:
static void OnFileData(Tox *tox, int32_t number, uint8_t fileNumber, const uint8_t *data, uint16_t length, void *arg);
// avatars
- std::tstring GetContactAvatarFilePath(MCONTACT hContact);
+ std::tstring GetAvatarFilePath(MCONTACT hContact = NULL);
bool SetToxAvatar(std::tstring path, bool checkHash = false);
INT_PTR __cdecl GetAvatarCaps(WPARAM wParam, LPARAM lParam);
@@ -225,7 +226,7 @@ private:
static bool IsFileExists(std::tstring path);
- std::tstring GetToxProfilePath();
+
void LoadToxData();
void SaveToxData();
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index 2b2d5daa75..d294be81cd 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -121,16 +121,6 @@ bool CToxProto::IsFileExists(std::tstring path)
return false;
}
-std::tstring CToxProto::GetToxProfilePath()
-{
- std::tstring profilePath;
- TCHAR defaultPath[MAX_PATH];
- mir_sntprintf(defaultPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), m_tszUserName);
- profilePath = defaultPath;
-
- return profilePath;
-}
-
void CToxProto::LoadToxData()
{
std::tstring toxProfilePath = GetToxProfilePath();
@@ -146,7 +136,6 @@ void CToxProto::LoadToxData()
rewind(hFile);
uint8_t *data = (uint8_t*)mir_alloc(size);
-
if (fread(data, sizeof(uint8_t), size, hFile) != size)
{
debugLogA("CToxProto::LoadToxData: could not read tox profile");
@@ -155,12 +144,23 @@ void CToxProto::LoadToxData()
return;
}
- if (tox_is_data_encrypted(data)) {
- ptrA password(mir_utf8encodeW(ptrT(getTStringA("Password"))));
- tox_encrypted_load(tox, data, size, (uint8_t*)(char*)password, strlen(password));
+ if (tox_is_data_encrypted(data))
+ {
+ ptrT password(getTStringA("Password"));
+ char *password_utf8 = mir_utf8encodeW(password);
+ if (tox_encrypted_load(tox, data, size, (uint8_t*)password_utf8, strlen(password_utf8)) == TOX_ERROR)
+ {
+ debugLogA("CToxProto::LoadToxData: could not decrypt tox profile");
+ }
+ mir_free(password_utf8);
}
else
- tox_load(tox, data, size);
+ {
+ if (tox_load(tox, data, size) == TOX_ERROR)
+ {
+ debugLogA("CToxProto::LoadToxData: could not load tox profile");
+ }
+ }
mir_free(data);
fclose(hFile);
@@ -178,8 +178,24 @@ void CToxProto::SaveToxData()
uint32_t size = tox_encrypted_size(tox);
uint8_t *data = (uint8_t*)mir_alloc(size);
- ptrA password(mir_utf8encodeW(ptrT(getTStringA("Password"))));
- tox_encrypted_save(tox, data, (uint8_t*)(char*)password, strlen(password));
+ ptrT password(getTStringA("Password"));
+ if (password && _tcslen(password))
+ {
+ char *password_utf8 = mir_utf8encodeW(password);
+ if (tox_encrypted_save(tox, data, (uint8_t*)password_utf8, strlen(password_utf8)) == TOX_ERROR)
+ {
+ debugLogA("CToxProto::LoadToxData: could not encrypt tox profile");
+ mir_free(password_utf8);
+ mir_free(data);
+ fclose(hFile);
+ return;
+ }
+ mir_free(password_utf8);
+ }
+ else
+ {
+ tox_save(tox, data);
+ }
if (fwrite(data, sizeof(uint8_t), size, hFile) != size)
{