mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 22:12:46 +00:00
[SHELL32] cache entries of "New" menu
CORE-10439 svn path=/trunk/; revision=71980
This commit is contained in:
parent
73e04c0cd1
commit
7541633310
2 changed files with 162 additions and 54 deletions
|
@ -163,22 +163,109 @@ CNewMenu::SHELLNEW_ITEM *CNewMenu::LoadItem(LPCWSTR pwszExt)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
CNewMenu::LoadAllItems()
|
CNewMenu::CacheItems()
|
||||||
{
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
DWORD dwSize = 0;
|
||||||
DWORD dwIndex = 0;
|
DWORD dwIndex = 0;
|
||||||
|
LPWSTR lpValue;
|
||||||
|
LPWSTR lpValues;
|
||||||
WCHAR wszName[MAX_PATH];
|
WCHAR wszName[MAX_PATH];
|
||||||
SHELLNEW_ITEM *pNewItem;
|
SHELLNEW_ITEM *pNewItem;
|
||||||
SHELLNEW_ITEM *pCurItem = NULL;
|
SHELLNEW_ITEM *pCurItem = NULL;
|
||||||
|
|
||||||
/* If there are any unload them */
|
/* Enumerate all extensions */
|
||||||
UnloadAllItems();
|
|
||||||
|
|
||||||
/* Enumerate all extesions */
|
|
||||||
while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS)
|
while (RegEnumKeyW(HKEY_CLASSES_ROOT, dwIndex++, wszName, _countof(wszName)) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
if (wszName[0] != L'.')
|
if (wszName[0] != L'.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
pNewItem = LoadItem(wszName);
|
||||||
|
if (pNewItem)
|
||||||
|
{
|
||||||
|
dwSize += wcslen(wszName) + 1;
|
||||||
|
if (wcsicmp(pNewItem->pwszExt, L".lnk") == 0)
|
||||||
|
{
|
||||||
|
/* Link handler */
|
||||||
|
m_pLinkItem = pNewItem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Add at the end of list */
|
||||||
|
if (pCurItem)
|
||||||
|
{
|
||||||
|
pCurItem->pNext = pNewItem;
|
||||||
|
pCurItem = pNewItem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pCurItem = m_pItems = pNewItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dwSize++;
|
||||||
|
|
||||||
|
lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize * sizeof(WCHAR));
|
||||||
|
if (!lpValues)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
lpValue = lpValues;
|
||||||
|
pCurItem = m_pItems;
|
||||||
|
while (pCurItem)
|
||||||
|
{
|
||||||
|
memcpy(lpValue, pCurItem->pwszExt, (wcslen(pCurItem->pwszExt) + 1) * sizeof(WCHAR));
|
||||||
|
lpValue += wcslen(pCurItem->pwszExt) + 1;
|
||||||
|
pCurItem = pCurItem->pNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegCreateKeyEx(HKEY_CURRENT_USER, ShellNewKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpValues);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegSetValueExW(hKey, L"Classes", NULL, REG_MULTI_SZ, (LPBYTE)lpValues, dwSize) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpValues);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpValues);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL
|
||||||
|
CNewMenu::LoadCachedItems()
|
||||||
|
{
|
||||||
|
LPWSTR wszName;
|
||||||
|
LPWSTR lpValues;
|
||||||
|
DWORD dwSize;
|
||||||
|
HKEY hKey;
|
||||||
|
SHELLNEW_ITEM *pNewItem;
|
||||||
|
SHELLNEW_ITEM *pCurItem = NULL;
|
||||||
|
|
||||||
|
if (RegOpenKeyExW(HKEY_CURRENT_USER, ShellNewKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, NULL, &dwSize) != ERROR_SUCCESS)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
lpValues = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwSize);
|
||||||
|
if (!lpValues)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (RegQueryValueExW(hKey, L"Classes", NULL, NULL, (LPBYTE)lpValues, &dwSize) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpValues);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
wszName = lpValues;
|
||||||
|
|
||||||
|
for (; '\0' != *wszName; wszName += wcslen(wszName) + 1)
|
||||||
|
{
|
||||||
pNewItem = LoadItem(wszName);
|
pNewItem = LoadItem(wszName);
|
||||||
if (pNewItem)
|
if (pNewItem)
|
||||||
{
|
{
|
||||||
|
@ -201,6 +288,23 @@ CNewMenu::LoadAllItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, lpValues);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL
|
||||||
|
CNewMenu::LoadAllItems()
|
||||||
|
{
|
||||||
|
/* If there are any unload them */
|
||||||
|
UnloadAllItems();
|
||||||
|
|
||||||
|
if (!LoadCachedItems())
|
||||||
|
{
|
||||||
|
CacheItems();
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_pLinkItem)
|
if (!m_pLinkItem)
|
||||||
{
|
{
|
||||||
m_pLinkItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM)));
|
m_pLinkItem = static_cast<SHELLNEW_ITEM *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHELLNEW_ITEM)));
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#ifndef _SHV_ITEM_NEW_H_
|
#ifndef _SHV_ITEM_NEW_H_
|
||||||
#define _SHV_ITEM_NEW_H_
|
#define _SHV_ITEM_NEW_H_
|
||||||
|
|
||||||
|
const WCHAR ShellNewKey[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Discardable\\PostSetup\\ShellNew";
|
||||||
|
|
||||||
class CNewMenu :
|
class CNewMenu :
|
||||||
public CComCoClass<CNewMenu, &CLSID_NewMenu>,
|
public CComCoClass<CNewMenu, &CLSID_NewMenu>,
|
||||||
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
||||||
|
@ -63,6 +65,8 @@ private:
|
||||||
SHELLNEW_ITEM *LoadItem(LPCWSTR pwszExt);
|
SHELLNEW_ITEM *LoadItem(LPCWSTR pwszExt);
|
||||||
void UnloadItem(SHELLNEW_ITEM *pItem);
|
void UnloadItem(SHELLNEW_ITEM *pItem);
|
||||||
void UnloadAllItems();
|
void UnloadAllItems();
|
||||||
|
BOOL CacheItems();
|
||||||
|
BOOL LoadCachedItems();
|
||||||
BOOL LoadAllItems();
|
BOOL LoadAllItems();
|
||||||
UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu);
|
UINT InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu);
|
||||||
SHELLNEW_ITEM *FindItemFromIdOffset(UINT IdOffset);
|
SHELLNEW_ITEM *FindItemFromIdOffset(UINT IdOffset);
|
||||||
|
|
Loading…
Reference in a new issue