From 0ed4c703d7de168e5f59c84cb7d447a42e27877e Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 31 Aug 2015 20:36:18 +0000 Subject: Toaster: code cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@15131 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Toaster/src/add_to_start_menu.cpp | 65 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'plugins/Toaster/src/add_to_start_menu.cpp') 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 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 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 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 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 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()))); +} -- cgit v1.2.3