ReactOS  0.4.14-dev-833-g5f692ed
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 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\nCLSID={BD84B380-8CA2-1069-AB1D-08000948F534}\r\n";
58  HANDLE hFile;
59  HRESULT hr;
60 
62  if (FAILED(hr))
63  return hr;
64 
66  if (FAILED(hr))
67  return hr;
68 
69  // Make this a system folder:
70  // Ideally this should not be done here, but when installing
71  // Otherwise, livecd won't have this set properly
74  {
77  }
78  else
79  {
80  ERR("Unable to get attributes for fonts folder (%d)\n", GetLastError());
81  }
82 
83  if (!PathAppendW(Path, L"desktop.ini"))
84  return E_FAIL;
85 
89 
90  DWORD BytesWritten, BytesToWrite = strlen(DesktopIniContents);
91  if (WriteFile(hFile, DesktopIniContents, (DWORD)BytesToWrite, &BytesWritten, NULL))
92  hr = (BytesToWrite == BytesWritten) ? S_OK : E_FAIL;
93  else
96  return hr;
97 }
98 
100 {
102 }
103 
104 
105 EXTERN_C
107 {
108  switch (dwReason)
109  {
110  case DLL_PROCESS_ATTACH:
112  gModule.Init(ObjectMap, hInstance, NULL);
113  break;
114  case DLL_PROCESS_DETACH:
115  gModule.Term();
116  break;
117  }
118 
119  return TRUE;
120 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
#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
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
HRESULT DllRegisterServer(BOOL bRegTypeLib=TRUE)
Definition: atlbase.h:940
#define CloseHandle
Definition: compat.h:406
#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 OBJECT_ENTRY(clsid, class)
Definition: atlcom.h:653
#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:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
BOOL Init(PUSERCONNECT UserCon)
Definition: dllmain.c:385
#define CSIDL_FONTS
Definition: shlobj.h:2030
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:121
EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: fontext.cpp:106
STDAPI DllRegisterServer()
Definition: fontext.cpp:54
DWORD dwReason
Definition: misc.cpp:154
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#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
smooth NULL
Definition: ftsmooth.c:416
WINE_DEFAULT_DEBUG_CHANNEL(fontext)
STDAPI DllUnregisterServer()
Definition: fontext.cpp:99
#define DLL_PROCESS_DETACH
Definition: compat.h:119
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
#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:109
#define S_OK
Definition: intsafe.h:59
#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 CreateFileW
Definition: compat.h:408
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2087
const GUID CLSID_CFontExt
Definition: fontext.cpp:12
#define BEGIN_OBJECT_MAP(x)
Definition: atlcom.h:649
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:651