diff options
-rw-r--r-- | protocols/Tox/src/main.cpp | 4 | ||||
-rw-r--r-- | protocols/Tox/src/tox_account.cpp | 28 | ||||
-rw-r--r-- | protocols/Tox/src/tox_accounts.cpp | 22 | ||||
-rw-r--r-- | protocols/Tox/src/tox_events.cpp | 7 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.cpp | 21 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 15 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 5 |
7 files changed, 39 insertions, 63 deletions
diff --git a/protocols/Tox/src/main.cpp b/protocols/Tox/src/main.cpp index dcf36ddbb6..4077163196 100644 --- a/protocols/Tox/src/main.cpp +++ b/protocols/Tox/src/main.cpp @@ -41,9 +41,7 @@ extern "C" int __declspec(dllexport) Load(void) pd.type = PROTOTYPE_PROTOCOL;
pd.fnInit = (pfnInitProto)CToxProto::InitAccount;
pd.fnUninit = (pfnUninitProto)CToxProto::UninitAccount;
- CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd);
-
- return 0;
+ return CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd);
}
extern "C" int __declspec(dllexport) Unload(void)
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index a733d5f480..0262ba774e 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -10,11 +10,33 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM) {
HookProtoEvent(ME_OPT_INITIALISE, &CToxProto::OnOptionsInit);
HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit);
- HookProtoEvent(ME_PROTO_ACCLISTCHANGED, &CToxProto::OnAccountListChanged);
HookProtoEvent(ME_DB_CONTACT_SETTINGCHANGED, &CToxProto::OnSettingsChanged);
- HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage);
+ HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage);
InitNetlib();
+ InitToxCore();
+
+ return 0;
+}
+
+int CToxProto::OnAccountRenamed(WPARAM, LPARAM lParam)
+{
+ PROTOACCOUNT *account = (PROTOACCOUNT*)lParam;
+
+ std::tstring newPath = GetToxProfilePath();
+ TCHAR oldPath[MAX_PATH];
+ mir_sntprintf(oldPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), accountName);
+ MoveFileEx(oldPath, newPath.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
+ mir_free(accountName);
+ accountName = mir_tstrdup(m_tszUserName);
+
+ return 0;
+}
+
+int CToxProto::OnAccountUnloaded(WPARAM, LPARAM)
+{
+ UninitToxCore();
+ UninitNetlib();
return 0;
}
@@ -35,7 +57,7 @@ void CToxProto::InitToxCore() options.udp_disabled = getByte("DisableUDP", 0);
options.ipv6enabled = !getByte("DisableIPv6", 0);
- if (hNetlib)
+ if (hNetlib != NULL)
{
NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) };
CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlib, (LPARAM)&nlus);
diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index 091923ccdf..875996b9a8 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -32,26 +32,4 @@ int CToxProto::UninitAccount(CToxProto* ppro) delete ppro;
return 0;
-}
-
-int CToxProto::OnAccountListChanged(WPARAM wParam, LPARAM lParam)
-{
- PROTOACCOUNT* account = (PROTOACCOUNT*)lParam;
-
- if (!strcmp(account->szModuleName, m_szModuleName))
- {
- switch (wParam)
- {
- case PRAC_CHANGED:
- std::tstring newPath = GetToxProfilePath();
- TCHAR oldPath[MAX_PATH];
- mir_sntprintf(oldPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), accountName);
- MoveFileEx(oldPath, newPath.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
- mir_free(accountName);
- accountName = mir_tstrdup(m_tszUserName);
- break;
- }
- }
-
- return 0;
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index a2a4b83a7e..d34ac4963a 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -1,12 +1,5 @@ #include "common.h"
-int CToxProto::OnPreShutdown(WPARAM, LPARAM)
-{
- UninitNetlib();
-
- return 0;
-}
-
INT_PTR CToxProto::OnAccountManagerInit(WPARAM, LPARAM lParam)
{
return (INT_PTR)CreateDialogParam(
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index 8131164053..de1a844234 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -17,12 +17,6 @@ std::tstring CToxProto::GetToxProfilePath(const TCHAR *accountName) void CToxProto::LoadToxProfile()
{
- if (tox == NULL)
- {
- debugLogA("CToxProto::SaveToxProfile: tox core was not initialized");
- return;
- }
-
DWORD size = GetFileSize(hProfile, NULL);
if (size == 0)
{
@@ -31,7 +25,7 @@ void CToxProto::LoadToxProfile() }
DWORD read = 0;
- uint8_t *data = (uint8_t*)mir_alloc(size);
+ uint8_t *data = (uint8_t*)mir_calloc(size);
if (!ReadFile(hProfile, data, size, &read, NULL) || size != read)
{
debugLogA("CToxProto::LoadToxData: could not read tox profile");
@@ -62,20 +56,13 @@ void CToxProto::LoadToxProfile() void CToxProto::SaveToxProfile()
{
- if (tox == NULL)
- {
- debugLogA("CToxProto::SaveToxProfile: tox core was not initialized");
- return;
- }
-
ptrT password(getTStringA("Password"));
bool needToEncrypt = password && _tcslen(password);
-
DWORD size = needToEncrypt
- ? size = tox_encrypted_size(tox)
- : size = tox_size(tox);
+ ? tox_encrypted_size(tox)
+ : tox_size(tox);
- uint8_t *data = (uint8_t*)mir_alloc(size);
+ uint8_t *data = (uint8_t*)mir_calloc(size);
if (needToEncrypt)
{
char *passwordInUtf8 = mir_utf8encodeW(password);
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 342b86e696..485c049c33 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -1,12 +1,10 @@ #include "common.h"
CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
-PROTO<CToxProto>(protoName, userName)
+ PROTO<CToxProto>(protoName, userName)
{
accountName = mir_tstrdup(userName);
- InitToxCore();
-
CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
SetAllContactsStatus(ID_STATUS_OFFLINE);
@@ -49,8 +47,6 @@ PROTO<CToxProto>(protoName, userName) CToxProto::~CToxProto()
{
- UninitToxCore();
-
mir_free(accountName);
}
@@ -236,11 +232,14 @@ int __cdecl CToxProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM case EV_PROTO_ONLOAD:
return OnAccountLoaded(wParam, lParam);
- case EV_PROTO_ONCONTACTDELETED:
- return OnContactDeleted(wParam, lParam);
+ case EV_PROTO_ONRENAME:
+ return OnAccountRenamed(wParam, lParam);
case EV_PROTO_ONEXIT:
- return OnPreShutdown(wParam, lParam);
+ return OnAccountUnloaded(wParam, lParam);
+
+ case EV_PROTO_ONCONTACTDELETED:
+ return OnContactDeleted(wParam, lParam);
}
return 1;
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index bef938599b..405da468b5 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -137,8 +137,6 @@ private: static LIST<CToxProto> accounts;
static int CompareAccounts(const CToxProto *p1, const CToxProto *p2);
- int __cdecl OnAccountListChanged(WPARAM wParam, LPARAM lParam);
-
// netlib
void InitNetlib();
void UninitNetlib();
@@ -146,9 +144,10 @@ private: // account
bool IsOnline();
int __cdecl OnAccountLoaded(WPARAM, LPARAM);
+ int __cdecl OnAccountRenamed(WPARAM, LPARAM);
+ int __cdecl OnAccountUnloaded(WPARAM, LPARAM);
// events
- int __cdecl OnPreShutdown(WPARAM, LPARAM);
int __cdecl OnSettingsChanged(WPARAM wParam, LPARAM lParam);
// options
|