Author: mlytwyn
Date: Thu May 26 18:37:08 2016
New Revision: 39811
URL: http://svn.gna.org/viewcvs/gnustep?rev=39811&view=rev
Log:
Fix test code from last checkin - additional cleanup - added creating
shortcut/reg code
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/Debug/ToastNotifications.dll
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/Release/ToastNotifications.dll
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastEventHandler.cpp
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.cpp
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.h
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj.filters
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/stdafx.cpp
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/Debug/ToastNotifications.dll
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/Debug/ToastNotifications.dll?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
Binary files - no diff available.
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/Release/ToastNotifications.dll
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/Release/ToastNotifications.dll?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
Binary files - no diff available.
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastEventHandler.cpp
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastEventHandler.cpp?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
---
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastEventHandler.cpp
(original)
+++
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastEventHandler.cpp
Thu May 26 18:37:08 2016
@@ -58,8 +58,6 @@
}
// Cleanup...
- delete sender;
- delete this;
return hr;
}
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.cpp
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.cpp?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
---
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.cpp
(original)
+++
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.cpp
Thu May 26 18:37:08 2016
@@ -17,7 +17,6 @@
#include <locale>
#include <codecvt>
#include <string>
-//#include <wchar.h>
using namespace Microsoft::WRL;
using namespace ABI::Windows::UI::Notifications;
@@ -84,11 +83,106 @@
return TRUE;
}
+// In order to display toasts, a desktop application must have a shortcut on
the Start menu.
+// Also, an AppUserModelID must be set on that shortcut.
+// The shortcut should be created as part of the installer. The following code
shows how to create
+// a shortcut and assign an AppUserModelID using Windows APIs. You must
download and include the
+// Windows API Code Pack for Microsoft .NET Framework for this code to function
+//
+// Included in this project is a wxs file that be used with the WiX toolkit
+// to make an installer that creates the necessary shortcut. One or the other
should be used.
+
+HRESULT CToastNotificationsApp::TryCreateShortcut()
+{
+ wchar_t shortcutPath[MAX_PATH];
+ DWORD charWritten = GetEnvironmentVariable(L"APPDATA", shortcutPath,
MAX_PATH);
+ HRESULT hr = charWritten > 0 ? S_OK : E_INVALIDARG;
+ dll_logw(shortcutPath);
+
+ if (SUCCEEDED(hr))
+ {
+ errno_t concatError = wcscat_s(shortcutPath, ARRAYSIZE(shortcutPath),
L"\\Microsoft\\Windows\\Start Menu\\Programs\\ToastNotifications.lnk");
+ hr = concatError == 0 ? S_OK : E_INVALIDARG;
+ if (SUCCEEDED(hr))
+ {
+ DWORD attributes = GetFileAttributes(shortcutPath);
+ bool fileExists = attributes < 0xFFFFFFF;
+
+ if (!fileExists)
+ {
+ hr = InstallShortcut(shortcutPath);
+ }
+ else
+ {
+ hr = S_FALSE;
+ }
+ }
+ }
+ return hr;
+}
+
+// Install the shortcut
+HRESULT CToastNotificationsApp::InstallShortcut(_In_z_ wchar_t *shortcutPath)
+{
+ dll_logw(shortcutPath);
+ wchar_t exePath[MAX_PATH];
+
+ DWORD charWritten = GetModuleFileNameEx(GetCurrentProcess(), nullptr,
exePath, ARRAYSIZE(exePath));
+ dll_logw(exePath);
+
+ HRESULT hr = charWritten > 0 ? S_OK : E_FAIL;
+
+ if (SUCCEEDED(hr))
+ {
+ ComPtr<IShellLink> shellLink;
+ hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&shellLink));
+
+ if (SUCCEEDED(hr))
+ {
+ hr = shellLink->SetPath(exePath);
+ if (SUCCEEDED(hr))
+ {
+ hr = shellLink->SetArguments(L"");
+ if (SUCCEEDED(hr))
+ {
+ ComPtr<IPropertyStore> propertyStore;
+
+ hr = shellLink.As(&propertyStore);
+ if (SUCCEEDED(hr))
+ {
+ PROPVARIANT appIdPropVar;
+ hr = InitPropVariantFromString(AppId, &appIdPropVar);
+ if (SUCCEEDED(hr))
+ {
+ hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar);
+ dll_log("propertyStore result: %d", hr);
+ 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;
+}
// Create the toast XML from a template
HRESULT CToastNotificationsApp::CreateToastXml(_In_
IToastNotificationManagerStatics *toastManager, _Outptr_ IXmlDocument**
inputXml, wchar_t* notificationTitle, wchar_t* notificationDescription,
wchar_t* imagePath)
{
- dll_dlog("note title: %s info %s imagePath: %s", notificationTitle,
notificationDescription, imagePath);
+ dll_dlogw(L"note title: %s info %s imagePath: %s", notificationTitle,
notificationDescription, imagePath);
HRESULT hr =
toastManager->GetTemplateContent(ToastTemplateType_ToastImageAndText04,
inputXml);
@@ -98,7 +192,19 @@
}
else
{
- //wchar_t *imagePath = _wfullpath(nullptr, L"toastImageAndText.png",
MAX_PATH);
+ // ONLY supporting .png files right now...
+ std::wstring filePath = imagePath;
+ if ((filePath.find_last_of(L".") == std::wstring::npos) ||
+ (filePath.substr(filePath.find_last_of(L".") + 1) != L"png"))
+ {
+ // Replace with proxy image...
+ imagePath = L"toastImageAndText.png";
+ }
+
+ // Get full path to image...
+ imagePath = _wfullpath(nullptr, imagePath, MAX_PATH);
+
+ dll_logw(TEXT("loading application image file: %s"), imagePath);
hr = imagePath != nullptr ? S_OK :
HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
if (FAILED(hr))
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.h?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
---
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.h
(original)
+++
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.h
Thu May 26 18:37:08 2016
@@ -9,7 +9,7 @@
#include "resource.h" // main symbols
-const wchar_t AppId[] = L"Testplant.Eggplant.Notifications";
+const wchar_t AppId[] = L"Testplant.Notifications.Eggplant";
@@ -57,7 +57,10 @@
_In_ ABI::Windows::Data::Xml::Dom::IXmlDocument *xml
);
-
+protected:
+ HRESULT TryCreateShortcut();
+ HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath);
+
private:
HWND _hwnd;
HWND _hEdit;
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
---
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj
(original)
+++
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj
Thu May 26 18:37:08 2016
@@ -126,6 +126,9 @@
<ItemGroup>
<ResourceCompile Include="ToastNotifications.rc" />
</ItemGroup>
+ <ItemGroup>
+ <Image Include="toastImageAndText.png" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj.filters
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj.filters?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
---
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj.filters
(original)
+++
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/ToastNotifications.vcxproj.filters
Thu May 26 18:37:08 2016
@@ -61,4 +61,9 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
+ <ItemGroup>
+ <Image Include="toastImageAndText.png">
+ <Filter>Resource Files</Filter>
+ </Image>
+ </ItemGroup>
</Project>
Modified:
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/stdafx.cpp
URL:
http://svn.gna.org/viewcvs/gnustep/libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/stdafx.cpp?rev=39811&r1=39810&r2=39811&view=diff
==============================================================================
---
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/stdafx.cpp
(original)
+++
libs/back/branches/gnustep_testplant_branch/Source/win32/MSUserNotifications/ToastNotifications/ToastNotifications/ToastNotifications/stdafx.cpp
Thu May 26 18:37:08 2016
@@ -7,7 +7,6 @@
void dll_log_s(const char *function, int line, const char *format, ...)
{
-#if defined(DEBUG)
static const size_t STRBUFSIZE = 512;
static char str[STRBUFSIZE];
va_list argptr;
@@ -16,12 +15,10 @@
vsprintf_s(&str[strlen(str)], STRBUFSIZE - strlen(str), format, argptr);
OutputDebugStringA(str);
va_end(argptr);
-#endif
}
void dll_logw_s(const wchar_t *function, int line, const wchar_t *format, ...)
{
-#if defined(DEBUG)
static const size_t STRBUFSIZE = 512;
static wchar_t wstr[STRBUFSIZE];
va_list argptr;
@@ -30,5 +27,4 @@
vswprintf_s(&wstr[_tcslen(wstr)], STRBUFSIZE - _tcslen(wstr), format,
argptr);
OutputDebugStringW(wstr);
va_end(argptr);
-#endif
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs