summaryrefslogtreecommitdiff
path: root/protocols/Tox
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-10-04 01:14:11 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-10-04 01:14:11 +0000
commit928158d25b533037df6ba4a1b1daedeefb05bbbb (patch)
treeff6d48fffb7182bda42cbd1d057496e78bed350d /protocols/Tox
parent334c3a9d18f177f1b6c71d754219f56057d315c0 (diff)
Tox:
- tox id is key again - reworked tox profile logic git-svn-id: http://svn.miranda-ng.org/main/trunk@10679 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r--protocols/Tox/res/resource.rc10
-rw-r--r--protocols/Tox/src/tox_account.cpp15
-rw-r--r--protocols/Tox/src/tox_accounts.cpp22
-rw-r--r--protocols/Tox/src/tox_profile.cpp85
-rw-r--r--protocols/Tox/src/tox_proto.cpp4
-rw-r--r--protocols/Tox/src/tox_proto.h7
-rw-r--r--protocols/Tox/src/tox_utils.cpp14
7 files changed, 62 insertions, 95 deletions
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc
index 5164fbea0e..b1628090db 100644
--- a/protocols/Tox/res/resource.rc
+++ b/protocols/Tox/res/resource.rc
@@ -116,17 +116,17 @@ BEGIN
EDITTEXT IDC_PASSWORD,81,66,219,14,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE
END
-IDD_PROFILE_IMPORT DIALOGEX 0, 0, 235, 87
+IDD_PROFILE_IMPORT DIALOGEX 0, 0, 239, 87
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Tox profile import"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Import",IDOK,124,68,50,14,WS_DISABLED
- LTEXT "Tox profile contains your ID and friend list.\r\nYou may import existing profile from other tox client.\r\nPress ""Import"" to perform import from existing profile.\r\nPress ""Cancel"" or close this window to create new profile.",IDC_STATIC,7,5,221,37
+ LTEXT "Tox profile contains your ID and friend list.\r\nYou may import existing profile from other tox client.\r\nPress ""Import"" to perform import from existing profile.\r\nPress ""Cancel"" or close this window to create new profile.",IDC_STATIC,7,5,225,37
EDITTEXT IDC_PROFILE_PATH,7,42,202,14,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_BROWSE_PROFILE,212,42,16,14
- DEFPUSHBUTTON "Cancel",IDCANCEL,178,68,50,14
+ PUSHBUTTON "...",IDC_BROWSE_PROFILE,216,42,16,14
+ DEFPUSHBUTTON "Cancel",IDCANCEL,182,68,50,14
END
IDD_SEARCH DIALOGEX 0, 0, 109, 113
@@ -186,7 +186,7 @@ BEGIN
IDD_PROFILE_IMPORT, DIALOG
BEGIN
LEFTMARGIN, 7
- RIGHTMARGIN, 228
+ RIGHTMARGIN, 232
TOPMARGIN, 5
BOTTOMMARGIN, 82
HORZGUIDE, 42
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp
index 6a40a14526..a733d5f480 100644
--- a/protocols/Tox/src/tox_account.cpp
+++ b/protocols/Tox/src/tox_account.cpp
@@ -22,17 +22,12 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM)
void CToxProto::InitToxCore()
{
std::tstring profilePath = GetToxProfilePath();
- if (!IsFileExists(profilePath))
- {
- return;
- }
-
hProfile = CreateFile(
profilePath.c_str(),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
- OPEN_EXISTING,
+ OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
@@ -49,7 +44,7 @@ void CToxProto::InitToxCore()
{
if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5)
{
- debugLogA("CToxProto::InitToxCore: Setting socks user proxy config");
+ debugLogA("CToxProto::InitToxCore: setting socks user proxy config");
options.proxy_enabled = 1;
strcpy(&options.proxy_address[0], nlus.szProxyServer);
options.proxy_port = nlus.wProxyPort;
@@ -97,12 +92,6 @@ void CToxProto::InitToxCore()
void CToxProto::UninitToxCore()
{
- std::tstring profilePath = GetToxProfilePath();
- if (!IsFileExists(profilePath))
- {
- return;
- }
-
SaveToxProfile();
tox_kill(tox);
CloseHandle(hProfile);
diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp
index 97b6f9b345..091923ccdf 100644
--- a/protocols/Tox/src/tox_accounts.cpp
+++ b/protocols/Tox/src/tox_accounts.cpp
@@ -9,6 +9,17 @@ int CToxProto::CompareAccounts(const CToxProto *p1, const CToxProto *p2)
CToxProto* CToxProto::InitAccount(const char* protoName, const wchar_t* userName)
{
+ ptrA address(db_get_sa(NULL, protoName, TOX_SETTINGS_ID));
+ if (address == NULL)
+ {
+ DialogBoxParam(
+ g_hInstance,
+ MAKEINTRESOURCE(IDD_PROFILE_IMPORT),
+ GetActiveWindow(),
+ CToxProto::ToxProfileImportProc,
+ (LPARAM)userName);
+ }
+
CToxProto *ppro = new CToxProto(protoName, userName);
accounts.insert(ppro);
@@ -31,17 +42,6 @@ int CToxProto::OnAccountListChanged(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
- case PRAC_ADDED:
- DialogBoxParam(
- g_hInstance,
- MAKEINTRESOURCE(IDD_PROFILE_IMPORT),
- account->hwndAccMgrUI,
- CToxProto::ToxProfileManagerProc,
- (LPARAM)this);
- InitToxCore();
- SaveToxProfile();
- break;
-
case PRAC_CHANGED:
std::tstring newPath = GetToxProfilePath();
TCHAR oldPath[MAX_PATH];
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp
index 88248f7c27..8131164053 100644
--- a/protocols/Tox/src/tox_profile.cpp
+++ b/protocols/Tox/src/tox_profile.cpp
@@ -2,9 +2,14 @@
std::tstring CToxProto::GetToxProfilePath()
{
+ return GetToxProfilePath(m_tszUserName);
+}
+
+std::tstring CToxProto::GetToxProfilePath(const TCHAR *accountName)
+{
std::tstring profilePath;
TCHAR defaultPath[MAX_PATH];
- mir_sntprintf(defaultPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), m_tszUserName);
+ mir_sntprintf(defaultPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), accountName);
profilePath = defaultPath;
return profilePath;
@@ -14,32 +19,22 @@ void CToxProto::LoadToxProfile()
{
if (tox == NULL)
{
+ debugLogA("CToxProto::SaveToxProfile: tox core was not initialized");
return;
}
- std::tstring toxProfilePath = GetToxProfilePath();
- FILE *hFile = _wfopen(toxProfilePath.c_str(), _T("rb"));
- if (!hFile)
- {
- debugLogA("CToxProto::LoadToxData: could not open tox profile");
- return;
- }
-
- fseek(hFile, 0, SEEK_END);
- uint32_t size = ftell(hFile);
- rewind(hFile);
+ DWORD size = GetFileSize(hProfile, NULL);
if (size == 0)
{
debugLogA("CToxProto::LoadToxData: tox profile is empty");
- fclose(hFile);
return;
}
+ DWORD read = 0;
uint8_t *data = (uint8_t*)mir_alloc(size);
- if (fread(data, sizeof(uint8_t), size, hFile) != size)
+ if (!ReadFile(hProfile, data, size, &read, NULL) || size != read)
{
debugLogA("CToxProto::LoadToxData: could not read tox profile");
- fclose(hFile);
mir_free(data);
return;
}
@@ -63,61 +58,53 @@ void CToxProto::LoadToxProfile()
}
mir_free(data);
- fclose(hFile);
}
void CToxProto::SaveToxProfile()
{
if (tox == NULL)
{
+ debugLogA("CToxProto::SaveToxProfile: tox core was not initialized");
return;
}
- std::tstring toxProfilePath = GetToxProfilePath();
- FILE *hFile = _wfopen(toxProfilePath.c_str(), _T("wb"));
- if (!hFile)
- {
- debugLogA("CToxProto::LoadToxData: could not open tox profile");
- return;
- }
-
- uint32_t size;
ptrT password(getTStringA("Password"));
- if (password && _tcslen(password))
- size = tox_encrypted_size(tox);
- else
- size = tox_size(tox);
+ bool needToEncrypt = password && _tcslen(password);
+
+ DWORD size = needToEncrypt
+ ? size = tox_encrypted_size(tox)
+ : size = tox_size(tox);
+
uint8_t *data = (uint8_t*)mir_alloc(size);
- if (password && _tcslen(password))
+ if (needToEncrypt)
{
- char *password_utf8 = mir_utf8encodeW(password);
- if (tox_encrypted_save(tox, data, (uint8_t*)password_utf8, strlen(password_utf8)) == TOX_ERROR)
+ char *passwordInUtf8 = mir_utf8encodeW(password);
+ if (tox_encrypted_save(tox, data, (uint8_t*)passwordInUtf8, strlen(passwordInUtf8)) == TOX_ERROR)
{
debugLogA("CToxProto::LoadToxData: could not encrypt tox profile");
- mir_free(password_utf8);
+ mir_free(passwordInUtf8);
mir_free(data);
- fclose(hFile);
return;
}
- mir_free(password_utf8);
+ mir_free(passwordInUtf8);
}
else
{
tox_save(tox, data);
}
- if (fwrite(data, sizeof(uint8_t), size, hFile) != size)
+ DWORD written = 0;
+ if (!WriteFile(hProfile, data, size, &written, NULL) || size != written)
{
debugLogA("CToxProto::LoadToxData: could not write tox profile");
}
mir_free(data);
- fclose(hFile);
}
-INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+INT_PTR CToxProto::ToxProfileImportProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ TCHAR *accountName = (TCHAR*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
TCHAR *profilePath = (TCHAR*)GetWindowLongPtr(hwnd, DWLP_USER);
switch (uMsg)
@@ -125,7 +112,7 @@ INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
case WM_INITDIALOG:
TranslateDialogDefault(hwnd);
{
- proto = (CToxProto*)lParam;
+ accountName = (TCHAR*)lParam;
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
profilePath = (TCHAR*)mir_calloc(sizeof(TCHAR)*MAX_PATH);
@@ -133,17 +120,9 @@ INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
}
return TRUE;
- case WM_CLOSE:
- {
- std::tstring defaultProfilePath = proto->GetToxProfilePath();
- fclose(_wfopen(defaultProfilePath.c_str(), _T("w")));
- EndDialog(hwnd, 0);
- }
- break;
-
case WM_DESTROY:
mir_free(profilePath);
- break;
+ return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
@@ -180,7 +159,7 @@ INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
case IDOK:
{
- std::tstring defaultProfilePath = proto->GetToxProfilePath();
+ std::tstring defaultProfilePath = GetToxProfilePath(accountName);
if (profilePath && _tcslen(profilePath))
{
if (_tcsicmp(profilePath, defaultProfilePath.c_str()) != 0)
@@ -197,11 +176,7 @@ INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
break;
case IDCANCEL:
- {
- std::tstring defaultProfilePath = proto->GetToxProfilePath();
- fclose(_wfopen(defaultProfilePath.c_str(), _T("w")));
- EndDialog(hwnd, 0);
- }
+ EndDialog(hwnd, 0);
break;
}
break;
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index c8e350b46e..342b86e696 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -66,9 +66,9 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact)
return PF4_IMSENDUTF | PF4_SINGLEFILEONLY | PF4_NOAUTHDENYREASON | PF4_FORCEAUTH
| PF4_FORCEADDED | PF4_SUPPORTTYPING | PF4_AVATARS;
case PFLAG_UNIQUEIDTEXT:
- return (INT_PTR)"Dns ID";
+ return (INT_PTR)"Tox ID";
case PFLAG_UNIQUEIDSETTING:
- return (DWORD_PTR)TOX_SETTINGS_DNS;
+ return (DWORD_PTR)TOX_SETTINGS_ID;
case PFLAG_MAXLENOFMESSAGE:
return TOX_MAX_MESSAGE_LENGTH;
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 608f439365..bef938599b 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -126,11 +126,12 @@ private:
// tox profile
HANDLE hProfile;
std::tstring GetToxProfilePath();
+ static std::tstring CToxProto::GetToxProfilePath(const TCHAR *accountName);
void LoadToxProfile();
void SaveToxProfile();
- static INT_PTR CALLBACK ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ static INT_PTR CALLBACK ToxProfileImportProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// accounts
static LIST<CToxProto> accounts;
@@ -222,8 +223,8 @@ private:
TOX_USERSTATUS MirandaToToxStatus(int status);
int ToxToMirandaStatus(TOX_USERSTATUS userstatus);
- static void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
- static void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL);
+ static void ShowNotification(const TCHAR *message, int flags = 0, MCONTACT hContact = NULL);
+ static void ShowNotification(const TCHAR *caption, const TCHAR *message, int flags = 0, MCONTACT hContact = NULL);
HANDLE AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index a290e6a76e..f45c8d937e 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -33,29 +33,31 @@ int CToxProto::ToxToMirandaStatus(TOX_USERSTATUS userstatus)
return status;
}
-void CToxProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact)
+void CToxProto::ShowNotification(const TCHAR *caption, const TCHAR *message, int flags, MCONTACT hContact)
{
if (Miranda_Terminated())
+ {
return;
+ }
if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1))
{
- POPUPDATAW ppd = { 0 };
+ POPUPDATAT ppd = { 0 };
ppd.lchContact = hContact;
wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE);
ppd.lchIcon = Skin_GetIcon("Tox_main");
- if (!PUAddPopupW(&ppd))
+ if (!PUAddPopupT(&ppd))
return;
}
- MessageBoxW(NULL, message, caption, MB_OK | flags);
+ MessageBox(NULL, message, caption, MB_OK | flags);
}
-void CToxProto::ShowNotification(const wchar_t *message, int flags, MCONTACT hContact)
+void CToxProto::ShowNotification(const TCHAR *message, int flags, MCONTACT hContact)
{
- ShowNotification(TranslateT(MODULE), message, flags, hContact);
+ ShowNotification(_T(MODULE), message, flags, hContact);
}
HANDLE CToxProto::AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob)