From 6cb1dfba3bb45c385801e85dd1486eae804cb78c Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Fri, 28 Aug 2015 12:26:33 +0000 Subject: dont show menu item if shortcut installed git-svn-id: http://svn.miranda-ng.org/main/trunk@15055 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AddToStartMenu/src/main.cpp | 62 +++++++++++++++++++++---------------- plugins/AddToStartMenu/src/stdafx.h | 2 ++ 2 files changed, 37 insertions(+), 27 deletions(-) (limited to 'plugins/AddToStartMenu/src') 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); -- cgit v1.2.3