ReactOS  0.4.15-dev-3203-gacde1e0
fontext.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Font Shell Extension
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Shell extension entry point
5  * COPYRIGHT: Copyright 2019,2020 Mark Jansen <mark.jansen@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
11 
12 const GUID CLSID_CFontExt = { 0xbd84b380, 0x8ca2, 0x1069, { 0xab, 0x1d, 0x08, 0x00, 0x09, 0x48, 0xf5, 0x34 } };
13 
14 
15 class CFontExtModule : public CComModule
16 {
17 public:
18  void Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE h, const GUID *plibid)
19  {
20  g_FontCache = new CFontCache();
21  CComModule::Init(p, h, plibid);
22  }
23 
24  void Term()
25  {
26  delete g_FontCache;
27  g_FontCache = NULL;
28  CComModule::Term();
29  }
30 };
31 
32 BEGIN_OBJECT_MAP(ObjectMap)
35 
36 
39 
40 
42 {
43  if (g_ModuleRefCnt)
44  return S_FALSE;
45  return gModule.DllCanUnloadNow();
46 }
47 
49 {
50  return gModule.DllGetClassObject(rclsid, riid, ppv);
51 }
52 
53 
55 {
56  WCHAR Path[MAX_PATH] = { 0 };
57  static const char DesktopIniContents[] = "[.ShellClassInfo]\r\n"
58  "CLSID={BD84B380-8CA2-1069-AB1D-08000948F534}\r\n"
59  "IconResource=%SystemRoot%\\system32\\shell32.dll,-39\r\n"; // IDI_SHELL_FONTS_FOLDER
60  HANDLE hFile;
61  HRESULT hr;
62 
65  return hr;
66 
69  return hr;
70 
71  // Make this a system folder:
72  // Ideally this should not be done here, but when installing
73  // Otherwise, livecd won't have this set properly
76  {
79  }
80  else
81  {
82  ERR("Unable to get attributes for fonts folder (%d)\n", GetLastError());
83  }
84 
85  if (!PathAppendW(Path, L"desktop.ini"))
86  return E_FAIL;
87 
91 
92  DWORD BytesWritten, BytesToWrite = strlen(DesktopIniContents);
93  if (WriteFile(hFile, DesktopIniContents, (DWORD)BytesToWrite, &BytesWritten, NULL))
94  hr = (BytesToWrite == BytesWritten) ? S_OK : E_FAIL;
95  else
98  return hr;
99 }
100 
102 {
104 }
105 
106 
107 EXTERN_C
109 {
110  switch (dwReason)
111  {
112  case DLL_PROCESS_ATTACH:
114  gModule.Init(ObjectMap, hInstance, NULL);
115  break;
116  case DLL_PROCESS_DETACH:
117  gModule.Term();
118  break;
119  }
120 
121  return TRUE;
122 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794
_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:949
#define STDAPI
Definition: basetyps.h:41
HRESULT DllCanUnloadNow()
Definition: atlbase.h:928
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define REFIID
Definition: guiddef.h:118
HRESULT DllRegisterServer(BOOL bRegTypeLib=TRUE)
Definition: atlbase.h:940
#define CloseHandle
Definition: compat.h:598
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
HRESULT hr
Definition: shlfolder.c:183
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
#define OBJECT_ENTRY(clsid, class)
Definition: atlcom.h:654
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
REFIID riid
Definition: precomp.h:44
#define REFCLSID
Definition: guiddef.h:117
CFontExtModule gModule
Definition: fontext.cpp:38
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
BOOL Init(PUSERCONNECT UserCon)
Definition: dllmain.c:385
#define CSIDL_FONTS
Definition: shlobj.h:2031
STDAPI DllCanUnloadNow()
Definition: fontext.cpp:41
#define E_FAIL
Definition: ddrawi.h:102
DWORD dwAttributes
Definition: vdmdbg.h:34
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:126
EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: fontext.cpp:108
STDAPI DllRegisterServer()
Definition: fontext.cpp:54
DWORD dwReason
Definition: misc.cpp:154
HINSTANCE hInstance
Definition: charmap.c:20
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
#define GENERIC_WRITE
Definition: nt_native.h:90
#define S_FALSE
Definition: winerror.h:2357
HRESULT DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: atlbase.h:935
WINE_DEFAULT_DEBUG_CHANNEL(fontext)
STDAPI DllUnregisterServer()
Definition: fontext.cpp:101
#define DLL_PROCESS_DETACH
Definition: compat.h:130
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:82
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
LONG g_ModuleRefCnt
Definition: fontext.cpp:37
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: fontext.cpp:48
static const WCHAR L[]
Definition: oid.c:1250
CFontCache * g_FontCache
Definition: CFontCache.cpp:12
_In_ HANDLE hFile
Definition: mswsock.h:90
void Init(_ATL_OBJMAP_ENTRY *p, HINSTANCE h, const GUID *plibid)
Definition: fontext.cpp:18
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:52
#define CREATE_ALWAYS
Definition: disk.h:72
void Term()
Definition: fontext.cpp:24
PRTL_UNICODE_STRING_BUFFER Path
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:600
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2447
const GUID CLSID_CFontExt
Definition: fontext.cpp:12
#define BEGIN_OBJECT_MAP(x)
Definition: atlcom.h:650
HRESULT DllUnregisterServer(BOOL bUnRegTypeLib=TRUE)
Definition: atlbase.h:945
GLfloat GLfloat p
Definition: glext.h:8902
#define EXTERN_C
Definition: basetyps.h:12
#define END_OBJECT_MAP()
Definition: atlcom.h:652