diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-28 12:26:33 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-28 12:26:33 +0000 |
commit | 6cb1dfba3bb45c385801e85dd1486eae804cb78c (patch) | |
tree | 80974b94fdcd053cd32cba9ab686445b170f1013 /plugins/AddToStartMenu | |
parent | d87f9ff6f923ae344ffe00465e97e71a001de2df (diff) |
dont show menu item if shortcut installed
git-svn-id: http://svn.miranda-ng.org/main/trunk@15055 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AddToStartMenu')
-rw-r--r-- | plugins/AddToStartMenu/src/main.cpp | 62 | ||||
-rw-r--r-- | plugins/AddToStartMenu/src/stdafx.h | 2 |
2 files changed, 37 insertions, 27 deletions
diff --git a/plugins/AddToStartMenu/src/main.cpp b/plugins/AddToStartMenu/src/main.cpp index 66f2b8e30e..a906b7e831 100644 --- a/plugins/AddToStartMenu/src/main.cpp +++ b/plugins/AddToStartMenu/src/main.cpp @@ -37,13 +37,16 @@ extern "C" int __declspec(dllexport) Load(void) mir_getLP(&pluginInfo);
CreateServiceFunction(MODULENAME "/Add", Service);
-
- CMenuItem mi;
- mi.position = -0x7FFFFFFF;
- //mi.hIcolibItem = icon.hIcolib;
- mi.name.a = LPGEN("Add to start menu");
- mi.pszService = MODULENAME "/Add";
- Menu_AddMainMenuItem(&mi);
+
+ if (!ShortcutExists())
+ {
+ CMenuItem mi;
+ mi.position = -0x7FFFFFFF;
+ //mi.hIcolibItem = icon.hIcolib;
+ mi.name.a = LPGEN("Add to start menu");
+ mi.pszService = MODULENAME "/Add";
+ Menu_AddMainMenuItem(&mi);
+ }
return 0;
}
@@ -58,34 +61,39 @@ INT_PTR Service(WPARAM, LPARAM) return (INT_PTR)TryCreateShortcut();
}
-HRESULT TryCreateShortcut()
+wchar_t* GetShortcutPath()
{
wchar_t shortcutPath[MAX_PATH];
- DWORD charWritten = GetEnvironmentVariable(L"APPDATA", shortcutPath, MAX_PATH);
- HRESULT hr = charWritten > 0 ? S_OK : E_INVALIDARG;
+ GetEnvironmentVariable(_T("APPDATA"), shortcutPath, MAX_PATH);
+ wcscat_s(shortcutPath, ARRAYSIZE(shortcutPath), L"\\Microsoft\\Windows\\Start Menu\\Programs\\Miranda NG.lnk");
- if (SUCCEEDED(hr))
- {
- errno_t concatError = wcscat_s(shortcutPath, ARRAYSIZE(shortcutPath), L"\\Microsoft\\Windows\\Start Menu\\Programs\\Miranda NG.lnk");
- hr = concatError == 0 ? S_OK : E_INVALIDARG;
- if (SUCCEEDED(hr))
- {
- DWORD attributes = GetFileAttributes(shortcutPath);
- bool fileExists = attributes < 0xFFFFFFF;
+ return mir_wstrdup(shortcutPath);
+}
- if (!fileExists)
- {
- hr = InstallShortcut(shortcutPath);
- }
- else
- {
- hr = S_FALSE;
- }
- }
+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_FALSE;
+}
+
HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath)
{
wchar_t exePath[MAX_PATH];
diff --git a/plugins/AddToStartMenu/src/stdafx.h b/plugins/AddToStartMenu/src/stdafx.h index 99a26d1bac..6992f1f40c 100644 --- a/plugins/AddToStartMenu/src/stdafx.h +++ b/plugins/AddToStartMenu/src/stdafx.h @@ -36,5 +36,7 @@ extern HINSTANCE g_hInst; INT_PTR Service(WPARAM, LPARAM);
+HRESULT ShortcutExists();
+wchar_t* GetShortcutPath();
HRESULT TryCreateShortcut();
HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath);
|