diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-12-29 19:59:31 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-12-29 19:59:31 +0000 |
commit | 544fb33475eb7ea1735f9e19f78dcf3c5e1ceb66 (patch) | |
tree | 9bcf88888f81aeb7e17ad20d9e7fd6fefa684725 /plugins/Toaster/src/utils.cpp | |
parent | 99034f294331209fbfa1d5efacf7fb25f88e227d (diff) |
Toaster: memleaks fix, code clenup
git-svn-id: http://svn.miranda-ng.org/main/trunk@15967 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster/src/utils.cpp')
-rw-r--r-- | plugins/Toaster/src/utils.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/Toaster/src/utils.cpp b/plugins/Toaster/src/utils.cpp new file mode 100644 index 0000000000..86062d2f4a --- /dev/null +++ b/plugins/Toaster/src/utils.cpp @@ -0,0 +1,61 @@ +#include "stdafx.h"
+
+#define SHORTCUT_PATH "\\Microsoft\\Windows\\Start Menu\\Programs\\Miranda NG.lnk"
+
+using namespace Microsoft::WRL;
+
+wchar_t* GetShortcutPath()
+{
+ wchar_t path[MAX_PATH];
+ GetEnvironmentVariable(_T("APPDATA"), path, MAX_PATH);
+ wcscat_s(path, _T(SHORTCUT_PATH));
+ return mir_wstrdup(path);
+}
+
+HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath)
+{
+ wchar_t exePath[MAX_PATH];
+ GetModuleFileName(NULL, exePath, MAX_PATH);
+
+ ComPtr<IShellLink> 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 = 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);
+ }
+ return hr;
+}
+
+bool ShortcutExists()
+{
+ return (GetFileAttributes(ptrW(GetShortcutPath())) < 0xFFFFFFF);
+}
+
+HRESULT TryCreateShortcut()
+{
+ return (ShortcutExists() ? S_OK : InstallShortcut(ptrW(GetShortcutPath())));
+}
|