2019-08-03 13:14:20 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Font Shell Extension
|
|
|
|
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
|
|
|
* PURPOSE: CFontExt implementation
|
2021-07-15 20:45:19 +00:00
|
|
|
* COPYRIGHT: Copyright 2019-2021 Mark Jansen <mark.jansen@reactos.org>
|
2019-11-12 11:26:56 +00:00
|
|
|
* Copyright 2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
2019-08-03 13:14:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
2020-09-12 00:40:48 +00:00
|
|
|
#include "undocgdi.h" // for GetFontResourceInfoW
|
2019-08-03 13:14:20 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(fontext);
|
|
|
|
|
2021-07-15 20:45:19 +00:00
|
|
|
#ifndef SHCIDS_ALLFIELDS
|
|
|
|
#define SHCIDS_ALLFIELDS 0x80000000L
|
|
|
|
#endif
|
2019-08-03 13:14:20 +00:00
|
|
|
|
|
|
|
struct FolderViewColumns
|
|
|
|
{
|
|
|
|
int iResource;
|
|
|
|
DWORD dwDefaultState;
|
|
|
|
int cxChar;
|
|
|
|
int fmt;
|
|
|
|
};
|
|
|
|
|
2021-07-15 20:45:19 +00:00
|
|
|
enum font_columns
|
|
|
|
{
|
|
|
|
FONTEXT_COL_NAME,
|
|
|
|
FONTEXT_COL_FILENAME,
|
|
|
|
FONTEXT_COL_SIZE,
|
|
|
|
FONTEXT_COL_MODIFIED,
|
|
|
|
FONTEXT_COL_ATTR,
|
|
|
|
};
|
|
|
|
|
2019-08-03 13:14:20 +00:00
|
|
|
static FolderViewColumns g_ColumnDefs[] =
|
|
|
|
{
|
|
|
|
{ IDS_COL_NAME, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 25, LVCFMT_LEFT },
|
2020-01-20 20:43:19 +00:00
|
|
|
{ IDS_COL_FILENAME, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 20, LVCFMT_LEFT },
|
|
|
|
{ IDS_COL_SIZE, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 10, LVCFMT_RIGHT },
|
|
|
|
{ IDS_COL_MODIFIED, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, 15, LVCFMT_LEFT },
|
|
|
|
{ IDS_COL_ATTR, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, 12, LVCFMT_RIGHT },
|
2019-08-03 13:14:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Should fix our headers..
|
|
|
|
EXTERN_C HRESULT WINAPI SHCreateFileExtractIconW(LPCWSTR pszPath, DWORD dwFileAttributes, REFIID riid, void **ppv);
|
|
|
|
|
|
|
|
|
|
|
|
// Helper functions to translate a guid to a readable name
|
|
|
|
bool GetInterfaceName(const WCHAR* InterfaceString, WCHAR* buf, size_t size)
|
|
|
|
{
|
|
|
|
WCHAR LocalBuf[100];
|
|
|
|
DWORD dwType = 0, dwDataSize = size * sizeof(WCHAR);
|
|
|
|
|
|
|
|
if (!SUCCEEDED(StringCchPrintfW(LocalBuf, _countof(LocalBuf), L"Interface\\%s", InterfaceString)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return RegGetValueW(HKEY_CLASSES_ROOT, LocalBuf, NULL, RRF_RT_REG_SZ, &dwType, buf, &dwDataSize) == ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
WCHAR* g2s(REFCLSID iid)
|
|
|
|
{
|
|
|
|
static WCHAR buf[2][300];
|
|
|
|
static int idx = 0;
|
|
|
|
|
|
|
|
idx ^= 1;
|
|
|
|
|
|
|
|
LPOLESTR tmp;
|
|
|
|
HRESULT hr = ProgIDFromCLSID(iid, &tmp);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
wcscpy(buf[idx], tmp);
|
|
|
|
CoTaskMemFree(tmp);
|
|
|
|
return buf[idx];
|
|
|
|
}
|
|
|
|
StringFromGUID2(iid, buf[idx], _countof(buf[idx]));
|
|
|
|
if (GetInterfaceName(buf[idx], buf[idx], _countof(buf[idx])))
|
|
|
|
{
|
|
|
|
return buf[idx];
|
|
|
|
}
|
|
|
|
StringFromGUID2(iid, buf[idx], _countof(buf[idx]));
|
|
|
|
|
|
|
|
return buf[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CFontExt::CFontExt()
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&g_ModuleRefCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFontExt::~CFontExt()
|
|
|
|
{
|
|
|
|
InterlockedDecrement(&g_ModuleRefCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
// *** IShellFolder2 methods ***
|
|
|
|
STDMETHODIMP CFontExt::GetDefaultSearchGUID(GUID *lpguid)
|
|
|
|
{
|
|
|
|
ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::EnumSearches(IEnumExtraSearch **ppenum)
|
|
|
|
{
|
|
|
|
ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::GetDefaultColumn(DWORD dwReserved, ULONG *pSort, ULONG *pDisplay)
|
|
|
|
{
|
|
|
|
ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::GetDefaultColumnState(UINT iColumn, SHCOLSTATEF *pcsFlags)
|
|
|
|
{
|
|
|
|
if (!pcsFlags || iColumn >= _countof(g_ColumnDefs))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*pcsFlags = g_ColumnDefs[iColumn].dwDefaultState;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv)
|
|
|
|
{
|
|
|
|
ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
|
|
|
|
{
|
|
|
|
if (iColumn >= _countof(g_ColumnDefs))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
psd->cxChar = g_ColumnDefs[iColumn].cxChar;
|
|
|
|
psd->fmt = g_ColumnDefs[iColumn].fmt;
|
|
|
|
|
|
|
|
// No item requested, so return the column name
|
|
|
|
if (pidl == NULL)
|
|
|
|
{
|
|
|
|
return SHSetStrRet(&psd->str, _AtlBaseModule.GetResourceInstance(), g_ColumnDefs[iColumn].iResource);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate that this pidl is the last one
|
|
|
|
PCUIDLIST_RELATIVE curpidl = ILGetNext(pidl);
|
|
|
|
if (curpidl->mkid.cb != 0)
|
|
|
|
{
|
|
|
|
ERR("ERROR, unhandled PIDL!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:43:19 +00:00
|
|
|
// Name, ReactOS specific?
|
2021-07-15 20:45:19 +00:00
|
|
|
if (iColumn == FONTEXT_COL_NAME)
|
2020-01-20 20:43:19 +00:00
|
|
|
return GetDisplayNameOf(pidl, 0, &psd->str);
|
|
|
|
|
|
|
|
const FontPidlEntry* fontEntry = _FontFromIL(pidl);
|
|
|
|
if (!fontEntry)
|
|
|
|
{
|
|
|
|
ERR("ERROR, not a font PIDL!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got here, we are in details view!
|
2021-07-15 20:45:19 +00:00
|
|
|
auto info = g_FontCache->Find(fontEntry);
|
|
|
|
if (info == nullptr)
|
2020-01-20 20:43:19 +00:00
|
|
|
{
|
2021-07-15 20:45:19 +00:00
|
|
|
ERR("Unable to query info about %S\n", fontEntry->Name);
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
2020-01-20 20:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
CStringA AttrLetters;
|
2021-07-15 20:45:19 +00:00
|
|
|
DWORD dwAttributes;
|
|
|
|
SYSTEMTIME time;
|
2019-08-03 13:14:20 +00:00
|
|
|
switch (iColumn)
|
|
|
|
{
|
2021-07-15 20:45:19 +00:00
|
|
|
case FONTEXT_COL_FILENAME:
|
|
|
|
return SHSetStrRet(&psd->str, PathFindFileNameW(info->File()));
|
|
|
|
case FONTEXT_COL_SIZE:
|
2020-01-20 20:43:19 +00:00
|
|
|
psd->str.uType = STRRET_CSTR;
|
2021-07-15 20:45:19 +00:00
|
|
|
StrFormatKBSizeA(info->FileSize().QuadPart, psd->str.cStr, MAX_PATH);
|
2020-01-20 20:43:19 +00:00
|
|
|
return S_OK;
|
2021-07-15 20:45:19 +00:00
|
|
|
case FONTEXT_COL_MODIFIED:
|
2020-01-20 20:43:19 +00:00
|
|
|
psd->str.uType = STRRET_CSTR;
|
2021-07-15 20:45:19 +00:00
|
|
|
FileTimeToSystemTime(&info->FileWriteTime(), &time);
|
2020-01-20 20:43:19 +00:00
|
|
|
ret = GetDateFormatA(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &time, NULL, psd->str.cStr, MAX_PATH);
|
|
|
|
if (ret < 1)
|
|
|
|
{
|
|
|
|
ERR("GetDateFormatA failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
psd->str.cStr[ret-1] = ' ';
|
|
|
|
GetTimeFormatA(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, &psd->str.cStr[ret], MAX_PATH - ret);
|
|
|
|
return S_OK;
|
2021-07-15 20:45:19 +00:00
|
|
|
case FONTEXT_COL_ATTR:
|
2020-01-20 20:43:19 +00:00
|
|
|
AttrLetters.LoadString(IDS_COL_ATTR_LETTERS);
|
|
|
|
if (AttrLetters.GetLength() != 5)
|
|
|
|
{
|
|
|
|
ERR("IDS_COL_ATTR_LETTERS does not contain 5 letters!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
psd->str.uType = STRRET_CSTR;
|
2021-07-15 20:45:19 +00:00
|
|
|
dwAttributes = info->FileAttributes();
|
2020-01-20 20:43:19 +00:00
|
|
|
ret = 0;
|
2021-07-15 20:45:19 +00:00
|
|
|
if (dwAttributes & FILE_ATTRIBUTE_READONLY)
|
2020-01-20 20:43:19 +00:00
|
|
|
psd->str.cStr[ret++] = AttrLetters[0];
|
2021-07-15 20:45:19 +00:00
|
|
|
if (dwAttributes & FILE_ATTRIBUTE_HIDDEN)
|
2020-01-20 20:43:19 +00:00
|
|
|
psd->str.cStr[ret++] = AttrLetters[1];
|
2021-07-15 20:45:19 +00:00
|
|
|
if (dwAttributes & FILE_ATTRIBUTE_SYSTEM)
|
2020-01-20 20:43:19 +00:00
|
|
|
psd->str.cStr[ret++] = AttrLetters[2];
|
2021-07-15 20:45:19 +00:00
|
|
|
if (dwAttributes & FILE_ATTRIBUTE_ARCHIVE)
|
2020-01-20 20:43:19 +00:00
|
|
|
psd->str.cStr[ret++] = AttrLetters[3];
|
2021-07-15 20:45:19 +00:00
|
|
|
if (dwAttributes & FILE_ATTRIBUTE_COMPRESSED)
|
2020-01-20 20:43:19 +00:00
|
|
|
psd->str.cStr[ret++] = AttrLetters[4];
|
|
|
|
psd->str.cStr[ret] = '\0';
|
|
|
|
return S_OK;
|
2019-08-03 13:14:20 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::MapColumnToSCID(UINT iColumn, SHCOLUMNID *pscid)
|
|
|
|
{
|
|
|
|
//ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// *** IShellFolder2 methods ***
|
|
|
|
STDMETHODIMP CFontExt::ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, DWORD *pchEaten, PIDLIST_RELATIVE *ppidl, DWORD *pdwAttributes)
|
|
|
|
{
|
|
|
|
ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
|
|
|
|
{
|
|
|
|
return _CEnumFonts_CreateInstance(this, dwFlags, IID_PPV_ARG(IEnumIDList, ppEnumIDList));
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
|
|
|
|
{
|
|
|
|
ERR("%s(riid=%S) UNIMPLEMENTED\n", __FUNCTION__, g2s(riid));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::BindToStorage(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
|
|
|
|
{
|
|
|
|
ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
|
|
|
|
{
|
|
|
|
const FontPidlEntry* fontEntry1 = _FontFromIL(pidl1);
|
|
|
|
const FontPidlEntry* fontEntry2 = _FontFromIL(pidl2);
|
|
|
|
|
|
|
|
if (!fontEntry1 || !fontEntry2)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2021-07-15 20:45:19 +00:00
|
|
|
int result;
|
|
|
|
DWORD sortMode = lParam & 0xFFFF0000;
|
|
|
|
DWORD column = lParam & 0x0000FFFF;
|
|
|
|
if (sortMode == SHCIDS_ALLFIELDS)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
result = (int)fontEntry1->Index - (int)fontEntry2->Index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto info1 = g_FontCache->Find(fontEntry1);
|
|
|
|
auto info2 = g_FontCache->Find(fontEntry2);
|
|
|
|
|
|
|
|
if (!info1 || !info2)
|
|
|
|
{
|
|
|
|
ERR("Unable to find font %S or %S in cache!\n", fontEntry1->Name, fontEntry2->Name);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (column)
|
|
|
|
{
|
|
|
|
case 0xffff:
|
|
|
|
/* ROS bug? */
|
|
|
|
case FONTEXT_COL_NAME:
|
|
|
|
// These items are already ordered by name
|
|
|
|
result = (int)fontEntry1->Index - (int)fontEntry2->Index;
|
|
|
|
break;
|
|
|
|
case FONTEXT_COL_FILENAME:
|
|
|
|
result = wcsicmp(PathFindFileNameW(info1->File()), PathFindFileNameW(info2->File()));
|
|
|
|
break;
|
|
|
|
case FONTEXT_COL_SIZE:
|
|
|
|
result = (int)info1->FileSize().HighPart - info2->FileSize().HighPart;
|
|
|
|
if (result == 0)
|
|
|
|
result = (int)info1->FileSize().LowPart - info2->FileSize().LowPart;
|
|
|
|
break;
|
|
|
|
case FONTEXT_COL_MODIFIED:
|
|
|
|
result = CompareFileTime(&info1->FileWriteTime(), &info2->FileWriteTime());
|
|
|
|
break;
|
|
|
|
case FONTEXT_COL_ATTR:
|
|
|
|
// FIXME: how to compare attributes?
|
|
|
|
result = (int)info1->FileAttributes() - info2->FileAttributes();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unimplemented column %u\n", column);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
2019-08-03 13:14:20 +00:00
|
|
|
|
|
|
|
return MAKE_COMPARE_HRESULT(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
|
|
|
|
{
|
|
|
|
HRESULT hr = E_NOINTERFACE;
|
|
|
|
|
|
|
|
*ppvOut = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, IID_IDropTarget))
|
|
|
|
{
|
|
|
|
ERR("IDropTarget not implemented\n");
|
2019-11-12 11:26:56 +00:00
|
|
|
*ppvOut = static_cast<IDropTarget *>(this);
|
|
|
|
AddRef();
|
|
|
|
hr = S_OK;
|
2019-08-03 13:14:20 +00:00
|
|
|
}
|
|
|
|
else if (IsEqualIID(riid, IID_IContextMenu))
|
|
|
|
{
|
|
|
|
ERR("IContextMenu not implemented\n");
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
else if (IsEqualIID(riid, IID_IShellView))
|
|
|
|
{
|
|
|
|
// Just create a default shell folder view, and register ourself as folder
|
|
|
|
SFV_CREATE sfv = { sizeof(SFV_CREATE) };
|
|
|
|
sfv.pshf = this;
|
|
|
|
hr = SHCreateShellFolderView(&sfv, (IShellView**)ppvOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut)
|
|
|
|
{
|
|
|
|
if (!rgfInOut || !cidl || !apidl)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
DWORD rgf = 0;
|
|
|
|
while (cidl > 0 && *apidl)
|
|
|
|
{
|
|
|
|
const FontPidlEntry* fontEntry = _FontFromIL(*apidl);
|
|
|
|
if (fontEntry)
|
|
|
|
{
|
|
|
|
// We don't support delete yet
|
|
|
|
rgf |= (/*SFGAO_CANDELETE |*/ SFGAO_HASPROPSHEET | SFGAO_CANCOPY | SFGAO_FILESYSTEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rgf = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
apidl++;
|
|
|
|
cidl--;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rgfInOut = rgf;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
|
|
|
|
{
|
|
|
|
if (riid == IID_IContextMenu ||
|
|
|
|
riid == IID_IContextMenu2 ||
|
|
|
|
riid == IID_IContextMenu3)
|
|
|
|
{
|
|
|
|
return _CFontMenu_CreateInstance(hwndOwner, cidl, apidl, this, riid, ppvOut);
|
|
|
|
}
|
|
|
|
else if (riid == IID_IExtractIconA || riid == IID_IExtractIconW)
|
|
|
|
{
|
|
|
|
if (cidl == 1)
|
|
|
|
{
|
|
|
|
const FontPidlEntry* fontEntry = _FontFromIL(*apidl);
|
|
|
|
if (fontEntry)
|
|
|
|
{
|
|
|
|
DWORD dwAttributes = FILE_ATTRIBUTE_NORMAL;
|
2021-07-15 20:45:19 +00:00
|
|
|
CStringW File = g_FontCache->Filename(g_FontCache->Find(fontEntry));
|
2019-08-03 13:14:20 +00:00
|
|
|
// Just create a default icon extractor based on the filename
|
|
|
|
// We might want to create a preview with the font to get really fancy one day.
|
|
|
|
return SHCreateFileExtractIconW(File, dwAttributes, riid, ppvOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("IID_IExtractIcon with cidl != 1 UNIMPLEMENTED\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (riid == IID_IDataObject)
|
|
|
|
{
|
|
|
|
if (cidl >= 1)
|
|
|
|
{
|
|
|
|
return _CDataObject_CreateInstance(m_Folder, cidl, apidl, riid, ppvOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("IID_IDataObject with cidl == 0 UNIMPLEMENTED\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//ERR("%s(riid=%S) UNIMPLEMENTED\n", __FUNCTION__, g2s(riid));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet)
|
|
|
|
{
|
|
|
|
if (!pidl)
|
2019-10-19 21:55:39 +00:00
|
|
|
return E_NOTIMPL;
|
2019-08-03 13:14:20 +00:00
|
|
|
|
|
|
|
// Validate that this pidl is the last one
|
|
|
|
PCUIDLIST_RELATIVE curpidl = ILGetNext(pidl);
|
|
|
|
if (curpidl->mkid.cb != 0)
|
|
|
|
{
|
|
|
|
ERR("ERROR, unhandled PIDL!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FontPidlEntry* fontEntry = _FontFromIL(pidl);
|
|
|
|
if (!fontEntry)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2021-07-15 20:45:19 +00:00
|
|
|
if (dwFlags == SHGDN_FORPARSING)
|
|
|
|
{
|
|
|
|
CStringW File = g_FontCache->Filename(g_FontCache->Find(fontEntry), true);
|
|
|
|
if (!File.IsEmpty())
|
|
|
|
{
|
|
|
|
return SHSetStrRet(strRet, File);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 13:14:20 +00:00
|
|
|
return SHSetStrRet(strRet, fontEntry->Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut)
|
|
|
|
{
|
|
|
|
ERR("%s() UNIMPLEMENTED\n", __FUNCTION__);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// *** IPersistFolder2 methods ***
|
|
|
|
STDMETHODIMP CFontExt::GetCurFolder(LPITEMIDLIST *ppidl)
|
|
|
|
{
|
|
|
|
if (ppidl && m_Folder)
|
|
|
|
{
|
|
|
|
*ppidl = ILClone(m_Folder);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// *** IPersistFolder methods ***
|
|
|
|
STDMETHODIMP CFontExt::Initialize(LPCITEMIDLIST pidl)
|
|
|
|
{
|
2020-01-20 20:43:19 +00:00
|
|
|
WCHAR PidlPath[MAX_PATH + 1] = {0}, FontsDir[MAX_PATH + 1];
|
2019-08-03 13:14:20 +00:00
|
|
|
if (!SHGetPathFromIDListW(pidl, PidlPath))
|
|
|
|
{
|
|
|
|
ERR("Unable to extract path from pidl\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:43:19 +00:00
|
|
|
HRESULT hr = SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, FontsDir);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2019-08-03 13:14:20 +00:00
|
|
|
{
|
|
|
|
ERR("Unable to get fonts path (0x%x)\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:43:19 +00:00
|
|
|
if (_wcsicmp(PidlPath, FontsDir))
|
2019-08-03 13:14:20 +00:00
|
|
|
{
|
|
|
|
ERR("CFontExt View initializing on unexpected folder: '%S'\n", PidlPath);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Folder.Attach(ILClone(pidl));
|
2020-01-20 20:43:19 +00:00
|
|
|
StringCchCatW(FontsDir, _countof(FontsDir), L"\\");
|
|
|
|
g_FontCache->SetFontDir(FontsDir);
|
2019-08-03 13:14:20 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// *** IPersist methods ***
|
|
|
|
STDMETHODIMP CFontExt::GetClassID(CLSID *lpClassId)
|
|
|
|
{
|
|
|
|
*lpClassId = CLSID_CFontExt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-12 11:26:56 +00:00
|
|
|
// *** IDropTarget methods ***
|
|
|
|
STDMETHODIMP CFontExt::DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
|
|
|
|
{
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
|
|
|
|
CComHeapPtr<CIDA> cida;
|
|
|
|
HRESULT hr = _GetCidlFromDataObject(pDataObj, &cida);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
*pdwEffect = DROPEFFECT_COPY;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::DragLeave()
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP CFontExt::Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
|
|
|
|
{
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
|
|
|
|
CComHeapPtr<CIDA> cida;
|
2020-01-20 20:43:19 +00:00
|
|
|
HRESULT hr = _GetCidlFromDataObject(pDataObj, &cida);
|
2019-11-12 11:26:56 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
PCUIDLIST_ABSOLUTE pidlParent = HIDA_GetPIDLFolder(cida);
|
|
|
|
if (!pidlParent)
|
|
|
|
{
|
|
|
|
ERR("pidlParent is NULL\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL bOK = TRUE;
|
|
|
|
CAtlArray<CStringW> FontPaths;
|
|
|
|
for (UINT n = 0; n < cida->cidl; ++n)
|
|
|
|
{
|
|
|
|
PCUIDLIST_RELATIVE pidlRelative = HIDA_GetPIDLItem(cida, n);
|
|
|
|
if (!pidlRelative)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PIDLIST_ABSOLUTE pidl = ILCombine(pidlParent, pidlRelative);
|
|
|
|
if (!pidl)
|
|
|
|
{
|
|
|
|
ERR("ILCombine failed\n");
|
|
|
|
bOK = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
BOOL ret = SHGetPathFromIDListW(pidl, szPath);
|
|
|
|
ILFree(pidl);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
ERR("SHGetPathFromIDListW failed\n");
|
|
|
|
bOK = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PathIsDirectoryW(szPath))
|
|
|
|
{
|
|
|
|
ERR("PathIsDirectory\n");
|
|
|
|
bOK = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPCWSTR pchDotExt = PathFindExtensionW(szPath);
|
|
|
|
if (!IsFontDotExt(pchDotExt))
|
|
|
|
{
|
|
|
|
ERR("'%S' is not supported\n", pchDotExt);
|
|
|
|
bOK = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontPaths.Add(szPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bOK)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
CRegKey keyFonts;
|
|
|
|
if (keyFonts.Open(FONT_HIVE, FONT_KEY, KEY_WRITE) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("keyFonts.Open failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t iItem = 0; iItem < FontPaths.GetCount(); ++iItem)
|
|
|
|
{
|
2020-01-20 20:43:19 +00:00
|
|
|
HRESULT hr = DoInstallFontFile(FontPaths[iItem], g_FontCache->FontPath(), keyFonts.m_hKey);
|
2019-11-12 11:26:56 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
{
|
|
|
|
bOK = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: update g_FontCache
|
|
|
|
|
|
|
|
SendMessageW(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2020-09-12 00:40:48 +00:00
|
|
|
CStringW strFontName;
|
|
|
|
if (!DoGetFontTitle(pszFontPath, strFontName))
|
2019-11-12 11:26:56 +00:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
RemoveFontResourceW(pszFileTitle);
|
|
|
|
|
|
|
|
StringCchCopyW(szDestFile, sizeof(szDestFile), pszFontsDir);
|
|
|
|
PathAppendW(szDestFile, pszFileTitle);
|
|
|
|
if (!CopyFileW(pszFontPath, szDestFile, FALSE))
|
|
|
|
{
|
|
|
|
ERR("CopyFileW('%S', '%S') failed\n", pszFontPath, szDestFile);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2020-09-12 00:40:48 +00:00
|
|
|
if (!AddFontResourceW(szDestFile))
|
2019-11-12 11:26:56 +00:00
|
|
|
{
|
|
|
|
ERR("AddFontResourceW('%S') failed\n", pszFileTitle);
|
|
|
|
DeleteFileW(szDestFile);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD cbData = (wcslen(pszFileTitle) + 1) * sizeof(WCHAR);
|
2020-09-12 00:40:48 +00:00
|
|
|
LONG nError = RegSetValueExW(hkeyFonts, strFontName, 0, REG_SZ,
|
|
|
|
(const BYTE *)pszFileTitle, cbData);
|
2019-11-12 11:26:56 +00:00
|
|
|
if (nError)
|
|
|
|
{
|
|
|
|
ERR("RegSetValueExW failed with %ld\n", nError);
|
|
|
|
RemoveFontResourceW(pszFileTitle);
|
|
|
|
DeleteFileW(szDestFile);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-09-12 00:40:48 +00:00
|
|
|
HRESULT
|
|
|
|
CFontExt::DoGetFontTitle(IN LPCWSTR pszFontPath, OUT CStringW& strFontName)
|
2019-11-12 11:26:56 +00:00
|
|
|
{
|
2020-09-12 00:40:48 +00:00
|
|
|
DWORD cbInfo = 0;
|
|
|
|
BOOL ret = GetFontResourceInfoW(pszFontPath, &cbInfo, NULL, 1);
|
|
|
|
if (!ret || !cbInfo)
|
|
|
|
{
|
|
|
|
ERR("GetFontResourceInfoW failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LPWSTR pszBuffer = strFontName.GetBuffer(cbInfo / sizeof(WCHAR));
|
|
|
|
ret = GetFontResourceInfoW(pszFontPath, &cbInfo, pszBuffer, 1);
|
|
|
|
strFontName.ReleaseBuffer();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
TRACE("pszFontName: %S\n", (LPCWSTR)strFontName);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("GetFontResourceInfoW failed\n");
|
2019-11-12 11:26:56 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|