diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-08-31 20:36:18 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-08-31 20:36:18 +0000 |
commit | 0ed4c703d7de168e5f59c84cb7d447a42e27877e (patch) | |
tree | 20360ca25e42d4fd29e26ddbeeda5a46cb7a684e /plugins/Toaster | |
parent | 9f87be3ed2ddf7db63e7b5d554df84122e2b21bb (diff) |
Toaster: code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@15131 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster')
-rw-r--r-- | plugins/Toaster/src/add_to_start_menu.cpp | 65 | ||||
-rw-r--r-- | plugins/Toaster/src/add_to_start_menu.h | 12 | ||||
-rw-r--r-- | plugins/Toaster/src/main.cpp | 3 | ||||
-rw-r--r-- | plugins/Toaster/src/services.cpp | 3 | ||||
-rw-r--r-- | plugins/Toaster/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/Toaster/src/toast_notification.cpp | 44 |
6 files changed, 56 insertions, 73 deletions
diff --git a/plugins/Toaster/src/add_to_start_menu.cpp b/plugins/Toaster/src/add_to_start_menu.cpp index ac0f2ff7b2..612ac322d7 100644 --- a/plugins/Toaster/src/add_to_start_menu.cpp +++ b/plugins/Toaster/src/add_to_start_menu.cpp @@ -18,42 +18,39 @@ HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath) GetModuleFileName(NULL, exePath, MAX_PATH);
ComPtr<IShellLink> shellLink;
- HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
+ CHECKHR(CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)));
+
+ CHECKHR(shellLink->SetPath(exePath));
+
+ CHECKHR(shellLink->SetArguments(L""));
+
+ ComPtr<IPropertyStore> propertyStore;
+ CHECKHR(shellLink.As(&propertyStore));
+
+ PROPVARIANT appIdPropVar;
+ HRESULT hr = InitPropVariantFromString(AppUserModelID, &appIdPropVar);
if (SUCCEEDED(hr))
{
- hr = shellLink->SetPath(exePath);
- if (SUCCEEDED(hr))
- {
- hr = shellLink->SetArguments(L"");
- if (SUCCEEDED(hr))
- {
- ComPtr<IPropertyStore> propertyStore;
- hr = shellLink.As(&propertyStore);
- if (SUCCEEDED(hr))
- {
- PROPVARIANT appIdPropVar;
- hr = InitPropVariantFromString(AppUserModelID, &appIdPropVar);
- if (SUCCEEDED(hr))
- {
- hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar);
- if (SUCCEEDED(hr))
- {
- hr = propertyStore->Commit();
- if (SUCCEEDED(hr))
- {
- ComPtr<IPersistFile> persistFile;
- hr = shellLink.As(&persistFile);
- if (SUCCEEDED(hr))
- {
- hr = persistFile->Save(shortcutPath, TRUE);
- }
- }
- }
- PropVariantClear(&appIdPropVar);
- }
- }
- }
- }
+ CHECKHR(propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar));
+
+ CHECKHR(propertyStore->Commit());
+
+ ComPtr<IPersistFile> persistFile;
+ CHECKHR(hr = shellLink.As(&persistFile))
+
+ hr = persistFile->Save(shortcutPath, TRUE);
}
+ PropVariantClear(&appIdPropVar);
+
return hr;
}
+
+bool ShortcutExists()
+{
+ return (GetFileAttributes(ptrW(GetShortcutPath())) < 0xFFFFFFF);
+}
+
+HRESULT TryCreateShortcut()
+{
+ return (ShortcutExists() ? S_OK : InstallShortcut(ptrW(GetShortcutPath())));
+}
diff --git a/plugins/Toaster/src/add_to_start_menu.h b/plugins/Toaster/src/add_to_start_menu.h index f4bccab295..17d22ba6ad 100644 --- a/plugins/Toaster/src/add_to_start_menu.h +++ b/plugins/Toaster/src/add_to_start_menu.h @@ -1,10 +1,6 @@ -wchar_t* GetShortcutPath();
-HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath);
+#ifndef _ADD_TOSTART_MENU_H_
+#define _ADD_TOSTART_MENU_H_
-__forceinline bool ShortcutExists()
-{ return (GetFileAttributes(ptrW(GetShortcutPath())) < 0xFFFFFFF);
-}
+HRESULT TryCreateShortcut();
-__forceinline HRESULT TryCreateShortcut()
-{ return (ShortcutExists() ? S_OK : InstallShortcut(ptrW(GetShortcutPath())));
-}
\ No newline at end of file +#endif //_ADD_TOSTART_MENU_H_
\ No newline at end of file diff --git a/plugins/Toaster/src/main.cpp b/plugins/Toaster/src/main.cpp index 7307451ba8..ac60b0a8b2 100644 --- a/plugins/Toaster/src/main.cpp +++ b/plugins/Toaster/src/main.cpp @@ -70,7 +70,8 @@ extern "C" int __declspec(dllexport) Unload(void) FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION,
false,
0,
- _T("") };
+ _T("")
+ };
SHFileOperation(&file_op);
return 0;
}
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index 6cc1b7569a..80bc0c85fe 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -81,8 +81,7 @@ void __stdcall ShowToastNotification(void* p) if (ProtoServiceExists(szProto, PS_GETAVATARINFO))
{
- PROTO_AVATAR_INFORMATION pai = { 0 };
- pai.hContact = td->hContact;
+ PROTO_AVATAR_INFORMATION pai = { td->hContact };
if (CallProtoService(szProto, PS_GETAVATARINFO, 0, (LPARAM)&pai) == GAIR_SUCCESS)
{
imagePath = mir_tstrdup(pai.filename);
diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h index 34c53b55fc..86bf5bb66c 100644 --- a/plugins/Toaster/src/stdafx.h +++ b/plugins/Toaster/src/stdafx.h @@ -31,6 +31,8 @@ DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, #define MODULE "Toaster"
+#define CHECKHR(x) if (FAILED(x)) return x;
+
#include "string_reference_wrapper.h"
#include "toast_event_handler.h"
#include "toast_notification.h"
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index af89e779d1..941bacbefc 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -1,5 +1,7 @@ #include "stdafx.h"
+using namespace Microsoft::WRL;
+
ToastNotification::ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption, _In_ wchar_t* imagePath)
: _text(text), _caption(caption), _imagePath(imagePath)
{
@@ -11,24 +13,15 @@ ToastNotification::~ToastNotification() HRESULT ToastNotification::Initialize()
{
- HRESULT hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), ¬ificationManager);
- if (SUCCEEDED(hr))
- {
- hr = notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), ¬ifier);
- if (SUCCEEDED(hr))
- {
- hr = Create(¬ification);
- }
- }
- return hr;
+ CHECKHR(Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), ¬ificationManager));
+ CHECKHR(notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), ¬ifier))
+ return Create(¬ification);
}
HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXmlDocument** xml)
{
- Microsoft::WRL::ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
- HRESULT hr = Windows::Foundation::ActivateInstance(StringReferenceWrapper(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument).Get(), &xmlDocument);
- if (FAILED(hr))
- return hr;
+ ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
+ CHECKHR(Windows::Foundation::ActivateInstance(StringReferenceWrapper(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument).Get(), &xmlDocument));
HXML xmlToast = xmlCreateNode(L"toast", NULL, 0);
HXML xmlAudioNode = xmlAddChild(xmlToast, L"audio", NULL);
@@ -57,25 +50,20 @@ HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXml TCHAR *xtmp = xmlToString(xmlToast, NULL);
size_t xlen = mir_tstrlen(xtmp);
- hr = xmlDocument->LoadXml(StringReferenceWrapper(xtmp, xlen).Get());
- if (FAILED(hr))
- return hr;
+ CHECKHR(xmlDocument->LoadXml(StringReferenceWrapper(xtmp, xlen).Get()));
return xmlDocument.CopyTo(xml);
}
HRESULT ToastNotification::Create(_Outptr_ ABI::Windows::UI::Notifications::IToastNotification** _notification)
{
- Microsoft::WRL::ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocument> xml;
- HRESULT hr = CreateXml(&xml);
- if (FAILED(hr))
- return hr;
-
- Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> factory;
- hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &factory);
- if (FAILED(hr))
- return hr;
- return hr = factory->CreateToastNotification(xml.Get(), _notification);
+ ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocument> xml;
+ CHECKHR(CreateXml(&xml));
+
+ ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> factory;
+ CHECKHR(Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &factory));
+
+ return factory->CreateToastNotification(xml.Get(), _notification);
}
HRESULT ToastNotification::Show()
@@ -86,7 +74,7 @@ HRESULT ToastNotification::Show() HRESULT ToastNotification::Show(_In_ ToastEventHandler* handler)
{
EventRegistrationToken activatedToken, dismissedToken, failedToken;
- Microsoft::WRL::ComPtr<ToastEventHandler> eventHandler(handler);
+ ComPtr<ToastEventHandler> eventHandler(handler);
notification->add_Activated(eventHandler.Get(), &activatedToken);
notification->add_Dismissed(eventHandler.Get(), &dismissedToken);
|