summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_accounts.cpp
blob: 95b7284e93920e27ebaeb2dd1fc5a904afd1997e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "common.h"

LIST<CToxProto> CToxProto::accounts(1, CToxProto::CompareAccounts);

int CToxProto::CompareAccounts(const CToxProto *p1, const CToxProto *p2)
{
	return _tcscmp(p1->m_tszUserName, p2->m_tszUserName);
}

CToxProto* CToxProto::InitAccount(const char* protoName, const wchar_t* userName)
{
	CToxProto *ppro = new CToxProto(protoName, userName);
	accounts.insert(ppro);

	return ppro;
}

int CToxProto::UninitAccount(CToxProto* ppro)
{
	accounts.remove(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_ADDED:
			UninitToxCore();
			DialogBoxParam(
				g_hInstance,
				MAKEINTRESOURCE(IDD_PROFILE_MANAGER),
				account->hwndAccMgrUI,
				CToxProto::ToxProfileManagerProc,
				(LPARAM)this);
			InitToxCore();
			break;

		case PRAC_CHANGED:
			UninitToxCore();
			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);
			mir_free(accountName);
			accountName = mir_tstrdup(m_tszUserName);
			InitToxCore();
			break;
		}
	}

	return 0;
}