33 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
44 * PURPOSE: CFontExt implementation
55 * COPYRIGHT: Copyright 2019-2021 Mark Jansen <[email protected] > 6- * Copyright 2019 Katayama Hirofumi MZ ([email protected] ) 6+ * Copyright 2019-2025 Katayama Hirofumi MZ ([email protected] ) 77 */
88
99#include " precomp.h"
10- #include " undocgdi.h" // for GetFontResourceInfoW
1110
1211WINE_DEFAULT_DEBUG_CHANNEL (fontext);
1312
@@ -41,7 +40,6 @@ static FolderViewColumns g_ColumnDefs[] =
4140 { IDS_COL_ATTR, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 12 , LVCFMT_RIGHT },
4241};
4342
44-
4543// Helper functions to translate a guid to a readable name
4644bool GetInterfaceName (const WCHAR* InterfaceString, WCHAR* buf, size_t size)
4745{
@@ -79,7 +77,6 @@ WCHAR* g2s(REFCLSID iid)
7977 return buf[idx];
8078}
8179
82-
8380CFontExt::CFontExt ()
8481{
8582 InterlockedIncrement (&g_ModuleRefCnt);
@@ -365,7 +362,6 @@ STDMETHODIMP CFontExt::GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, D
365362 return S_OK;
366363}
367364
368-
369365STDMETHODIMP CFontExt::GetUIObjectOf (HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
370366{
371367 if (riid == IID_IContextMenu ||
@@ -456,7 +452,6 @@ STDMETHODIMP CFontExt::GetCurFolder(LPITEMIDLIST *ppidl)
456452 return E_POINTER;
457453}
458454
459-
460455// *** IPersistFolder methods ***
461456STDMETHODIMP CFontExt::Initialize (LPCITEMIDLIST pidl)
462457{
@@ -487,7 +482,6 @@ STDMETHODIMP CFontExt::Initialize(LPCITEMIDLIST pidl)
487482 return S_OK;
488483}
489484
490-
491485// *** IPersist methods ***
492486STDMETHODIMP CFontExt::GetClassID (CLSID *lpClassId)
493487{
@@ -523,7 +517,7 @@ STDMETHODIMP CFontExt::Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt,
523517 *pdwEffect = DROPEFFECT_NONE;
524518
525519 CDataObjectHIDA cida (pDataObj);
526- if (!cida)
520+ if (!cida || cida-> cidl <= 0 )
527521 return E_UNEXPECTED;
528522
529523 PCUIDLIST_ABSOLUTE pidlParent = HIDA_GetPIDLFolder (cida);
@@ -533,71 +527,23 @@ STDMETHODIMP CFontExt::Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt,
533527 return E_FAIL;
534528 }
535529
536- BOOL bOK = TRUE ;
537- CAtlArray<CStringW> FontPaths;
530+ CAtlArray<PCUIDLIST_RELATIVE> apidl;
538531 for (UINT n = 0 ; n < cida->cidl ; ++n)
539532 {
540533 PCUIDLIST_RELATIVE pidlRelative = HIDA_GetPIDLItem (cida, n);
541534 if (!pidlRelative)
542- continue ;
543-
544- PIDLIST_ABSOLUTE pidl = ILCombine (pidlParent, pidlRelative);
545- if (!pidl)
546- {
547- ERR (" ILCombine failed\n " );
548- bOK = FALSE ;
549- break ;
550- }
551-
552- WCHAR szPath[MAX_PATH];
553- BOOL ret = SHGetPathFromIDListW (pidl, szPath);
554- ILFree (pidl);
555-
556- if (!ret)
557- {
558- ERR (" SHGetPathFromIDListW failed\n " );
559- bOK = FALSE ;
560- break ;
561- }
562-
563- if (PathIsDirectoryW (szPath))
564- {
565- ERR (" PathIsDirectory\n " );
566- bOK = FALSE ;
567- break ;
568- }
569-
570- LPCWSTR pchDotExt = PathFindExtensionW (szPath);
571- if (!IsFontDotExt (pchDotExt))
572- {
573- ERR (" '%S' is not supported\n " , pchDotExt);
574- bOK = FALSE ;
575- break ;
576- }
535+ return E_FAIL;
577536
578- FontPaths .Add (szPath );
537+ apidl .Add (pidlRelative );
579538 }
580539
581- if (!bOK)
582- return E_FAIL;
583-
584- CRegKey keyFonts;
585- if (keyFonts.Open (FONT_HIVE, FONT_KEY, KEY_WRITE) != ERROR_SUCCESS)
540+ CStringW strMessage;
541+ if (InstallFontFiles (strMessage, pidlParent, cida->cidl , &apidl[0 ]) != S_OK)
586542 {
587- ERR ( " keyFonts.Open failed \n " );
543+ // TODO: Show message
588544 return E_FAIL;
589545 }
590546
591- for (size_t iItem = 0 ; iItem < FontPaths.GetCount (); ++iItem)
592- {
593- HRESULT hr = DoInstallFontFile (FontPaths[iItem], g_FontCache->FontPath (), keyFonts.m_hKey );
594- if (FAILED_UNEXPECTEDLY (hr))
595- {
596- bOK = FALSE ;
597- break ;
598- }
599- }
600-
601547 // Invalidate our cache
602548 g_FontCache->Read ();
603549
@@ -609,79 +555,5 @@ STDMETHODIMP CFontExt::Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt,
609555
610556 // TODO: Show message
611557
612- return bOK ? S_OK : E_FAIL;
613- }
614-
615- HRESULT CFontExt::DoInstallFontFile (LPCWSTR pszFontPath, LPCWSTR pszFontsDir, HKEY hkeyFonts)
616- {
617- WCHAR szDestFile[MAX_PATH];
618-
619- // Add this font to the font list, so we can query the name
620- if (!AddFontResourceW (pszFontPath))
621- {
622- ERR (" AddFontResourceW('%S') failed\n " , pszFontPath);
623- DeleteFileW (szDestFile);
624- return E_FAIL;
625- }
626-
627- CStringW strFontName;
628- HRESULT hr = DoGetFontTitle (pszFontPath, strFontName);
629-
630- // We got the name, remove it again
631- RemoveFontResourceW (pszFontPath);
632-
633- if (!SUCCEEDED (hr))
634- {
635- ERR (" DoGetFontTitle failed (err=0x%x)!\n " , hr);
636- return hr;
637- }
638-
639- StringCchCopyW (szDestFile, sizeof (szDestFile), pszFontsDir);
640-
641- LPCWSTR pszFileTitle = PathFindFileName (pszFontPath);
642- PathAppendW (szDestFile, pszFileTitle);
643- if (!CopyFileW (pszFontPath, szDestFile, FALSE ))
644- {
645- ERR (" CopyFileW('%S', '%S') failed\n " , pszFontPath, szDestFile);
646- return E_FAIL;
647- }
648-
649- DWORD cbData = (wcslen (pszFileTitle) + 1 ) * sizeof (WCHAR);
650- LONG nError = RegSetValueExW (hkeyFonts, strFontName, 0 , REG_SZ,
651- (const BYTE *)pszFileTitle, cbData);
652- if (nError)
653- {
654- ERR (" RegSetValueExW failed with %ld\n " , nError);
655- DeleteFileW (szDestFile);
656- return E_FAIL;
657- }
658-
659- AddFontResourceW (szDestFile);
660-
661558 return S_OK;
662559}
663-
664- HRESULT
665- CFontExt::DoGetFontTitle (IN LPCWSTR pszFontPath, OUT CStringW& strFontName)
666- {
667- DWORD cbInfo = 0 ;
668- BOOL ret = GetFontResourceInfoW (pszFontPath, &cbInfo, NULL , 1 );
669- if (!ret || !cbInfo)
670- {
671- ERR (" GetFontResourceInfoW failed (err: %u)\n " , GetLastError ());
672- return E_FAIL;
673- }
674-
675- LPWSTR pszBuffer = strFontName.GetBuffer (cbInfo / sizeof (WCHAR));
676- ret = GetFontResourceInfoW (pszFontPath, &cbInfo, pszBuffer, 1 );
677- DWORD dwErr = GetLastError ();;
678- strFontName.ReleaseBuffer ();
679- if (ret)
680- {
681- TRACE (" pszFontName: %S\n " , (LPCWSTR)strFontName);
682- return S_OK;
683- }
684-
685- ERR (" GetFontResourceInfoW failed (err: %u)\n " , dwErr);
686- return E_FAIL;
687- }
0 commit comments