ReactOS 0.4.16-dev-959-g2ec3a19
fontext.cpp File Reference
#include "precomp.h"
#include "undocgdi.h"
Include dependency graph for fontext.cpp:

Go to the source code of this file.

Classes

class  CFontExtModule
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (fontext)
 
STDAPI DllCanUnloadNow ()
 
STDAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppv)
 
STDAPI DllRegisterServer ()
 
STDAPI DllUnregisterServer ()
 
HRESULT InstallFontFiles (_Out_ CStringW &strMsg, _In_ PCUIDLIST_ABSOLUTE pidlParent, _In_ UINT cidl, _In_ PCUITEMID_CHILD_ARRAY apidl)
 
HRESULT DoInstallFontFile (_Out_ CStringW &strMsg, _In_ PCWSTR pszFontPath, _In_ PCWSTR pszFontsDir, _In_ HKEY hkeyFonts)
 
HRESULT DoGetFontTitle (_In_ LPCWSTR pszFontPath, _Out_ CStringW &strFontName)
 
EXTERN_C BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 

Variables

const GUID CLSID_CFontExt = { 0xbd84b380, 0x8ca2, 0x1069, { 0xab, 0x1d, 0x08, 0x00, 0x09, 0x48, 0xf5, 0x34 } }
 
LONG g_ModuleRefCnt
 
CFontExtModule gModule
 

Function Documentation

◆ DllCanUnloadNow()

STDAPI DllCanUnloadNow ( void  )

Definition at line 39 of file fontext.cpp.

40{
42 return S_FALSE;
43 return gModule.DllCanUnloadNow();
44}
HRESULT DllCanUnloadNow()
Definition: atlbase.h:1030
LONG g_ModuleRefCnt
Definition: fontext.cpp:36
CFontExtModule gModule
Definition: fontext.cpp:37
#define S_FALSE
Definition: winerror.h:2357

◆ DllGetClassObject()

STDAPI DllGetClassObject ( REFCLSID  rclsid,
REFIID  riid,
LPVOID ppv 
)

Definition at line 46 of file fontext.cpp.

47{
48 return gModule.DllGetClassObject(rclsid, riid, ppv);
49}
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: atlbase.h:1037
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39

◆ DllMain()

EXTERN_C BOOL WINAPI DllMain ( HINSTANCE  hInstance,
DWORD  dwReason,
LPVOID  lpReserved 
)

Definition at line 228 of file fontext.cpp.

229{
230 switch (dwReason)
231 {
234 gModule.Init(ObjectMap, hInstance, NULL);
235 break;
237 gModule.Term();
238 break;
239 }
240
241 return TRUE;
242}
DWORD dwReason
Definition: misc.cpp:135
HINSTANCE hInstance
Definition: charmap.c:19
void Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE h, const GUID *plibid)
Definition: fontext.cpp:18
void Term()
Definition: fontext.cpp:24
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85

◆ DllRegisterServer()

STDAPI DllRegisterServer ( void  )

Definition at line 51 of file fontext.cpp.

52{
53 WCHAR Path[MAX_PATH] = { 0 };
54 static const char DesktopIniContents[] = "[.ShellClassInfo]\r\n"
55 "CLSID={BD84B380-8CA2-1069-AB1D-08000948F534}\r\n"
56 "IconResource=%SystemRoot%\\system32\\shell32.dll,-39\r\n"; // IDI_SHELL_FONTS_FOLDER
58 HRESULT hr;
59
62 return hr;
63
66 return hr;
67
68 // Make this a system folder:
69 // Ideally this should not be done here, but when installing
70 // Otherwise, livecd won't have this set properly
73 {
76 }
77 else
78 {
79 ERR("Unable to get attributes for fonts folder (%d)\n", GetLastError());
80 }
81
82 if (!PathAppendW(Path, L"desktop.ini"))
83 return E_FAIL;
84
88
89 DWORD BytesWritten, BytesToWrite = strlen(DesktopIniContents);
90 if (WriteFile(hFile, DesktopIniContents, (DWORD)BytesToWrite, &BytesWritten, NULL))
91 hr = (BytesToWrite == BytesWritten) ? S_OK : E_FAIL;
92 else
95 return hr;
96}
PRTL_UNICODE_STRING_BUFFER Path
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ERR(fmt,...)
Definition: precomp.h:57
HRESULT DllRegisterServer(BOOL bRegTypeLib=TRUE)
Definition: atlbase.h:1042
#define E_FAIL
Definition: ddrawi.h:102
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2740
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define CREATE_ALWAYS
Definition: disk.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
#define PathAppendW
Definition: pathcch.h:309
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_FONTS
Definition: shlobj.h:2200
DWORD dwAttributes
Definition: vdmdbg.h:34
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ DllUnregisterServer()

STDAPI DllUnregisterServer ( void  )

Definition at line 98 of file fontext.cpp.

99{
101}
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib=TRUE)
Definition: atlbase.h:1047

◆ DoGetFontTitle()

HRESULT DoGetFontTitle ( _In_ LPCWSTR  pszFontPath,
_Out_ CStringW strFontName 
)

Definition at line 201 of file fontext.cpp.

204{
205 DWORD cbInfo = 0;
206 BOOL ret = GetFontResourceInfoW(pszFontPath, &cbInfo, NULL, 1);
207 if (!ret || !cbInfo)
208 {
209 ERR("GetFontResourceInfoW failed (err: %u)\n", GetLastError());
210 return E_FAIL;
211 }
212
213 LPWSTR pszBuffer = strFontName.GetBuffer(cbInfo / sizeof(WCHAR));
214 ret = GetFontResourceInfoW(pszFontPath, &cbInfo, pszBuffer, 1);
216 strFontName.ReleaseBuffer();
217 if (ret)
218 {
219 TRACE("pszFontName: %S\n", (LPCWSTR)strFontName);
220 return S_OK;
221 }
222
223 ERR("GetFontResourceInfoW failed (err: %u)\n", dwErr);
224 return E_FAIL;
225}
DWORD dwErr
Definition: service.c:36
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI GetFontResourceInfoW(LPCWSTR lpFileName, DWORD *pdwBufSize, void *lpBuffer, DWORD dwType)
#define TRACE(s)
Definition: solgame.cpp:4
int ret
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by DoInstallFontFile().

◆ DoInstallFontFile()

HRESULT DoInstallFontFile ( _Out_ CStringW strMsg,
_In_ PCWSTR  pszFontPath,
_In_ PCWSTR  pszFontsDir,
_In_ HKEY  hkeyFonts 
)

Definition at line 150 of file fontext.cpp.

155{
156 WCHAR szDestFile[MAX_PATH];
157
158 // Add this font to the font list, so we can query the name
159 if (!AddFontResourceW(pszFontPath))
160 {
161 ERR("AddFontResourceW('%S') failed\n", pszFontPath);
162 return E_FAIL;
163 }
164
165 CStringW strFontName;
166 HRESULT hr = DoGetFontTitle(pszFontPath, strFontName);
167
168 // We got the name, remove it again
169 RemoveFontResourceW(pszFontPath);
170
171 if (!SUCCEEDED(hr))
172 {
173 ERR("DoGetFontTitle failed (err=0x%x)!\n", hr);
174 return hr;
175 }
176
177 StringCchCopyW(szDestFile, sizeof(szDestFile), pszFontsDir);
178
179 LPCWSTR pszFileTitle = PathFindFileName(pszFontPath);
180 PathAppendW(szDestFile, pszFileTitle);
181 if (!CopyFileW(pszFontPath, szDestFile, FALSE))
182 {
183 ERR("CopyFileW('%S', '%S') failed\n", pszFontPath, szDestFile);
184 return E_FAIL;
185 }
186
187 DWORD cbData = (wcslen(pszFileTitle) + 1) * sizeof(WCHAR);
188 LONG nError = RegSetValueExW(hkeyFonts, strFontName, 0, REG_SZ,
189 (const BYTE *)pszFileTitle, cbData);
190 if (nError)
191 {
192 ERR("RegSetValueExW failed with %ld\n", nError);
193 DeleteFileW(szDestFile);
194 return E_FAIL;
195 }
196
197 return AddFontResourceW(szDestFile) ? S_OK : E_FAIL;
198}
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
HRESULT DoGetFontTitle(_In_ LPCWSTR pszFontPath, _Out_ CStringW &strFontName)
Definition: fontext.cpp:201
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define REG_SZ
Definition: layer.c:22
long LONG
Definition: pedump.c:60
#define PathFindFileName
Definition: shlwapi.h:946
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
int WINAPI AddFontResourceW(_In_ LPCWSTR pszFilename)
Definition: font.c:2167
BOOL WINAPI RemoveFontResourceW(_In_ LPCWSTR)
Definition: font.c:2175
unsigned char BYTE
Definition: xxhash.c:193

Referenced by InstallFontFiles().

◆ InstallFontFiles()

HRESULT InstallFontFiles ( _Out_ CStringW strMsg,
_In_ PCUIDLIST_ABSOLUTE  pidlParent,
_In_ UINT  cidl,
_In_ PCUITEMID_CHILD_ARRAY  apidl 
)

Definition at line 104 of file fontext.cpp.

109{
110 CAtlArray<CStringW> FontPaths;
111 for (UINT n = 0; n < cidl; ++n)
112 {
114 pidl.Attach(ILCombine(pidlParent, apidl[n]));
115 if (!pidl)
116 {
117 ERR("Out of memory\n");
118 return E_OUTOFMEMORY;
119 }
120
124 {
125 ERR("Not font file: %s\n", wine_dbgstr_w(szPath));
126 return E_FAIL;
127 }
128
129 FontPaths.Add(szPath);
130 }
131
132 CRegKey keyFonts;
133 if (keyFonts.Open(FONT_HIVE, FONT_KEY, KEY_WRITE) != ERROR_SUCCESS)
134 {
135 ERR("CRegKey::Open failed\n");
136 return E_FAIL;
137 }
138
139 for (SIZE_T iItem = 0; iItem < FontPaths.GetCount(); ++iItem)
140 {
141 HRESULT hr = DoInstallFontFile(strMsg, FontPaths[iItem], g_FontCache->FontPath(), keyFonts);
143 return hr;
144 }
145
146 return S_OK;
147}
CFontCache * g_FontCache
Definition: CFontCache.cpp:12
size_t Add(INARGTYPE element)
Definition: atlcoll.h:295
size_t GetCount() const
Definition: atlcoll.h:373
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE) noexcept
Definition: atlbase.h:1173
const CStringW & FontPath() const
Definition: CFontCache.hpp:51
void Attach(T *lp)
Definition: atlalloc.h:162
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL IsFontDotExt(LPCWSTR pchDotExt)
Definition: precomp.h:44
#define FONT_HIVE
Definition: precomp.h:35
#define FONT_KEY
Definition: precomp.h:36
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1729
HRESULT DoInstallFontFile(_Out_ CStringW &strMsg, _In_ PCWSTR pszFontPath, _In_ PCWSTR pszFontsDir, _In_ HKEY hkeyFonts)
Definition: fontext.cpp:150
GLdouble n
Definition: glext.h:7729
#define wine_dbgstr_w
Definition: kernel32.h:34
LPCWSTR szPath
Definition: env.c:37
unsigned int UINT
Definition: ndis.h:50
#define KEY_WRITE
Definition: nt_native.h:1031
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:816
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1454
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by CFontExt::Drop().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( fontext  )

Variable Documentation

◆ CLSID_CFontExt

const GUID CLSID_CFontExt = { 0xbd84b380, 0x8ca2, 0x1069, { 0xab, 0x1d, 0x08, 0x00, 0x09, 0x48, 0xf5, 0x34 } }

Definition at line 13 of file fontext.cpp.

Referenced by CFontExt::GetClassID().

◆ g_ModuleRefCnt

LONG g_ModuleRefCnt

Definition at line 36 of file fontext.cpp.

Referenced by DllCanUnloadNow().

◆ gModule