summaryrefslogtreecommitdiff
path: root/plugins/UserGuide/main.cpp
blob: 908c99e09b404847d4a71264bd5f1a849b170f49 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "commonheaders.h"

struct MM_INTERFACE mmi;
HINSTANCE hInst;
PLUGINLINK *pluginLink;
HANDLE hModulesLoaded, hShowGuide;
int hLangpack;

PLUGININFOEX pluginInfo={
	sizeof(PLUGININFOEX),
	"User Guide Plugin",
	PLUGIN_MAKE_VERSION(0,0,0,1),
	"This plug-in adds the main menu item used to view miranda-im pack user guide.",
	"Yasnovidyashii",
	"yasnovidyashii@gmail.com",
	"© 2009 Mikhail Yuriev",
	"http://miranda-im.org/",
	UNICODE_AWARE,		//not transient
	0,		//doesn't replace anything built-in
    // Generate your own unique id for your plugin.
    // Do not use this UUID!
    // Use uuidgen.exe to generate the uuuid
    MIID_USERGUIDE
};

static INT_PTR ShowGuideFile(WPARAM wParam,LPARAM lParam)
{
	DBVARIANT dbv = {0};
	int iRes;

	LPCTSTR pszEmptySting = _T("");
	LPTSTR pszDirName, pszDirNameEx, pszFileName,pszDivider;

	REPLACEVARSDATA dat = {0};
	dat.cbSize = sizeof( dat );
	dat.dwFlags = RVF_TCHAR;
	
	pszDirName = (LPTSTR)mir_alloc(250*sizeof(TCHAR));
	pszFileName = (LPTSTR)mir_alloc(250*sizeof(TCHAR));

	iRes = DBGetContactSettingTString(NULL, "UserGuide", "PathToHelpFile", &dbv);
	
	if (iRes!=0)
	{
			_tcscpy(pszDirName, _T("%miranda_path%\\Plugins"));
			_tcscpy(pszFileName, _T("UserGuide.chm"));			
	}
	else
	{
		if(!_tcscmp((dbv.ptszVal), pszEmptySting))
		{
			_tcscpy(pszDirName, _T("%miranda_path%\\Plugins"));
			_tcscpy(pszFileName, _T("UserGuide.chm"));
		}
		else 
		{
			pszDivider = _tcsrchr(dbv.ptszVal, '\\');
			if (pszDivider == NULL)
			{	
				pszDirName = _T("");
				_tcsncpy(pszFileName, dbv.ptszVal, _tcslen(dbv.ptszVal));
			}
			else
			{
				_tcsncpy(pszFileName, pszDivider + 1, _tcslen(dbv.ptszVal) - _tcslen(pszDivider) - 1);
				pszFileName[_tcslen(dbv.ptszVal) - _tcslen(pszDivider) - 1] = 0;
				_tcsncpy(pszDirName, dbv.ptszVal, pszDivider - dbv.ptszVal);
				pszDirName[pszDivider - dbv.ptszVal] = 0;
			}
		}
		DBFreeVariant(&dbv);
	}
	if (ServiceExists(MS_UTILS_REPLACEVARS))
		pszDirNameEx = (TCHAR *) CallService(MS_UTILS_REPLACEVARS, (WPARAM)pszDirName, (LPARAM)&dat);
	else
		pszDirNameEx = mir_tstrdup(pszDirName);

	ShellExecute(NULL, _T("open"), pszFileName, NULL, pszDirNameEx, SW_SHOW);
	mir_free(pszDirName);
	mir_free(pszFileName);
	mir_free(pszDirNameEx);
	return 0;
}

int ModulesLoaded(WPARAM wParam,LPARAM lParam)
{
	CLISTMENUITEM mi;

	hShowGuide = CreateServiceFunction("UserGuide/ShowGuide", ShowGuideFile);
	ZeroMemory(&mi, sizeof(mi));
	mi.cbSize = sizeof(mi);
	mi.position = 500000;
	mi.flags = CMIF_TCHAR;
	mi.hIcon = LoadSkinnedIcon(SKINICON_OTHER_HELP);
	mi.ptszName = LPGENT("User Guide");
	mi.pszService = "UserGuide/ShowGuide";
	Menu_AddMainMenuItem(&mi);
	
	return 0;
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
	hInst = hinstDLL;
	return TRUE;
}


extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
	return &pluginInfo;
}

extern "C" __declspec(dllexport) int Load(PLUGINLINK *link)
{
	pluginLink = link;
	mir_getMMI(&mmi);
	mir_getLP(&pluginInfo);
	hModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED,ModulesLoaded);
	return 0;
}

extern "C" __declspec(dllexport) int Unload(void)
{
	UnhookEvent(hModulesLoaded);
	DestroyServiceFunction(hShowGuide);
	return 0;
}