22 SnoreToast is capable to invoke Windows 8 toast notifications.
33 Copyright (C) 2013 Patrick von Reth <vonreth@kde.org>
44
5-
65 SnoreToast is free software: you can redistribute it and/or modify
76 it under the terms of the GNU Lesser General Public License as published by
87 the Free Software Foundation, either version 3 of the License, or
2524
2625using namespace Microsoft ::WRL;
2726
28-
29-
30- HRESULT LinkHelper::tryCreateShortcut (const std::wstring &shortcutPath,const std::wstring &exePath, const std::wstring &appID)
27+ HRESULT LinkHelper::tryCreateShortcut (const std::wstring &shortcutPath, const std::wstring &exePath, const std::wstring &appID)
3128{
3229 HRESULT hr = S_OK;
3330
3431 std::wstringstream path;
3532 std::wstring lnkName;
3633 wchar_t buffer[MAX_PATH];
3734
38- if (GetEnvironmentVariable (L" APPDATA" ,buffer , MAX_PATH)>0 )
39- {
35+ if (GetEnvironmentVariable (L" APPDATA" , buffer , MAX_PATH) > 0 ) {
4036 path << buffer
41- << L" \\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ " ;
37+ << L" \\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ " ;
4238
4339 }
4440
4541 lnkName = shortcutPath;
4642
47- if (shortcutPath.rfind (L" .lnk" ) == std::wstring::npos)
48- {
43+ if (shortcutPath.rfind (L" .lnk" ) == std::wstring::npos) {
4944 lnkName.append (L" .lnk" );
5045 }
51- hr = mkdirs (path.str (),lnkName);
52- if (SUCCEEDED (hr))
53- {
46+ hr = mkdirs (path.str (), lnkName);
47+ if (SUCCEEDED (hr)) {
5448 path << lnkName;
5549
5650 DWORD attributes = GetFileAttributes (path.str ().c_str ());
5751 bool fileExists = attributes < 0xFFFFFFF ;
5852
59- if (!fileExists)
60- {
61- hr = installShortcut (path.str (),exePath,appID);
62- }
63- else
64- {
53+ if (!fileExists) {
54+ hr = installShortcut (path.str (), exePath, appID);
55+ } else {
6556 hr = S_FALSE;
6657 }
6758 }
@@ -71,54 +62,41 @@ HRESULT LinkHelper::tryCreateShortcut(const std::wstring &shortcutPath,const std
7162HRESULT LinkHelper::tryCreateShortcut (const std::wstring &appID)
7263{
7364 wchar_t buffer[MAX_PATH];
74- if (GetModuleFileNameEx (GetCurrentProcess (), nullptr , buffer,MAX_PATH)>0 )
75- {
76- return tryCreateShortcut (L" SnoreToast.lnk" ,buffer,appID);
65+ if (GetModuleFileNameEx (GetCurrentProcess (), nullptr , buffer, MAX_PATH) > 0 ) {
66+ return tryCreateShortcut (L" SnoreToast.lnk" , buffer, appID);
7767 }
7868 return E_FAIL;
7969}
8070
81-
82-
83-
8471// Install the shortcut
85- HRESULT LinkHelper::installShortcut (const std::wstring &shortcutPath,const std::wstring &exePath, const std::wstring &appID)
72+ HRESULT LinkHelper::installShortcut (const std::wstring &shortcutPath, const std::wstring &exePath, const std::wstring &appID)
8673{
8774 std::wcout << L" Installing shortcut: " << shortcutPath << L" " << exePath << L" " << appID << std::endl;
8875 HRESULT hr = S_OK;
8976
90- if (SUCCEEDED (hr))
91- {
77+ if (SUCCEEDED (hr)) {
9278 ComPtr<IShellLink> shellLink;
9379 hr = CoCreateInstance (CLSID_ShellLink, nullptr , CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&shellLink));
9480
95- if (SUCCEEDED (hr))
96- {
81+ if (SUCCEEDED (hr)) {
9782 hr = shellLink->SetPath (exePath.c_str ());
98- if (SUCCEEDED (hr))
99- {
83+ if (SUCCEEDED (hr)) {
10084 hr = shellLink->SetArguments (L" " );
101- if (SUCCEEDED (hr))
102- {
85+ if (SUCCEEDED (hr)) {
10386 ComPtr<IPropertyStore> propertyStore;
10487
10588 hr = shellLink.As (&propertyStore);
106- if (SUCCEEDED (hr))
107- {
89+ if (SUCCEEDED (hr)) {
10890 PROPVARIANT appIdPropVar;
10991 hr = InitPropVariantFromString (appID.c_str (), &appIdPropVar);
110- if (SUCCEEDED (hr))
111- {
92+ if (SUCCEEDED (hr)) {
11293 hr = propertyStore->SetValue (PKEY_AppUserModel_ID, appIdPropVar);
113- if (SUCCEEDED (hr))
114- {
94+ if (SUCCEEDED (hr)) {
11595 hr = propertyStore->Commit ();
116- if (SUCCEEDED (hr))
117- {
96+ if (SUCCEEDED (hr)) {
11897 ComPtr<IPersistFile> persistFile;
11998 hr = shellLink.As (&persistFile);
120- if (SUCCEEDED (hr))
121- {
99+ if (SUCCEEDED (hr)) {
122100 hr = persistFile->Save (shortcutPath.c_str (), TRUE );
123101 }
124102 }
@@ -133,23 +111,20 @@ HRESULT LinkHelper::installShortcut(const std::wstring &shortcutPath,const std::
133111 return hr;
134112}
135113
136- HRESULT LinkHelper::mkdirs (const std::wstring &basepath,const std::wstring &dirs)
114+ HRESULT LinkHelper::mkdirs (const std::wstring &basepath, const std::wstring &dirs)
137115{
138116 HRESULT hr = S_OK;
139117 size_t pos;
140118 size_t oldPos = 0 ;
141119 size_t last_pos = dirs.rfind (L" \\ " );
142- if (last_pos == std::wstring::npos)
143- {
120+ if (last_pos == std::wstring::npos) {
144121 return hr;
145122 }
146- while (SUCCEEDED (hr) && (pos = dirs.find (L" \\ " ,oldPos)) <= last_pos)
147- {
148- hr = _wmkdir ((basepath + dirs.substr (0 ,pos)).c_str ()) != ENOENT?S_OK:E_FAIL;
149- if (oldPos == pos)
150- {
151- break ;
152- }
123+ while (SUCCEEDED (hr) && (pos = dirs.find (L" \\ " , oldPos)) <= last_pos) {
124+ hr = _wmkdir ((basepath + dirs.substr (0 , pos)).c_str ()) != ENOENT ? S_OK : E_FAIL;
125+ if (oldPos == pos) {
126+ break ;
127+ }
153128 oldPos = pos;
154129 }
155130 return hr;
0 commit comments