blob: 9751dcb13fd10320e2fe29bd7028f3a1e96f15fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include "stdafx.h"
using namespace Microsoft::WRL;
wchar_t* GetShortcutPath()
{
wchar_t path[MAX_PATH];
SHGetSpecialFolderPathW(nullptr, path, CSIDL_STARTMENU, FALSE);
wcscat_s(path, L"\\Programs\\Miranda NG.lnk");
return mir_wstrdup(path);
}
HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath)
{
wchar_t exePath[MAX_PATH];
GetModuleFileName(nullptr, 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())));
}
|