https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ab7b004d51c3c38440794…
commit ab7b004d51c3c38440794ce5d3b7fb03c03af2a8
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Sun Jul 25 01:11:01 2021 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Mon Nov 15 20:02:14 2021 +0100
[FONTEXT] Fix font installation
---
dll/shellext/fontext/CFontCache.hpp | 3 ++-
dll/shellext/fontext/CFontExt.cpp | 45 ++++++++++++++++++++++++-------------
2 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/dll/shellext/fontext/CFontCache.hpp b/dll/shellext/fontext/CFontCache.hpp
index e047e6b4b1d..ba9d9e39636 100644
--- a/dll/shellext/fontext/CFontCache.hpp
+++ b/dll/shellext/fontext/CFontCache.hpp
@@ -45,9 +45,10 @@ protected:
CFontCache();
void Insert(CAtlList<CFontInfo>& fonts, const CStringW& KeyName);
- void Read();
public:
+ void Read();
+
void SetFontDir(const LPCWSTR Path);
const CStringW& FontPath() const { return m_FontFolderPath; }
diff --git a/dll/shellext/fontext/CFontExt.cpp b/dll/shellext/fontext/CFontExt.cpp
index 23b7e0b2721..7fffa90736e 100644
--- a/dll/shellext/fontext/CFontExt.cpp
+++ b/dll/shellext/fontext/CFontExt.cpp
@@ -603,10 +603,15 @@ STDMETHODIMP CFontExt::Drop(IDataObject* pDataObj, DWORD
grfKeyState, POINTL pt,
}
}
- // TODO: update g_FontCache
+ // Invalidate our cache
+ g_FontCache->Read();
+ // Notify the system that a font was added
SendMessageW(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
+ // Notify the shell that the folder contents are changed
+ SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATHW, g_FontCache->FontPath().GetString(),
NULL);
+
// TODO: Show message
return bOK ? S_OK : E_FAIL;
@@ -615,15 +620,30 @@ STDMETHODIMP CFontExt::Drop(IDataObject* pDataObj, DWORD
grfKeyState, POINTL pt,
HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HKEY
hkeyFonts)
{
WCHAR szDestFile[MAX_PATH];
- LPCWSTR pszFileTitle = PathFindFileName(pszFontPath);
- CStringW strFontName;
- if (!DoGetFontTitle(pszFontPath, strFontName))
+ // Add this font to the font list, so we can query the name
+ if (!AddFontResourceW(pszFontPath))
+ {
+ ERR("AddFontResourceW('%S') failed\n", pszFontPath);
+ DeleteFileW(szDestFile);
return E_FAIL;
+ }
+
+ CStringW strFontName;
+ HRESULT hr = DoGetFontTitle(pszFontPath, strFontName);
- RemoveFontResourceW(pszFileTitle);
+ // We got the name, remove it again
+ RemoveFontResourceW(pszFontPath);
+
+ if (!SUCCEEDED(hr))
+ {
+ ERR("DoGetFontTitle failed (err=0x%x)!\n", hr);
+ return hr;
+ }
StringCchCopyW(szDestFile, sizeof(szDestFile), pszFontsDir);
+
+ LPCWSTR pszFileTitle = PathFindFileName(pszFontPath);
PathAppendW(szDestFile, pszFileTitle);
if (!CopyFileW(pszFontPath, szDestFile, FALSE))
{
@@ -631,24 +651,18 @@ HRESULT CFontExt::DoInstallFontFile(LPCWSTR pszFontPath, LPCWSTR
pszFontsDir, HK
return E_FAIL;
}
- if (!AddFontResourceW(szDestFile))
- {
- ERR("AddFontResourceW('%S') failed\n", pszFileTitle);
- DeleteFileW(szDestFile);
- return E_FAIL;
- }
-
DWORD cbData = (wcslen(pszFileTitle) + 1) * sizeof(WCHAR);
LONG nError = RegSetValueExW(hkeyFonts, strFontName, 0, REG_SZ,
(const BYTE *)pszFileTitle, cbData);
if (nError)
{
ERR("RegSetValueExW failed with %ld\n", nError);
- RemoveFontResourceW(pszFileTitle);
DeleteFileW(szDestFile);
return E_FAIL;
}
+ AddFontResourceW(szDestFile);
+
return S_OK;
}
@@ -659,12 +673,13 @@ CFontExt::DoGetFontTitle(IN LPCWSTR pszFontPath, OUT CStringW&
strFontName)
BOOL ret = GetFontResourceInfoW(pszFontPath, &cbInfo, NULL, 1);
if (!ret || !cbInfo)
{
- ERR("GetFontResourceInfoW failed\n");
+ ERR("GetFontResourceInfoW failed (err: %u)\n", GetLastError());
return E_FAIL;
}
LPWSTR pszBuffer = strFontName.GetBuffer(cbInfo / sizeof(WCHAR));
ret = GetFontResourceInfoW(pszFontPath, &cbInfo, pszBuffer, 1);
+ DWORD dwErr = GetLastError();;
strFontName.ReleaseBuffer();
if (ret)
{
@@ -672,6 +687,6 @@ CFontExt::DoGetFontTitle(IN LPCWSTR pszFontPath, OUT CStringW&
strFontName)
return S_OK;
}
- ERR("GetFontResourceInfoW failed\n");
+ ERR("GetFontResourceInfoW failed (err: %u)\n", dwErr);
return E_FAIL;
}