Update Shell

Fix Package Store Logo Read
This commit is contained in:
Bruce
2025-11-26 23:53:09 +08:00
parent a70b0547bd
commit a3b3b097b2
12 changed files with 715 additions and 442 deletions

View File

@@ -539,44 +539,63 @@ HRESULT CreateToastNoticeWithIStream (LPCWSTR lpIdName, LPCWSTR lpText, HANDLE p
}
HRESULT NoticeGetLastHResult () { return g_lasthr; }
LPCWSTR NoticeGetLastDetailMessage () { return g_lastexc.c_str (); }
HRESULT CreateShortcutWithAppIdW (LPCWSTR pszShortcutPath, LPCWSTR pszTargetPath, LPCWSTR pszAppId)
HRESULT CreateShortcutWithAppIdW (LPCWSTR pszShortcutPath, LPCWSTR pszTargetPath, LPCWSTR pszAppId, LPWSTR *lpException)
{
HRESULT hr;
if (FAILED (hr)) return hr;
IShellLinkW *pShellLinkW = nullptr;
raii reltask1 ([&] () {
if (pShellLinkW) pShellLinkW->Release ();
pShellLinkW = nullptr;
HRESULT &hr = g_lasthr;
destruct relt ([&] () {
if (FAILED (hr))
{
if (lpException && !*lpException)
{
_com_error ex (hr);
g_lastexc = ex.ErrorMessage () ? ex.ErrorMessage () : L"";
*lpException = _wcsdup (g_lastexc.c_str ());
}
}
});
hr = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void **)&pShellLinkW);
if (FAILED (hr)) return hr;
hr = pShellLinkW->SetPath (pszTargetPath); return hr;
IPropertyStore *pPropStore = nullptr;
raii reltask2 ([&] () {
if (pPropStore) pPropStore->Release ();
pPropStore = nullptr;
});
hr = pShellLinkW->QueryInterface (IID_IPropertyStore, (void **)&pPropStore);
if (SUCCEEDED (hr))
if (lpException) *lpException = nullptr;
try
{
PROPVARIANT propvar;
hr = InitPropVariantFromString (pszAppId, &propvar);
hr = CoInitialize (NULL);
if (FAILED (hr)) return hr;
IShellLinkW *pShellLinkW = nullptr;
raii reltask1 ([&] () {
if (pShellLinkW) pShellLinkW->Release ();
pShellLinkW = nullptr;
});
hr = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void **)&pShellLinkW);
if (FAILED (hr)) return hr;
hr = pShellLinkW->SetPath (pszTargetPath);
if (FAILED (hr)) return hr;
IPropertyStore *pPropStore = nullptr;
raii reltask2 ([&] () {
if (pPropStore) pPropStore->Release ();
pPropStore = nullptr;
});
hr = pShellLinkW->QueryInterface (IID_IPropertyStore, (void **)&pPropStore);
if (SUCCEEDED (hr))
{
hr = pPropStore->SetValue (PKEY_AppUserModel_ID, propvar);
if (SUCCEEDED (hr)) hr = pPropStore->Commit ();
PropVariantClear (&propvar);
PROPVARIANT propvar;
hr = InitPropVariantFromString (pszAppId, &propvar);
if (SUCCEEDED (hr))
{
hr = pPropStore->SetValue (PKEY_AppUserModel_ID, propvar);
if (SUCCEEDED (hr)) hr = pPropStore->Commit ();
PropVariantClear (&propvar);
}
}
else pPropStore = nullptr;
IPersistFile *pPersistFile = nullptr;
raii reltask3 ([&] () {
if (pPersistFile) pPersistFile->Release ();
pPersistFile = nullptr;
});
hr = pShellLinkW->QueryInterface (IID_IPersistFile, (void **)&pPersistFile);
if (SUCCEEDED (hr)) hr = pPersistFile->Save (pszShortcutPath, TRUE);
else pPersistFile = nullptr;
return hr;
}
else pPropStore = nullptr;
IPersistFile *pPersistFile = nullptr;
raii reltask3 ([&] () {
if (pPersistFile) pPersistFile->Release ();
pPersistFile = nullptr;
});
hr = pShellLinkW->QueryInterface (IID_IPersistFile, (void **)&pPersistFile);
if (SUCCEEDED (hr)) hr = pPersistFile->Save (pszShortcutPath, TRUE);
else pPersistFile = nullptr;
catch_lasterr (&hr, lpException);
return hr;
}
@@ -646,4 +665,51 @@ HRESULT CreateToastNotice2WithImgBase64 (LPCWSTR lpIdName, LPCWSTR lpTitle, LPCW
if (bytes.size ())
{ if (FAILED (BytesToIStream (bytes, &ist))) ist = nullptr; }
return CreateToastNoticeWithIStream2 (lpIdName, lpTitle, lpText, ist, pfCallback, pCustom, lpExceptMsg);
}
HRESULT CreateMessageDialog (const std::wstring &content, const std::wstring &title, LPWSTR *lpException)
{
auto &hr = g_lasthr;
try
{
auto refcon = ref new Platform::String (content.c_str ());
auto reftit = ref new Platform::String (title.c_str ());
Windows::UI::Popups::MessageDialog ^msgdlg = nullptr;
if (IsNormalizeStringEmpty (title)) msgdlg = ref new Windows::UI::Popups::MessageDialog (refcon);
else msgdlg = ref new Windows::UI::Popups::MessageDialog (refcon, reftit);
msgdlg->ShowAsync ();
return S_OK;
}
catch_lasterr (&hr, lpException);
return hr;
}
HRESULT SimpleMessageDialog (LPCWSTR lpContent, LPCWSTR lpTitle, LPWSTR *lpException)
{
auto &hr = g_lasthr;
try
{
return CreateMessageDialog (
lpContent ? lpContent : L"",
lpTitle ? lpTitle : L"",
lpException
);
}
catch_lasterr (&hr, lpException);
return hr;
}
HRESULT CreateTileNoticifation (LPCWSTR lpAppId, LPCWSTR lpXmlDoc, LPWSTR *lpExMsg)
{
auto &hr = g_lasthr;
try
{
auto refcon = ref new Platform::String (lpXmlDoc ? lpXmlDoc : L"");
auto xmldoc = ref new Windows::Data::Xml::Dom::XmlDocument ();
xmldoc->LoadXml (ref new Platform::String (lpXmlDoc ? lpXmlDoc : L""));
auto tile = ref new Windows::UI::Notifications::TileNotification (xmldoc);
auto tilemgr = Windows::UI::Notifications::TileUpdateManager::CreateTileUpdaterForApplication (ref new Platform::String (lpAppId ? lpAppId : L""));
tilemgr->Update (tile);
return S_OK;
}
catch_lasterr (&hr, lpExMsg);
return hr;
}

View File

@@ -70,7 +70,7 @@ extern "C"
NOTICE_API LPCWSTR NoticeGetLastDetailMessage ();
// 创建快捷方式
// (不用安装程序原生的创建,因为需要 AppUserID 才能使用 Toast 通知,当然这个限制只有 Windows 8.x 有Windows 10 没有这个限制了)
NOTICE_API HRESULT CreateShortcutWithAppIdW (LPCWSTR pszShortcutPath, LPCWSTR pszTargetPath, LPCWSTR pszAppId);
NOTICE_API HRESULT CreateShortcutWithAppIdW (LPCWSTR pszShortcutPath, LPCWSTR pszTargetPath, LPCWSTR pszAppId, LPWSTR *lpException);
// 由 notice.dll 获取到的动态字符串必须由此释放。
NOTICE_API void NoticeApiFreeString (LPWSTR lpstr);
// 创建一个简单的 Toast 通知。支持两段文本和一张图片(图片是 data uri 或者只是 Base64 编码后的字符串,如果不想设置则置 NULL
@@ -80,6 +80,7 @@ extern "C"
// lpText 可以设置为 NULL 或空文本。此时函数的作用与 CreateToastNoticeWithIStream 一致。
// 一些参数作用与 CreateToastNoticeFromXmlDocument 中的同名参数作用一致。
NOTICE_API HRESULT CreateToastNotice2WithImgBase64 (LPCWSTR lpIdName, LPCWSTR lpTitle, LPCWSTR lpText, LPCWSTR lpImgBase64, NOTICE_ACTIVECALLBACK pfCallback, void *pCustom, LPWSTR *lpExceptMsg);
#ifdef _DEFAULT_INIT_VALUE_
#undef _DEFAULT_INIT_VALUE_
#endif
@@ -185,7 +186,14 @@ notice::hresult CreateToastNoticeWithIStream (notice::qcwstring idname, notice::
notice::hresult CreateToastNotice (notice::qcwstring idname, notice::qcwstring xmlstring, std::function <void ()> callback) { return CreateToastNoticeFromXmlDocument (idname, xmlstring, callback); }
notice::hresult CreateToastNotice (notice::qcwstring idname, notice::qcwstring text, IStream *imgstream, std::function <void ()> callback = nullptr) { return CreateToastNoticeWithIStream (idname, text, imgstream, callback); }
notice::hresult CreateToastNotice (notice::qcwstring idname, notice::qcwstring title, notice::qcwstring text, IStream *imgstream, std::function <void ()> callback = nullptr) { return CreateToastNoticeWithIStream2 (idname, title, text, imgstream, callback); }
HRESULT CreateShortcutWithAppIdW (notice::qcwstring shortcut_path, notice::qcwstring targetpath, notice::qcwstring appid) { return CreateShortcutWithAppIdW (shortcut_path.c_str (), targetpath.c_str (), appid.c_str ()); }
notice::hresult CreateShortcutWithAppIdW (notice::qcwstring shortcut_path, notice::qcwstring targetpath, notice::qcwstring appid)
{
notice::autostr exp;
notice::hresult hr;
hr.hr = CreateShortcutWithAppIdW (shortcut_path.c_str (), targetpath.c_str (), appid.c_str (), &exp.lpstr);
hr.message = exp.get_string ();
return hr;
}
HRESULT CreateToastNoticeWithImgBase64 (notice::qcwstring idname, notice::qcwstring text, notice::qcwstring imgbase64, std::function <void ()> callback = nullptr)
{
notice::autostr exp;
@@ -202,4 +210,6 @@ HRESULT CreateToastNotice2WithImgBase64 (notice::qcwstring idname, notice::qcwst
hr.message = exp.get_string ();
return hr;
}
// WinRT API 测试用
#endif

View File

@@ -53,7 +53,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalOptions>/ZW:nostdlib /FUplatform.winmd /FUwindows.winmd %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;NOTICE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;NOTICE_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAsWinRT>true</CompileAsWinRT>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
@@ -72,7 +72,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalOptions>/ZW:nostdlib /FUplatform.winmd /FUWindows.winmd %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;NOTICE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;NOTICE_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAsWinRT>true</CompileAsWinRT>
</ClCompile>
<Link>