diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-31 09:33:13 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-31 09:33:13 +0000 |
commit | c4e939d79b82b195604e48e8d1b794da4c42347f (patch) | |
tree | 7e733724ae420fab0d8bb485734f605b0f878456 | |
parent | 9331a9d035bb1b2f9e08ef9141acad1e180fb70b (diff) |
Toaster: crash fixes, popup icons support
git-svn-id: http://svn.miranda-ng.org/main/trunk@15126 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/Toaster/src/main.cpp | 17 | ||||
-rw-r--r-- | plugins/Toaster/src/services.cpp | 43 | ||||
-rw-r--r-- | plugins/Toaster/src/stdafx.h | 9 |
3 files changed, 53 insertions, 16 deletions
diff --git a/plugins/Toaster/src/main.cpp b/plugins/Toaster/src/main.cpp index 004cec4734..7307451ba8 100644 --- a/plugins/Toaster/src/main.cpp +++ b/plugins/Toaster/src/main.cpp @@ -42,6 +42,13 @@ extern "C" int __declspec(dllexport) Load(void) 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()))
@@ -55,6 +62,16 @@ extern "C" int __declspec(dllexport) Load(void) 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;
}
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index c5eaf84f6a..6cc1b7569a 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -2,17 +2,16 @@ mir_cs csNotifications;
OBJLIST<ToastNotification> lstNotifications(1);
+wchar_t wszTempDir[MAX_PATH];
__forceinline bool isChatRoom(MCONTACT hContact)
{ return (db_get_b(hContact, GetContactProto(hContact), "ChatRoom", 0) == 1);
}
-wchar_t* SaveBitmap(HBITMAP bmp, const char *szProto)
+wchar_t* SaveBitmap(HBITMAP bmp, const char *szId)
{
- wchar_t wszSavePath[MAX_PATH], wszRelativePath[MAX_PATH];
- GetEnvironmentVariableW(L"TEMP", wszSavePath, MAX_PATH);
- mir_snwprintf(wszRelativePath, L"\\MirandaToaster.%s.png", _A2T(szProto));
- wcscat_s(wszSavePath, wszRelativePath);
+ wchar_t wszSavePath[MAX_PATH];
+ mir_snwprintf(wszSavePath, L"%s\\MirandaToaster.%s.png", wszTempDir, _A2T(szId));
if (!(GetFileAttributes(wszSavePath) < 0xFFFFFFF))
{
@@ -27,14 +26,13 @@ wchar_t* SaveBitmap(HBITMAP bmp, const char *szProto) return mir_wstrdup(wszSavePath);
}
-wchar_t* ProtoIcon(const char *szProto)
+wchar_t* SaveHIcon(HICON hIcon, const char *szId)
{
- HICON hIcon = Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1);
wchar_t *wszResult = NULL;
ICONINFO icon;
if (GetIconInfo(hIcon, &icon))
{
- wszResult = SaveBitmap(icon.hbmColor, szProto);
+ wszResult = SaveBitmap(icon.hbmColor, szId);
DeleteObject(icon.hbmMask);
DeleteObject(icon.hbmColor);
@@ -42,6 +40,10 @@ wchar_t* ProtoIcon(const char *szProto) return wszResult;
}
+__forceinline wchar_t* ProtoIcon(const char *szProto)
+{ return SaveHIcon(Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1), szProto);
+}
+
static void __cdecl OnToastNotificationClicked(void* arg)
{
callbackArg *cb = (callbackArg*)arg;
@@ -72,7 +74,7 @@ void __stdcall ShowToastNotification(void* p) ptrT imagePath;
callbackArg *arg = (callbackArg*)mir_calloc(sizeof(callbackArg));
- if (td->hContact)
+ if (td->hContact != NULL && td->hContact != INVALID_CONTACT_ID)
{
arg->hContact = td->hContact;
const char* szProto = GetContactProto(td->hContact);
@@ -85,14 +87,25 @@ void __stdcall ShowToastNotification(void* p) {
imagePath = mir_tstrdup(pai.filename);
}
- else
+ }
+
+ if (imagePath == NULL)
+ {
+ if (szProto)
{
imagePath = ProtoIcon(szProto);
}
+ else if (td->hIcon)
+ {
+ imagePath = SaveHIcon(td->hIcon, CMStringA(FORMAT, "%p", td->hIcon));
+ }
}
- else
+ }
+ else
+ {
+ if (td->hIcon)
{
- imagePath = ProtoIcon(szProto);
+ imagePath = SaveHIcon(td->hIcon, CMStringA(FORMAT, "%p", td->hIcon));
}
}
@@ -116,7 +129,7 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) ptrW text(mir_a2u(ppd->lpzText));
ptrW contactName(mir_a2u(ppd->lpzContactName));
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, contactName, text));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, contactName, text, ppd->lchIcon));
return 0;
}
@@ -124,7 +137,7 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) static INT_PTR CreatePopupW(WPARAM wParam, LPARAM)
{
POPUPDATAW *ppd = (POPUPDATAW*)wParam;
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, ppd->lpwzContactName, ppd->lpwzText));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, ppd->lpwzContactName, ppd->lpwzText, ppd->lchIcon));
return 0;
}
@@ -144,7 +157,7 @@ static INT_PTR CreatePopup2(WPARAM wParam, LPARAM) title = mir_a2u(ppd->lpzTitle);
}
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, title, text));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, title, text, ppd->lchIcon));
return 0;
}
diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h index 3fce653263..d470f9f43d 100644 --- a/plugins/Toaster/src/stdafx.h +++ b/plugins/Toaster/src/stdafx.h @@ -38,6 +38,7 @@ DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, extern HINSTANCE g_hInstance;
extern mir_cs csNotifications;
extern OBJLIST<ToastNotification> lstNotifications;
+extern wchar_t wszTempDir[MAX_PATH];
struct callbackArg
{
@@ -50,8 +51,14 @@ struct ToastData MCONTACT hContact;
TCHAR *tszTitle;
TCHAR *tszText;
+ HICON hIcon;
- ToastData(MCONTACT _hContact, TCHAR *_tszTitle, TCHAR *_tszText) : hContact(_hContact), tszTitle(_tszTitle), tszText(_tszText) {}
+ ToastData(MCONTACT _hContact, TCHAR *_tszTitle, TCHAR *_tszText, HICON _hIcon = NULL) : hContact(_hContact), tszTitle(mir_tstrdup(_tszTitle)), tszText(mir_tstrdup(_tszText)), hIcon(_hIcon) {}
+ ~ToastData()
+ {
+ mir_free(tszTitle);
+ mir_free(tszText);
+ }
};
void InitServices();
|