Backed out 3 changesets (bug 1883476, bug 1826375) for causing windows build bustages...
[gecko.git] / third_party / WinToast / moz-check-system-shortcut.patch
blob84411ae7bc1bc5b58cc4e3110433bd2ee2de7863
1 diff --git a/src/wintoastlib.cpp b/src/wintoastlib.cpp
2 index 0895ff7..ac8d5cf 100644
3 --- a/src/wintoastlib.cpp
4 +++ b/src/wintoastlib.cpp
5 @@ -213,8 +213,8 @@ namespace Util {
9 - inline HRESULT defaultShellLinksDirectory(_In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
10 - DWORD written = GetEnvironmentVariableW(L"APPDATA", path, nSize);
11 + inline HRESULT commonShellLinksDirectory(_In_ const WCHAR* baseEnv, _In_ WCHAR* path, _In_ DWORD nSize) {
12 + DWORD written = GetEnvironmentVariableW(baseEnv, path, nSize);
13 HRESULT hr = written > 0 ? S_OK : E_INVALIDARG;
14 if (SUCCEEDED(hr)) {
15 errno_t result = wcscat_s(path, nSize, DEFAULT_SHELL_LINKS_PATH);
16 @@ -224,8 +224,8 @@ namespace Util {
17 return hr;
20 - inline HRESULT defaultShellLinkPath(const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
21 - HRESULT hr = defaultShellLinksDirectory(path, nSize);
22 + inline HRESULT commonShellLinkPath(_In_ const WCHAR* baseEnv, const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize) {
23 + HRESULT hr = commonShellLinksDirectory(baseEnv, path, nSize);
24 if (SUCCEEDED(hr)) {
25 const std::wstring appLink(appname + DEFAULT_LINK_FORMAT);
26 errno_t result = wcscat_s(path, nSize, appLink.c_str());
27 @@ -235,6 +235,13 @@ namespace Util {
28 return hr;
31 + inline HRESULT defaultUserShellLinkPath(const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
32 + return commonShellLinkPath(L"APPDATA", appname, path, nSize);
33 + }
35 + inline HRESULT defaultSystemShellLinkPath(const std::wstring& appname, _In_ WCHAR* path, _In_ DWORD nSize = MAX_PATH) {
36 + return commonShellLinkPath(L"PROGRAMDATA", appname, path, nSize);
37 + }
39 inline PCWSTR AsString(ComPtr<IXmlDocument> &xmlDocument) {
40 HSTRING xml;
41 @@ -523,12 +530,19 @@ const std::wstring& WinToast::appUserModelId() const {
43 HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
44 WCHAR path[MAX_PATH] = { L'\0' };
45 - Util::defaultShellLinkPath(_appName, path);
46 + Util::defaultUserShellLinkPath(_appName, path);
47 // Check if the file exist
48 DWORD attr = GetFileAttributesW(path);
49 if (attr >= 0xFFFFFFF) {
50 - DEBUG_MSG("Error, shell link not found. Try to create a new one in: " << path);
51 - return E_FAIL;
52 + // The shortcut may be in the system Start Menu.
53 + WCHAR systemPath[MAX_PATH] = { L'\0' };
54 + Util::defaultSystemShellLinkPath(_appName, systemPath);
55 + attr = GetFileAttributesW(systemPath);
56 + if (attr >= 0xFFFFFFF) {
57 + DEBUG_MSG("Error, shell link not found. Try to create a new one in: " << path);
58 + return E_FAIL;
59 + }
60 + wcscpy(path, systemPath);
63 // Let's load the file as shell link to validate.
64 @@ -543,7 +557,7 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
65 ComPtr<IPersistFile> persistFile;
66 hr = shellLink.As(&persistFile);
67 if (SUCCEEDED(hr)) {
68 - hr = persistFile->Load(path, STGM_READWRITE);
69 + hr = persistFile->Load(path, STGM_READ);
70 if (SUCCEEDED(hr)) {
71 ComPtr<IPropertyStore> propertyStore;
72 hr = shellLink.As(&propertyStore);
73 @@ -583,7 +597,7 @@ HRESULT WinToast::validateShellLinkHelper(_Out_ bool& wasChanged) {
74 HRESULT WinToast::createShellLinkHelper() {
75 WCHAR exePath[MAX_PATH]{L'\0'};
76 WCHAR slPath[MAX_PATH]{L'\0'};
77 - Util::defaultShellLinkPath(_appName, slPath);
78 + Util::defaultUserShellLinkPath(_appName, slPath);
79 Util::defaultExecutablePath(exePath);
80 ComPtr<IShellLinkW> shellLink;
81 HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));