summaryrefslogtreecommitdiff
path: root/plugins/Folders/src/services.cpp
blob: b5e9cfd96b1eefa80dcf85f6c797de4b2bb26403 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Custom profile folders plugin for Miranda IM

Copyright © 2005 Cristian Libotean

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "stdafx.h"

#define DEFAULT_SECTION "Unknown"

wchar_t szCurrentProfilePath[MAX_FOLDERS_PATH];
wchar_t szCurrentProfile[MAX_FOLDERS_PATH];
wchar_t szMirandaPath[MAX_FOLDERS_PATH];
wchar_t szUserDataPath[MAX_FOLDERS_PATH];

INT_PTR RegisterPathService(WPARAM, LPARAM lParam)
{
	FOLDERSDATA *data = (FOLDERSDATA*)lParam;
	if (data == nullptr)
		return NULL;

	if (data->cbSize != sizeof(FOLDERSDATA))
		return NULL;

	CFolderItem *pNew;
	if (data->flags & FF_UNICODE)
		pNew = new CFolderItem(data->szSection, data->szName, data->szFormatW, data->szUserNameW);
	else
		pNew = new CFolderItem(data->szSection, data->szName, _A2T(data->szFormat), _A2T(data->szUserName));

	lstRegisteredFolders.insert(pNew);
	return (INT_PTR)pNew;
}

INT_PTR GetPathSizeService(WPARAM wParam, LPARAM lParam)
{
	CFolderItem *p = (CFolderItem*)wParam;
	size_t len = (lstRegisteredFolders.getIndex(p) != -1) ? p->Expand().GetLength() : 0;

	if (lParam != NULL)
		*((size_t*)lParam) = len;

	return len;
}

INT_PTR GetPathService(WPARAM wParam, LPARAM lParam)
{
	CFolderItem *p = (CFolderItem*)wParam;
	if (lstRegisteredFolders.getIndex(p) == -1)
		return 1;

	FOLDERSGETDATA* data = (FOLDERSGETDATA*)lParam;
	if (data->cbSize != sizeof(FOLDERSGETDATA))
		return 1;

	CMStringW buf(p->Expand());
	if (data->flags & FF_UNICODE)
		wcsncpy_s(data->szPathT, data->nMaxPathSize, buf, _TRUNCATE);
	else
		strncpy_s(data->szPath, data->nMaxPathSize, _T2A(buf), _TRUNCATE);
	return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////

int InitServices()
{
	Profile_GetPathW(_countof(szCurrentProfilePath), szCurrentProfilePath);
	Profile_GetNameW(_countof(szCurrentProfile), szCurrentProfile);
	wchar_t *pos = wcsrchr(szCurrentProfile, '.'); if (pos) *pos = 0;

	GetModuleFileName(GetModuleHandleA("mir_app.mir"), szMirandaPath, _countof(szMirandaPath));
	pos = wcsrchr(szMirandaPath, '\\'); if (pos) *pos = 0;

	wchar_t *szTemp = Utils_ReplaceVarsW(L"%miranda_userdata%");
	mir_snwprintf(szUserDataPath, szTemp);
	mir_free(szTemp);

	CreateServiceFunction(MS_FOLDERS_GET_PATH, GetPathService);
	CreateServiceFunction(MS_FOLDERS_GET_SIZE, GetPathSizeService);
	CreateServiceFunction(MS_FOLDERS_REGISTER_PATH, RegisterPathService);
	return 0;
}