summaryrefslogtreecommitdiff
path: root/plugins/Toaster/src/main.cpp
blob: af76da6955cf0789861b94de911369c4fc0703e7 (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
#include "stdafx.h"

int hLangpack;

HINSTANCE g_hInstance;

PLUGININFOEX pluginInfo =
{
	sizeof(PLUGININFOEX),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__AUTHOREMAIL,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	// {1FDBD8F0-3929-41BC-92D1-020779460769}
	{ 0x1fdbd8f0, 0x3929, 0x41bc, { 0x92, 0xd1, 0x2, 0x7, 0x79, 0x46, 0x7, 0x69 } }
};

DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
{
	g_hInstance = hInstance;
	return TRUE;
}

extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
	if (!IsWinVer8Plus())
	{
		MessageBox(NULL, TranslateT("This plugin requires Windows 8 or higher"), _T(MODULE), MB_OK | MB_ICONERROR);
		return NULL;
	}
	return &pluginInfo;
}

extern "C" int __declspec(dllexport) Load(void)
{
	mir_getLP(&pluginInfo);

	HookEvent(ME_SYSTEM_PRESHUTDOWN, &OnPreShutdown);
	InitServices();

	GetEnvironmentVariableW(L"TEMP", wszTempDir, MAX_PATH);
	wcscat_s(wszTempDir, L"\\Miranda.Toaster");

	DWORD dwAttributes = GetFileAttributes(wszTempDir);
	if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
		CreateDirectoryTreeT(wszTempDir);

	if (IsWinVer8Plus() && !IsWinVer10Plus())
	{
		if (FAILED(TryCreateShortcut()))
		{
			MessageBox(NULL, TranslateT("Failed to create shortcut"), _T(MODULE), MB_OK | MB_ICONERROR);
		}
	}

	return 0;
}

extern "C" int __declspec(dllexport) Unload(void)
{
	SHFILEOPSTRUCT file_op = {
		NULL,
		FO_DELETE,
		wszTempDir,
		_T(""),
		FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION,
		false,
		0,
		_T("")
	};
	SHFileOperation(&file_op);
	return 0;
}

int OnPreShutdown(WPARAM, LPARAM)
{
	CallFunctionAsync(&HideAllToasts, NULL);
	CleanupClasses();
	return 0;
}