}
}
- // 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;
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))
{
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;
}
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)
{
return S_OK;
}
- ERR("GetFontResourceInfoW failed\n");
+ ERR("GetFontResourceInfoW failed (err: %u)\n", dwErr);
return E_FAIL;
}