diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-29 09:34:57 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-29 09:34:57 +0000 |
commit | d6506dc95d0f6750033b93981b2e767117585fb4 (patch) | |
tree | 2d39a07d378ea60c566f1817249769a4c6a8126b /plugins | |
parent | 0d29af86c3cf8a56f21e50cb94f12e62bf9b69e4 (diff) |
forgotten file
git-svn-id: http://svn.miranda-ng.org/main/trunk@15085 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Toaster/src/add_to_start_menu.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/Toaster/src/add_to_start_menu.cpp b/plugins/Toaster/src/add_to_start_menu.cpp new file mode 100644 index 0000000000..ae2d1e7131 --- /dev/null +++ b/plugins/Toaster/src/add_to_start_menu.cpp @@ -0,0 +1,82 @@ +#include "stdafx.h"
+
+using namespace Microsoft::WRL;
+
+wchar_t* GetShortcutPath()
+{
+ wchar_t shortcutPath[MAX_PATH];
+ GetEnvironmentVariable(_T("APPDATA"), shortcutPath, MAX_PATH);
+ wcscat_s(shortcutPath, ARRAYSIZE(shortcutPath), L"\\Microsoft\\Windows\\Start Menu\\Programs\\Miranda NG.lnk");
+
+ return mir_wstrdup(shortcutPath);
+}
+
+HRESULT ShortcutExists()
+{
+ HRESULT hr;
+ DWORD attributes = GetFileAttributes(ptrW(GetShortcutPath()));
+ bool fileExists = attributes < 0xFFFFFFF;
+
+ if (!fileExists)
+ {
+ hr = S_OK;
+ }
+ else
+ {
+ hr = S_FALSE;
+ }
+ return hr;
+}
+
+HRESULT TryCreateShortcut()
+{
+ if (!ShortcutExists())
+ return InstallShortcut(ptrW(GetShortcutPath()));
+ return S_OK;
+}
+
+HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath)
+{
+ wchar_t exePath[MAX_PATH];
+ GetModuleFileName(NULL, exePath, MAX_PATH);
+
+ ComPtr<IShellLink> shellLink;
+ HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
+ 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);
+ }
+ }
+ }
+ }
+ }
+ return hr;
+}
|