ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
August 2015
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
15 participants
301 discussions
Start a n
N
ew thread
[dquintana] 68785: [NTOBJSHEX] * Improve the filenames to better represent their purpose at a glance.
by dquintana@svn.reactos.org
Author: dquintana Date: Fri Aug 21 15:01:04 2015 New Revision: 68785 URL:
http://svn.reactos.org/svn/reactos?rev=68785&view=rev
Log: [NTOBJSHEX] * Improve the filenames to better represent their purpose at a glance. Added: trunk/reactos/dll/shellext/ntobjshex/ntobjenum.cpp - copied, changed from r68784, trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp trunk/reactos/dll/shellext/ntobjshex/ntobjenum.h - copied unchanged from r68784, trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h trunk/reactos/dll/shellext/ntobjshex/ntobjfolder.cpp - copied, changed from r68784, trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp trunk/reactos/dll/shellext/ntobjshex/ntobjfolder.h - copied unchanged from r68784, trunk/reactos/dll/shellext/ntobjshex/ntobjns.h Removed: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp trunk/reactos/dll/shellext/ntobjshex/ntobjns.h trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h Modified: trunk/reactos/dll/shellext/ntobjshex/CMakeLists.txt trunk/reactos/dll/shellext/ntobjshex/precomp.h trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp Modified: trunk/reactos/dll/shellext/ntobjshex/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/CMa…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/CMakeLists.txt [iso-8859-1] Fri Aug 21 15:01:04 2015 @@ -15,9 +15,9 @@ spec2def(ntobjshex.dll ntobjshex.spec) add_library(ntobjshex SHARED - ntobjns.cpp + ntobjenum.cpp + ntobjfolder.cpp ntobjshex.cpp - ntobjutil.cpp ntobjshex.rc regfolder.cpp ${CMAKE_CURRENT_BINARY_DIR}/ntobjshex.def) Copied: trunk/reactos/dll/shellext/ntobjshex/ntobjenum.cpp (from r68784, trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp) URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjenum.cpp [iso-8859-1] Fri Aug 21 15:01:04 2015 @@ -18,7 +18,7 @@ #include <precomp.h> -#include "ntobjutil.h" +#include "ntobjenum.h" #include <strsafe.h> WINE_DEFAULT_DEBUG_CHANNEL(ntobjshex); Copied: trunk/reactos/dll/shellext/ntobjshex/ntobjfolder.cpp (from r68784, trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp) URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjfolder.cpp [iso-8859-1] Fri Aug 21 15:01:04 2015 @@ -7,7 +7,7 @@ */ #include "precomp.h" -#include "ntobjutil.h" +#include "ntobjenum.h" #include <ntquery.h> #include "util.h" Removed: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp (removed) @@ -1,1044 +0,0 @@ -/* - * PROJECT: ReactOS shell extensions - * LICENSE: GPL - See COPYING in the top level directory - * FILE: dll\shellext\ntobjshex\ntobjns.cpp - * PURPOSE: NT Object Namespace shell extension - * PROGRAMMERS: David Quintana <gigaherz(a)gmail.com> - */ - -#include "precomp.h" -#include "ntobjutil.h" -#include <ntquery.h> -#include "util.h" - -#define DFM_MERGECONTEXTMENU 1 // uFlags LPQCMINFO -#define DFM_INVOKECOMMAND 2 // idCmd pszArgs -#define DFM_INVOKECOMMANDEX 12 // idCmd PDFMICS -#define DFM_GETDEFSTATICID 14 // idCmd * 0 - -#define SHCIDS_ALLFIELDS 0x80000000L -#define SHCIDS_CANONICALONLY 0x10000000L - -#define GET_SHGDN_FOR(dwFlags) ((DWORD)dwFlags & (DWORD)0x0000FF00) -#define GET_SHGDN_RELATION(dwFlags) ((DWORD)dwFlags & (DWORD)0x000000FF) - -WINE_DEFAULT_DEBUG_CHANNEL(ntobjshex); - -// {845B0FB2-66E0-416B-8F91-314E23F7C12D} -const GUID CLSID_NtObjectFolder = { 0x845b0fb2, 0x66e0, 0x416b, { 0x8f, 0x91, 0x31, 0x4e, 0x23, 0xf7, 0xc1, 0x2d } }; - -// {F4C430C3-3A8D-4B56-A018-E598DA60C2E0} -static const GUID GUID_NtObjectColumns = { 0xf4c430c3, 0x3a8d, 0x4b56, { 0xa0, 0x18, 0xe5, 0x98, 0xda, 0x60, 0xc2, 0xe0 } }; - -enum NtObjectColumns -{ - NTOBJECT_COLUMN_NAME = 0, - NTOBJECT_COLUMN_TYPE, - NTOBJECT_COLUMN_LINKTARGET, - NTOBJECT_COLUMN_END -}; - -class CNtObjectFolderExtractIcon : - public CComObjectRootEx<CComMultiThreadModelNoCS>, - public IExtractIconW -{ - PCITEMID_CHILD m_pcidlChild; - LPCWSTR m_NtPath; - -public: - CNtObjectFolderExtractIcon() : - m_pcidlChild(NULL), m_NtPath(NULL) - { - - } - - virtual ~CNtObjectFolderExtractIcon() - { - if (m_pcidlChild) - ILFree((LPITEMIDLIST) m_pcidlChild); - } - - HRESULT Initialize(LPCWSTR ntPath, UINT cidl, PCUITEMID_CHILD_ARRAY apidl) - { - m_NtPath = ntPath; - if (cidl != 1) - return E_INVALIDARG; - m_pcidlChild = ILClone(apidl[0]); - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE GetIconLocation( - UINT uFlags, - LPWSTR szIconFile, - UINT cchMax, - INT *piIndex, - UINT *pwFlags) - { - const NtPidlEntry * entry = (NtPidlEntry *) m_pcidlChild; - - if ((entry->cb < sizeof(NtPidlEntry)) || (entry->magic != NT_OBJECT_PIDL_MAGIC)) - return E_INVALIDARG; - - UINT flags = 0; - - switch (entry->objectType) - { - case DIRECTORY_OBJECT: - case SYMBOLICLINK_OBJECT: - GetModuleFileNameW(g_hInstance, szIconFile, cchMax); - *piIndex = -((uFlags & GIL_OPENICON) ? IDI_NTOBJECTDIROPEN : IDI_NTOBJECTDIR); - *pwFlags = flags; - return S_OK; - case DEVICE_OBJECT: - GetModuleFileNameW(g_hInstance, szIconFile, cchMax); - *piIndex = -IDI_NTOBJECTDEVICE; - *pwFlags = flags; - return S_OK; - case PORT_OBJECT: - GetModuleFileNameW(g_hInstance, szIconFile, cchMax); - *piIndex = -IDI_NTOBJECTPORT; - *pwFlags = flags; - return S_OK; - case KEY_OBJECT: - GetModuleFileNameW(g_hInstance, szIconFile, cchMax); - *piIndex = -IDI_REGISTRYKEY; - *pwFlags = flags; - return S_OK; - default: - GetModuleFileNameW(g_hInstance, szIconFile, cchMax); - *piIndex = -IDI_NTOBJECTITEM; - *pwFlags = flags; - return S_OK; - } - } - - virtual HRESULT STDMETHODCALLTYPE Extract( - LPCWSTR pszFile, - UINT nIconIndex, - HICON *phiconLarge, - HICON *phiconSmall, - UINT nIconSize) - { - return SHDefExtractIconW(pszFile, nIconIndex, 0, phiconLarge, phiconSmall, nIconSize); - } - - DECLARE_NOT_AGGREGATABLE(CNtObjectFolderExtractIcon) - DECLARE_PROTECT_FINAL_CONSTRUCT() - - BEGIN_COM_MAP(CNtObjectFolderExtractIcon) - COM_INTERFACE_ENTRY_IID(IID_IExtractIconW, IExtractIconW) - END_COM_MAP() - -}; - -class CNtObjectPidlManager -{ -private: - PWSTR m_ntPath; - -public: - CNtObjectPidlManager() : - m_ntPath(NULL) - { - } - - ~CNtObjectPidlManager() - { - } - - HRESULT Initialize(PWSTR ntPath) - { - m_ntPath = ntPath; - - return S_OK; - } - - static HRESULT CompareIDs(LPARAM lParam, const NtPidlEntry * first, const NtPidlEntry * second) - { - if ((lParam & 0xFFFF0000) == SHCIDS_ALLFIELDS) - { - if (lParam != 0) - return E_INVALIDARG; - - int minsize = min(first->cb, second->cb); - int ord = memcmp(second, first, minsize); - - if (ord != 0) - return MAKE_HRESULT(0, 0, (USHORT) ord); - - if (second->cb > first->cb) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (second->cb < first->cb) - return MAKE_HRESULT(0, 0, (USHORT) -1); - } - else - { - bool canonical = ((lParam & 0xFFFF0000) == SHCIDS_CANONICALONLY); - - switch (lParam & 0xFFFF) - { - case NTOBJECT_COLUMN_NAME: - { - bool f1 = (first->objectType == KEY_OBJECT) || (first->objectType == DIRECTORY_OBJECT); - bool f2 = (second->objectType == KEY_OBJECT) || (second->objectType == DIRECTORY_OBJECT); - - if (f1 && !f2) - return MAKE_HRESULT(0, 0, (USHORT) -1); - if (f2 && !f1) - return MAKE_HRESULT(0, 0, (USHORT) 1); - - if (canonical) - { - // Shortcut: avoid comparing contents if not necessary when the results are not for display. - if (second->entryNameLength > first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (second->entryNameLength < first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - int minlength = min(first->entryNameLength, second->entryNameLength); - if (minlength > 0) - { - int ord = memcmp(first->entryName, second->entryName, minlength); - if (ord != 0) - return MAKE_HRESULT(0, 0, (USHORT) ord); - } - return S_OK; - } - else - { - int minlength = min(first->entryNameLength, second->entryNameLength); - if (minlength > 0) - { - int ord = StrCmpNW(first->entryName, second->entryName, minlength / sizeof(WCHAR)); - if (ord != 0) - return MAKE_HRESULT(0, 0, (USHORT) ord); - } - - if (second->entryNameLength > first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (second->entryNameLength < first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - return S_OK; - } - } - case NTOBJECT_COLUMN_TYPE: - { - int ord = second->objectType - first->objectType; - if (ord > 0) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (ord < 0) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - return S_OK; - } - case NTOBJECT_COLUMN_LINKTARGET: - { - // Can't sort by value - return E_INVALIDARG; - } - default: - { - DbgPrint("Unsupported sorting mode.\n"); - return E_INVALIDARG; - } - } - } - - return E_INVALIDARG; - } - - static HRESULT CompareIDs(LPARAM lParam, const NtPidlEntry * first, LPCITEMIDLIST pcidl) - { - LPCITEMIDLIST p = pcidl; - NtPidlEntry * second = (NtPidlEntry*) &(p->mkid); - if ((second->cb < sizeof(NtPidlEntry)) || (second->magic != NT_OBJECT_PIDL_MAGIC)) - return E_INVALIDARG; - - return CompareIDs(lParam, first, second); - } - - static HRESULT CompareIDs(LPARAM lParam, LPCITEMIDLIST pcidl1, LPCITEMIDLIST pcidl2) - { - LPCITEMIDLIST p = pcidl1; - NtPidlEntry * first = (NtPidlEntry*) &(p->mkid); - if ((first->cb < sizeof(NtPidlEntry)) || (first->magic != NT_OBJECT_PIDL_MAGIC)) - return E_INVALIDARG; - - return CompareIDs(lParam, first, pcidl2); - } - - static ULONG ConvertAttributes(const NtPidlEntry * entry, PULONG inMask) - { - ULONG mask = inMask ? *inMask : 0xFFFFFFFF; - ULONG flags = SFGAO_HASPROPSHEET | SFGAO_CANLINK; - - if (entry->objectType == DIRECTORY_OBJECT) - flags |= SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_BROWSABLE; - - if (entry->objectType == SYMBOLICLINK_OBJECT) - flags |= SFGAO_LINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_BROWSABLE; - - if (entry->objectType == KEY_OBJECT) - flags |= SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_BROWSABLE; - - return flags & mask; - } - - BOOL IsFolder(LPCITEMIDLIST pcidl) - { - NtPidlEntry * entry = (NtPidlEntry*) &(pcidl->mkid); - if ((entry->cb < sizeof(NtPidlEntry)) || (entry->magic != NT_OBJECT_PIDL_MAGIC)) - return FALSE; - - return (entry->objectType == DIRECTORY_OBJECT) || - (entry->objectType == SYMBOLICLINK_OBJECT) || - (entry->objectType == KEY_OBJECT); - } - - HRESULT GetInfoFromPidl(LPCITEMIDLIST pcidl, const NtPidlEntry ** pentry) - { - NtPidlEntry * entry = (NtPidlEntry*) &(pcidl->mkid); - - if (entry->cb < sizeof(NtPidlEntry)) - { - DbgPrint("PCIDL too small %l (required %l)\n", entry->cb, sizeof(NtPidlEntry)); - return E_INVALIDARG; - } - - if (entry->magic != NT_OBJECT_PIDL_MAGIC) - { - DbgPrint("PCIDL magic mismatch %04x (expected %04x)\n", entry->magic, NT_OBJECT_PIDL_MAGIC); - return E_INVALIDARG; - } - - *pentry = entry; - return S_OK; - } -}; - -//----------------------------------------------------------------------------- -// CNtObjectFolder - -CNtObjectFolder::CNtObjectFolder() : - m_PidlManager(NULL), - m_shellPidl(NULL) -{ -} - -CNtObjectFolder::~CNtObjectFolder() -{ - if (m_shellPidl) - ILFree(m_shellPidl); - if (m_PidlManager) - delete m_PidlManager; -} - -// IShellFolder -HRESULT STDMETHODCALLTYPE CNtObjectFolder::ParseDisplayName( - HWND hwndOwner, - LPBC pbcReserved, - LPOLESTR lpszDisplayName, - ULONG *pchEaten, - LPITEMIDLIST *ppidl, - ULONG *pdwAttributes) -{ - if (!ppidl) - return E_POINTER; - - if (pchEaten) - *pchEaten = 0; - - if (pdwAttributes) - *pdwAttributes = 0; - - TRACE("CNtObjectFolder::ParseDisplayName name=%S (ntPath=%S)\n", lpszDisplayName, m_NtPath); - - const NtPidlEntry * info; - IEnumIDList * it; - HRESULT hr = GetEnumNTDirectory(m_NtPath, &it); - if (FAILED(hr)) - return hr; - - while (TRUE) - { - hr = it->Next(1, ppidl, NULL); - - if (FAILED(hr)) - return hr; - - if (hr != S_OK) - break; - - hr = m_PidlManager->GetInfoFromPidl(*ppidl, &info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (StrCmpW(info->entryName, lpszDisplayName) == 0) - break; - } - - if (hr != S_OK) - { - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - - if (pchEaten || pdwAttributes) - { - if (pchEaten) - *pchEaten = wcslen(info->entryName); - - if (pdwAttributes) - *pdwAttributes = m_PidlManager->ConvertAttributes(info, pdwAttributes); - } - - return S_OK; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::EnumObjects( - HWND hwndOwner, - SHCONTF grfFlags, - IEnumIDList **ppenumIDList) -{ - return GetEnumNTDirectory(m_NtPath, ppenumIDList); -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::BindToObject( - LPCITEMIDLIST pidl, - LPBC pbcReserved, - REFIID riid, - void **ppvOut) -{ - const NtPidlEntry * info; - - if (IsEqualIID(riid, IID_IShellFolder)) - { - HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - WCHAR path[MAX_PATH]; - - StringCbCopyW(path, _countof(path), m_NtPath); - - PathAppendW(path, info->entryName); - - LPITEMIDLIST first = ILCloneFirst(pidl); - LPCITEMIDLIST rest = ILGetNext(pidl); - - LPITEMIDLIST fullPidl = ILCombine(m_shellPidl, first); - - if (info->objectType == SYMBOLICLINK_OBJECT) - { - WCHAR wbLink[MAX_PATH] = { 0 }; - UNICODE_STRING link; - RtlInitEmptyUnicodeString(&link, wbLink, sizeof(wbLink)); - - hr = GetNTObjectSymbolicLinkTarget(m_NtPath, info->entryName, &link); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (link.Length > 0) - { - if (link.Buffer[1] == L':' && isalphaW(link.Buffer[0])) - { - CComPtr<IShellFolder> psfDesktop; - hr = SHGetDesktopFolder(&psfDesktop); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - hr = psfDesktop->ParseDisplayName(NULL, NULL, path, NULL, &first, NULL); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - return psfDesktop->BindToObject(rest, pbcReserved, riid, ppvOut); - } - - StringCbCopyW(path, _countof(path), L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{845B0FB2-66E0-416B-8F91-314E23F7C12D}"); - PathAppend(path, link.Buffer); - - CComPtr<IShellFolder> psfDesktop; - hr = SHGetDesktopFolder(&psfDesktop); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - hr = psfDesktop->ParseDisplayName(NULL, NULL, path, NULL, &first, NULL); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - } - else - { - return E_UNEXPECTED; - } - } - - CComPtr<IShellFolder> psfChild; - - if (info->objectType == KEY_OBJECT) - { - hr = ShellObjectCreatorInit<CRegistryFolder>(fullPidl, path, (HKEY) NULL, IID_PPV_ARG(IShellFolder, &psfChild)); - } - else - { - hr = ShellObjectCreatorInit<CNtObjectFolder>(fullPidl, path, IID_PPV_ARG(IShellFolder, &psfChild)); - } - - ILFree(fullPidl); - ILFree(first); - - if (rest->mkid.cb > 0) - { - return psfChild->BindToObject(rest, pbcReserved, riid, ppvOut); - } - - return psfChild->QueryInterface(riid, ppvOut); - } - - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::BindToStorage( - LPCITEMIDLIST pidl, - LPBC pbcReserved, - REFIID riid, - void **ppvObj) -{ - UNIMPLEMENTED; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::CompareIDs( - LPARAM lParam, - LPCITEMIDLIST pidl1, - LPCITEMIDLIST pidl2) -{ - TRACE("CompareIDs\n"); - - HRESULT hr = m_PidlManager->CompareIDs(lParam, pidl1, pidl2); - if (hr != S_OK) - return hr; - - LPCITEMIDLIST rest1 = ILGetNext(pidl1); - LPCITEMIDLIST rest2 = ILGetNext(pidl2); - - bool hasNext1 = (rest1->mkid.cb > 0); - bool hasNext2 = (rest2->mkid.cb > 0); - - if (hasNext1 || hasNext2) - { - if (hasNext1 && !hasNext2) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - if (hasNext2 && !hasNext1) - return MAKE_HRESULT(0, 0, (USHORT) 1); - - LPCITEMIDLIST first1 = ILCloneFirst(pidl1); - - CComPtr<IShellFolder> psfNext; - hr = BindToObject(first1, NULL, IID_PPV_ARG(IShellFolder, &psfNext)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - return psfNext->CompareIDs(lParam, rest1, rest2); - } - - return S_OK; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::CreateViewObject( - HWND hwndOwner, - REFIID riid, - void **ppvOut) -{ - if (!IsEqualIID(riid, IID_IShellView)) - return E_NOINTERFACE; - - SFV_CREATE sfv; - sfv.cbSize = sizeof(sfv); - sfv.pshf = this; - sfv.psvOuter = NULL; - sfv.psfvcb = this; - - return SHCreateShellFolderView(&sfv, (IShellView**) ppvOut); -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetAttributesOf( - UINT cidl, - PCUITEMID_CHILD_ARRAY apidl, - SFGAOF *rgfInOut) -{ - const NtPidlEntry * info; - - TRACE("GetAttributesOf %d\n", cidl); - - if (cidl == 0) - { - *rgfInOut &= SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_BROWSABLE; - return S_OK; - } - - for (int i = 0; i < (int) cidl; i++) - { - PCUITEMID_CHILD pidl = apidl[i]; - - HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - // Update attributes. - *rgfInOut = m_PidlManager->ConvertAttributes(info, rgfInOut); - } - - return S_OK; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetUIObjectOf( - HWND hwndOwner, - UINT cidl, - PCUITEMID_CHILD_ARRAY apidl, - REFIID riid, - UINT *prgfInOut, - void **ppvOut) -{ - DWORD res; - TRACE("GetUIObjectOf\n"); - - if (IsEqualIID(riid, IID_IContextMenu) || - IsEqualIID(riid, IID_IContextMenu2) || - IsEqualIID(riid, IID_IContextMenu3)) - { - CComPtr<IContextMenu> pcm; - - HKEY keys[1]; - - int nkeys = _countof(keys); - if (cidl == 1 && m_PidlManager->IsFolder(apidl[0])) - { - res = RegOpenKey(HKEY_CLASSES_ROOT, L"Folder", keys + 0); - if (!NT_SUCCESS(res)) - return HRESULT_FROM_NT(res); - } - else - { - nkeys = 0; - } - - HRESULT hr = CDefFolderMenu_Create2(m_shellPidl, hwndOwner, cidl, apidl, this, DefCtxMenuCallback, nkeys, keys, &pcm); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - return pcm->QueryInterface(riid, ppvOut); - } - - if (IsEqualIID(riid, IID_IExtractIconW)) - { - return ShellObjectCreatorInit<CNtObjectFolderExtractIcon>(m_NtPath, cidl, apidl, riid, ppvOut); - } - - if (IsEqualIID(riid, IID_IDataObject)) - { - return CIDLData_CreateFromIDArray(m_shellPidl, cidl, apidl, (IDataObject**) ppvOut); - } - - if (IsEqualIID(riid, IID_IQueryAssociations)) - { - if (cidl == 1 && m_PidlManager->IsFolder(apidl[0])) - { - CComPtr<IQueryAssociations> pqa; - HRESULT hr = AssocCreate(CLSID_QueryAssociations, IID_PPV_ARG(IQueryAssociations, &pqa)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - hr = pqa->Init(ASSOCF_INIT_DEFAULTTOFOLDER, L"NTObjShEx.NTDirectory", NULL, hwndOwner); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - return pqa->QueryInterface(riid, ppvOut); - } - } - - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDisplayNameOf( - LPCITEMIDLIST pidl, - SHGDNF uFlags, - STRRET *lpName) -{ - const NtPidlEntry * info; - - TRACE("GetDisplayNameOf %p\n", pidl); - - HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if ((GET_SHGDN_RELATION(uFlags) == SHGDN_NORMAL) && - (GET_SHGDN_FOR(uFlags) & SHGDN_FORPARSING)) - { - WCHAR path[MAX_PATH] = { 0 }; - - hr = GetFullName(m_shellPidl, uFlags, path, _countof(path)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - PathAppendW(path, info->entryName); - - hr = MakeStrRetFromString(path, lpName); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - LPCITEMIDLIST pidlFirst = ILCloneFirst(pidl); - LPCITEMIDLIST pidlNext = ILGetNext(pidl); - - if (pidlNext && pidlNext->mkid.cb > 0) - { - CComPtr<IShellFolder> psfChild; - hr = BindToObject(pidlFirst, NULL, IID_PPV_ARG(IShellFolder, &psfChild)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - WCHAR temp[MAX_PATH]; - STRRET childName; - - hr = psfChild->GetDisplayNameOf(pidlNext, uFlags | SHGDN_INFOLDER, &childName); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - hr = StrRetToBufW(&childName, pidlNext, temp, _countof(temp)); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - PathAppendW(path, temp); - } - - ILFree((LPITEMIDLIST) pidlFirst); - } - else - { - MakeStrRetFromString(info->entryName, info->entryNameLength, lpName); - } - - return S_OK; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::SetNameOf( - HWND hwnd, - LPCITEMIDLIST pidl, - LPCOLESTR lpszName, - SHGDNF uFlags, - LPITEMIDLIST *ppidlOut) -{ - UNIMPLEMENTED; - return E_NOTIMPL; -} - -// IPersist -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetClassID(CLSID *lpClassId) -{ - if (!lpClassId) - return E_POINTER; - - *lpClassId = CLSID_NtObjectFolder; - return S_OK; -} - -// IPersistFolder -HRESULT STDMETHODCALLTYPE CNtObjectFolder::Initialize(LPCITEMIDLIST pidl) -{ - m_shellPidl = ILClone(pidl); - - PCWSTR ntPath = L"\\"; - - if (!m_PidlManager) - { - m_PidlManager = new CNtObjectPidlManager(); - - StringCbCopy(m_NtPath, _countof(m_NtPath), ntPath); - } - - return m_PidlManager->Initialize(m_NtPath); -} - -// Internal -HRESULT STDMETHODCALLTYPE CNtObjectFolder::Initialize(LPCITEMIDLIST pidl, PCWSTR ntPath) -{ - m_shellPidl = ILClone(pidl); - - if (!m_PidlManager) - m_PidlManager = new CNtObjectPidlManager(); - - StringCbCopy(m_NtPath, _countof(m_NtPath), ntPath); - return m_PidlManager->Initialize(m_NtPath); -} - -// IPersistFolder2 -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetCurFolder(LPITEMIDLIST * pidl) -{ - if (pidl) - *pidl = ILClone(m_shellPidl); - if (!m_shellPidl) - return S_FALSE; - return S_OK; -} - -// IShellFolder2 -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDefaultSearchGUID( - GUID *lpguid) -{ - UNIMPLEMENTED; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::EnumSearches( - IEnumExtraSearch **ppenum) -{ - UNIMPLEMENTED; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDefaultColumn( - DWORD dwReserved, - ULONG *pSort, - ULONG *pDisplay) -{ - if (pSort) - *pSort = 0; - if (pDisplay) - *pDisplay = 0; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDefaultColumnState( - UINT iColumn, - SHCOLSTATEF *pcsFlags) -{ - switch (iColumn) - { - case NTOBJECT_COLUMN_NAME: - *pcsFlags = SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT; - return S_OK; - case NTOBJECT_COLUMN_TYPE: - *pcsFlags = SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT; - return S_OK; - case NTOBJECT_COLUMN_LINKTARGET: - *pcsFlags = SHCOLSTATE_TYPE_STR | SHCOLSTATE_SLOW; - return S_OK; - } - - return E_INVALIDARG; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDetailsEx( - LPCITEMIDLIST pidl, - const SHCOLUMNID *pscid, - VARIANT *pv) -{ - const NtPidlEntry * info; - - TRACE("GetDetailsEx\n"); - - if (pidl) - { - HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - static const GUID storage = PSGUID_STORAGE; - if (IsEqualGUID(pscid->fmtid, storage)) - { - if (pscid->pid == PID_STG_NAME) - { - return MakeVariantString(pv, info->entryName); - } - else if (pscid->pid == PID_STG_STORAGETYPE) - { - if (info->objectType < 0) - { - NtPidlTypeData * td = (NtPidlTypeData*) (((PBYTE) info) + FIELD_OFFSET(NtPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); - - if (td->typeNameLength > 0) - { - return MakeVariantString(pv, td->typeName); - } - else - { - return MakeVariantString(pv, L"Unknown"); - } - } - else - { - return MakeVariantString(pv, ObjectTypeNames[info->objectType]); - } - } - } - else if (IsEqualGUID(pscid->fmtid, GUID_NtObjectColumns)) - { - if (pscid->pid == NTOBJECT_COLUMN_LINKTARGET && info->objectType == SYMBOLICLINK_OBJECT) - { - WCHAR wbLink[MAX_PATH] = { 0 }; - UNICODE_STRING link; - RtlInitEmptyUnicodeString(&link, wbLink, sizeof(wbLink)); - - HRESULT hr = GetNTObjectSymbolicLinkTarget(m_NtPath, info->entryName, &link); - - if (!FAILED_UNEXPECTEDLY(hr) && link.Length > 0) - { - return MakeVariantString(pv, link.Buffer); - } - } - - V_VT(pv) = VT_EMPTY; - return S_OK; - } - } - - return E_INVALIDARG; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::GetDetailsOf( - LPCITEMIDLIST pidl, - UINT iColumn, - SHELLDETAILS *psd) -{ - const NtPidlEntry * info; - - TRACE("GetDetailsOf\n"); - - if (pidl) - { - HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - switch (iColumn) - { - case NTOBJECT_COLUMN_NAME: - psd->fmt = LVCFMT_LEFT; - - MakeStrRetFromString(info->entryName, info->entryNameLength, &(psd->str)); - return S_OK; - case NTOBJECT_COLUMN_TYPE: - psd->fmt = LVCFMT_LEFT; - - if (info->objectType < 0) - { - NtPidlTypeData * td = (NtPidlTypeData*) (((PBYTE) info) + FIELD_OFFSET(NtPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); - - if (td->typeNameLength > 0) - MakeStrRetFromString(td->typeName, td->typeNameLength, &(psd->str)); - else - MakeStrRetFromString(L"Unknown", &(psd->str)); - } - else - MakeStrRetFromString(ObjectTypeNames[info->objectType], &(psd->str)); - return S_OK; - case NTOBJECT_COLUMN_LINKTARGET: - { - psd->fmt = LVCFMT_LEFT; - - if (info->objectType == SYMBOLICLINK_OBJECT) - { - WCHAR wbLink[MAX_PATH] = { 0 }; - UNICODE_STRING link; - RtlInitEmptyUnicodeString(&link, wbLink, sizeof(wbLink)); - - HRESULT hr = GetNTObjectSymbolicLinkTarget(m_NtPath, info->entryName, &link); - - if (!FAILED_UNEXPECTEDLY(hr) && link.Length > 0) - { - MakeStrRetFromString(link.Buffer, link.Length, &(psd->str)); - return S_OK; - } - } - - MakeStrRetFromString(L"", &(psd->str)); - return S_OK; - } - } - } - else - { - switch (iColumn) - { - case NTOBJECT_COLUMN_NAME: - psd->fmt = LVCFMT_LEFT; - psd->cxChar = 30; - - // TODO: Make localizable - MakeStrRetFromString(L"Object Name", &(psd->str)); - return S_OK; - case NTOBJECT_COLUMN_TYPE: - psd->fmt = LVCFMT_LEFT; - psd->cxChar = 20; - - // TODO: Make localizable - MakeStrRetFromString(L"Object Type", &(psd->str)); - return S_OK; - case NTOBJECT_COLUMN_LINKTARGET: - psd->fmt = LVCFMT_LEFT; - psd->cxChar = 30; - - // TODO: Make localizable - MakeStrRetFromString(L"Symlink Target", &(psd->str)); - return S_OK; - } - } - - return E_INVALIDARG; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::MapColumnToSCID( - UINT iColumn, - SHCOLUMNID *pscid) -{ - static const GUID storage = PSGUID_STORAGE; - switch (iColumn) - { - case NTOBJECT_COLUMN_NAME: - pscid->fmtid = storage; - pscid->pid = PID_STG_NAME; - return S_OK; - case NTOBJECT_COLUMN_TYPE: - pscid->fmtid = storage; - pscid->pid = PID_STG_STORAGETYPE; - return S_OK; - case NTOBJECT_COLUMN_LINKTARGET: - pscid->fmtid = GUID_NtObjectColumns; - pscid->pid = NTOBJECT_COLUMN_LINKTARGET; - return S_OK; - } - return E_INVALIDARG; -} - -HRESULT STDMETHODCALLTYPE CNtObjectFolder::MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch (uMsg) - { - case SFVM_DEFVIEWMODE: - { - FOLDERVIEWMODE* pViewMode = (FOLDERVIEWMODE*) lParam; - *pViewMode = FVM_DETAILS; - return S_OK; - } - case SFVM_COLUMNCLICK: - return S_FALSE; - case SFVM_BACKGROUNDENUM: - return S_OK; - } - return E_NOTIMPL; -} - -HRESULT CNtObjectFolder::DefCtxMenuCallback(IShellFolder * /*psf*/, HWND /*hwnd*/, IDataObject * /*pdtobj*/, UINT uMsg, WPARAM /*wParam*/, LPARAM /*lParam*/) -{ - switch (uMsg) - { - case DFM_MERGECONTEXTMENU: - return S_OK; - case DFM_INVOKECOMMAND: - case DFM_INVOKECOMMANDEX: - case DFM_GETDEFSTATICID: // Required for Windows 7 to pick a default - return S_FALSE; - } - return E_NOTIMPL; -} Removed: trunk/reactos/dll/shellext/ntobjshex/ntobjns.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjns.h [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjns.h (removed) @@ -1,155 +0,0 @@ -/* - * PROJECT: ReactOS shell extensions - * LICENSE: GPL - See COPYING in the top level directory - * FILE: dll\shellext\ntobjshex\ntobjns.h - * PURPOSE: NT Object Namespace shell extension - * PROGRAMMERS: David Quintana <gigaherz(a)gmail.com> - */ -#pragma once - -extern const GUID CLSID_NtObjectFolder; - -class CNtObjectPidlManager; - -class CNtObjectFolder : - public CComCoClass<CNtObjectFolder, &CLSID_NtObjectFolder>, - public CComObjectRootEx<CComMultiThreadModelNoCS>, - public IShellFolder2, - public IPersistFolder2, - public IShellFolderViewCB -{ - CNtObjectPidlManager * m_PidlManager; - - WCHAR m_NtPath[MAX_PATH]; - - LPITEMIDLIST m_shellPidl; - -public: - - CNtObjectFolder(); - virtual ~CNtObjectFolder(); - - CNtObjectPidlManager& GetManager() { return *m_PidlManager; } - - // IShellFolder - virtual HRESULT STDMETHODCALLTYPE ParseDisplayName( - HWND hwndOwner, - LPBC pbcReserved, - LPOLESTR lpszDisplayName, - ULONG *pchEaten, - LPITEMIDLIST *ppidl, - ULONG *pdwAttributes); - - virtual HRESULT STDMETHODCALLTYPE EnumObjects( - HWND hwndOwner, - SHCONTF grfFlags, - IEnumIDList **ppenumIDList); - - virtual HRESULT STDMETHODCALLTYPE BindToObject( - LPCITEMIDLIST pidl, - LPBC pbcReserved, - REFIID riid, - void **ppvOut); - - virtual HRESULT STDMETHODCALLTYPE BindToStorage( - LPCITEMIDLIST pidl, - LPBC pbcReserved, - REFIID riid, - void **ppvObj); - - virtual HRESULT STDMETHODCALLTYPE CompareIDs( - LPARAM lParam, - LPCITEMIDLIST pidl1, - LPCITEMIDLIST pidl2); - - virtual HRESULT STDMETHODCALLTYPE CreateViewObject( - HWND hwndOwner, - REFIID riid, - void **ppvOut); - - virtual HRESULT STDMETHODCALLTYPE GetAttributesOf( - UINT cidl, - PCUITEMID_CHILD_ARRAY apidl, - SFGAOF *rgfInOut); - - virtual HRESULT STDMETHODCALLTYPE GetUIObjectOf( - HWND hwndOwner, - UINT cidl, - PCUITEMID_CHILD_ARRAY apidl, - REFIID riid, - UINT *prgfInOut, - void **ppvOut); - - virtual HRESULT STDMETHODCALLTYPE GetDisplayNameOf( - LPCITEMIDLIST pidl, - SHGDNF uFlags, - STRRET *lpName); - - virtual HRESULT STDMETHODCALLTYPE SetNameOf( - HWND hwnd, - LPCITEMIDLIST pidl, - LPCOLESTR lpszName, - SHGDNF uFlags, - LPITEMIDLIST *ppidlOut); - - // IShellFolder2 - virtual HRESULT STDMETHODCALLTYPE GetDefaultSearchGUID( - GUID *lpguid); - - virtual HRESULT STDMETHODCALLTYPE EnumSearches( - IEnumExtraSearch **ppenum); - - virtual HRESULT STDMETHODCALLTYPE GetDefaultColumn( - DWORD dwReserved, - ULONG *pSort, - ULONG *pDisplay); - - virtual HRESULT STDMETHODCALLTYPE GetDefaultColumnState( - UINT iColumn, - SHCOLSTATEF *pcsFlags); - - virtual HRESULT STDMETHODCALLTYPE GetDetailsEx( - LPCITEMIDLIST pidl, - const SHCOLUMNID *pscid, - VARIANT *pv); - - virtual HRESULT STDMETHODCALLTYPE GetDetailsOf( - LPCITEMIDLIST pidl, - UINT iColumn, - SHELLDETAILS *psd); - - virtual HRESULT STDMETHODCALLTYPE MapColumnToSCID( - UINT iColumn, - SHCOLUMNID *pscid); - - // IPersist - virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *lpClassId); - - // IPersistFolder - virtual HRESULT STDMETHODCALLTYPE Initialize(LPCITEMIDLIST pidl); - - // IPersistFolder2 - virtual HRESULT STDMETHODCALLTYPE GetCurFolder(LPITEMIDLIST * pidl); - - // IShellFolderViewCB - virtual HRESULT STDMETHODCALLTYPE MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam); - - // Internal - HRESULT STDMETHODCALLTYPE Initialize(LPCITEMIDLIST pidl, PCWSTR ntPath); - - static HRESULT CALLBACK DefCtxMenuCallback(IShellFolder *, HWND, IDataObject *, UINT, WPARAM, LPARAM); - - DECLARE_REGISTRY_RESOURCEID(IDR_NTOBJECTFOLDER) - DECLARE_NOT_AGGREGATABLE(CNtObjectFolder) - DECLARE_PROTECT_FINAL_CONSTRUCT() - - BEGIN_COM_MAP(CNtObjectFolder) - COM_INTERFACE_ENTRY_IID(IID_IShellFolder, IShellFolder) - COM_INTERFACE_ENTRY_IID(IID_IShellFolder2, IShellFolder2) - COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist) - COM_INTERFACE_ENTRY_IID(IID_IPersistFolder, IPersistFolder) - COM_INTERFACE_ENTRY_IID(IID_IPersistFolder2, IPersistFolder2) - COM_INTERFACE_ENTRY_IID(IID_IShellFolderViewCB, IShellFolderViewCB) - END_COM_MAP() - -}; Removed: trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp (removed) @@ -1,744 +0,0 @@ -/* - * Copyright 2004, 2005 Martin Fuchs - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <precomp.h> - -#include "ntobjutil.h" -#include <strsafe.h> - -WINE_DEFAULT_DEBUG_CHANNEL(ntobjshex); - -static struct RootKeyEntry { - HKEY key; - PCWSTR keyName; -} RootKeys [] = { - { HKEY_CLASSES_ROOT, L"HKEY_CLASSES_ROOT" }, - { HKEY_CURRENT_USER, L"HKEY_CURRENT_USER" }, - { HKEY_LOCAL_MACHINE, L"HKEY_LOCAL_MACHINE" }, - { HKEY_USERS, L"HKEY_USERS" }, - { HKEY_CURRENT_CONFIG, L"HKEY_CURRENT_CONFIG" } -}; - -typedef NTSTATUS(__stdcall* pfnNtGenericOpen)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES); -typedef NTSTATUS(__stdcall* pfnNtOpenFile)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, ULONG, ULONG); - -const LPCWSTR ObjectTypeNames [] = { - L"Directory", L"SymbolicLink", - L"Mutant", L"Section", L"Event", L"Semaphore", - L"Timer", L"Key", L"EventPair", L"IoCompletion", - L"Device", L"File", L"Controller", L"Profile", - L"Type", L"Desktop", L"WindowStatiom", L"Driver", - L"Token", L"Process", L"Thread", L"Adapter", L"Port", - 0 -}; - -const LPCWSTR RegistryTypeNames [] = { - L"REG_NONE", - L"REG_SZ", - L"REG_EXPAND_SZ", - L"REG_BINARY", - L"REG_DWORD", - L"REG_DWORD_BIG_ENDIAN", - L"REG_LINK", - L"REG_MULTI_SZ", - L"REG_RESOURCE_LIST", - L"REG_FULL_RESOURCE_DESCRIPTOR", - L"REG_RESOURCE_REQUIREMENTS_LIST ", - L"REG_QWORD" -}; - -static DWORD NtOpenObject(OBJECT_TYPE type, PHANDLE phandle, DWORD access, LPCWSTR path) -{ - UNICODE_STRING ustr; - - RtlInitUnicodeString(&ustr, path); - - OBJECT_ATTRIBUTES open_struct = { sizeof(OBJECT_ATTRIBUTES), 0x00, &ustr, 0x40 }; - - if (type != FILE_OBJECT) - access |= STANDARD_RIGHTS_READ; - - IO_STATUS_BLOCK ioStatusBlock; - - switch (type) - { - case DIRECTORY_OBJECT: return NtOpenDirectoryObject(phandle, access, &open_struct); - case SYMBOLICLINK_OBJECT: return NtOpenSymbolicLinkObject(phandle, access, &open_struct); - case MUTANT_OBJECT: return NtOpenMutant(phandle, access, &open_struct); - case SECTION_OBJECT: return NtOpenSection(phandle, access, &open_struct); - case EVENT_OBJECT: return NtOpenEvent(phandle, access, &open_struct); - case SEMAPHORE_OBJECT: return NtOpenSemaphore(phandle, access, &open_struct); - case TIMER_OBJECT: return NtOpenTimer(phandle, access, &open_struct); - case KEY_OBJECT: return NtOpenKey(phandle, access, &open_struct); - case EVENTPAIR_OBJECT: return NtOpenEventPair(phandle, access, &open_struct); - case IOCOMPLETITION_OBJECT: return NtOpenIoCompletion(phandle, access, &open_struct); - case FILE_OBJECT: return NtOpenFile(phandle, access, &open_struct, &ioStatusBlock, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0); - default: - return ERROR_INVALID_FUNCTION; - } -} - -OBJECT_TYPE MapTypeNameToType(LPCWSTR TypeName, DWORD cbTypeName) -{ - if (!TypeName) - return UNKNOWN_OBJECT_TYPE; - - for (UINT i = 0; i < _countof(ObjectTypeNames); i++) - { - LPCWSTR typeName = ObjectTypeNames[i]; - if (!StrCmpNW(typeName, TypeName, cbTypeName / sizeof(WCHAR))) - { - return (OBJECT_TYPE) i; - } - } - - return UNKNOWN_OBJECT_TYPE; -} - -HRESULT ReadRegistryValue(HKEY root, PCWSTR path, PCWSTR valueName, PVOID * valueData, PDWORD valueLength) -{ - HKEY hkey; - - DWORD res; - if (root) - { - res = RegOpenKeyExW(root, *path == '\\' ? path + 1 : path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, &hkey); - } - else - { - res = NtOpenObject(KEY_OBJECT, (PHANDLE) &hkey, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, path); - } - if (!NT_SUCCESS(res)) - { - ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); - return HRESULT_FROM_NT(res); - } - - res = RegQueryValueExW(hkey, valueName, NULL, NULL, NULL, valueLength); - if (!NT_SUCCESS(res)) - { - ERR("RegQueryValueExW failed for path %S with status=%x\n", path, res); - return HRESULT_FROM_NT(res); - } - - if (*valueLength > 0) - { - PBYTE data = (PBYTE) CoTaskMemAlloc(*valueLength);; - *valueData = data; - - res = RegQueryValueExW(hkey, valueName, NULL, NULL, data, valueLength); - if (!NT_SUCCESS(res)) - { - CoTaskMemFree(data); - *valueData = NULL; - - RegCloseKey(hkey); - - ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); - return HRESULT_FROM_NT(res); - } - } - else - { - *valueData = NULL; - } - - RegCloseKey(hkey); - - return S_OK; -} - -HRESULT GetNTObjectSymbolicLinkTarget(LPCWSTR path, LPCWSTR entryName, PUNICODE_STRING LinkTarget) -{ - HANDLE handle; - WCHAR buffer[MAX_PATH]; - LPWSTR pend = buffer; - - StringCbCopyExW(buffer, sizeof(buffer), path, &pend, NULL, 0); - - if (pend[-1] != '\\') - *pend++ = '\\'; - - StringCbCatW(buffer, sizeof(buffer), entryName); - - DbgPrint("GetNTObjectSymbolicLinkTarget %d\n", buffer); - - LinkTarget->Length = 0; - - DWORD err = NtOpenObject(SYMBOLICLINK_OBJECT, &handle, 0, buffer); - if (!NT_SUCCESS(err)) - return HRESULT_FROM_NT(err); - - err = NT_SUCCESS(NtQuerySymbolicLinkObject(handle, LinkTarget, NULL)); - if (!NT_SUCCESS(err)) - return HRESULT_FROM_NT(err); - - NtClose(handle); - - return S_OK; -} - -class CEnumRegRoot : - public CComObjectRootEx<CComMultiThreadModelNoCS>, - public IEnumIDList -{ - UINT m_idx; - -public: - CEnumRegRoot() - : m_idx(0) - { - } - - ~CEnumRegRoot() - { - } - - HRESULT EnumerateNext(LPITEMIDLIST* ppidl) - { - if (m_idx >= _countof(RootKeys)) - return S_FALSE; - - RootKeyEntry& key = RootKeys[m_idx++]; - - PCWSTR name = key.keyName; - DWORD cchName = wcslen(name); - - REG_ENTRY_TYPE otype = REG_ENTRY_ROOT; - - DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); - - // allocate space for the terminator - entryBufferLength += 2; - - RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength); - if (!entry) - return E_OUTOFMEMORY; - - memset(entry, 0, entryBufferLength); - - entry->cb = FIELD_OFFSET(RegPidlEntry, entryName); - entry->magic = REGISTRY_PIDL_MAGIC; - entry->entryType = otype; - entry->rootKey = key.key; - - if (cchName > 0) - { - entry->entryNameLength = cchName * sizeof(WCHAR); - StringCbCopyNW(entry->entryName, entryBufferLength, name, entry->entryNameLength); - entry->cb += entry->entryNameLength + sizeof(WCHAR); - } - else - { - entry->entryNameLength = 0; - entry->entryName[0] = 0; - entry->cb += sizeof(WCHAR); - } - - *ppidl = (LPITEMIDLIST) entry; - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) - { - if (pceltFetched) - *pceltFetched = 0; - - while (celt-- > 0) - { - HRESULT hr = EnumerateNext(rgelt); - if (hr != S_OK) - return hr; - - if (pceltFetched) - (*pceltFetched)++; - if (rgelt) - rgelt++; - } - - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) - { - while (celt > 0) - { - HRESULT hr = EnumerateNext(NULL); - if (FAILED(hr)) - return hr; - if (hr != S_OK) - break; - } - - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Reset() - { - return E_NOTIMPL; - } - - virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) - { - return E_NOTIMPL; - } - - DECLARE_NOT_AGGREGATABLE(CEnumRegRoot) - DECLARE_PROTECT_FINAL_CONSTRUCT() - - BEGIN_COM_MAP(CEnumRegRoot) - COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) - END_COM_MAP() - -}; - -class CEnumRegKey : - public CComObjectRootEx<CComMultiThreadModelNoCS>, - public IEnumIDList -{ - PCWSTR m_path; - HKEY m_hkey; - BOOL m_values; - int m_idx; - -public: - CEnumRegKey() - : m_path(NULL), m_hkey(NULL), m_values(FALSE), m_idx(0) - { - } - - ~CEnumRegKey() - { - RegCloseKey(m_hkey); - } - - HRESULT Initialize(PCWSTR path, HKEY root) - { - m_path = path; - - DWORD res; - if (root) - { - res = RegOpenKeyExW(root, *path == '\\' ? path + 1 : path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &m_hkey); - } - else - { - res = NtOpenObject(KEY_OBJECT, (PHANDLE) &m_hkey, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, path); - } - if (!NT_SUCCESS(res)) - { - ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); - return HRESULT_FROM_NT(res); - } - - return S_OK; - } - - HRESULT NextKey(LPITEMIDLIST* ppidl) - { - WCHAR name[MAX_PATH]; - DWORD cchName = _countof(name); - - WCHAR className[MAX_PATH]; - DWORD cchClass = _countof(className); - - if (RegEnumKeyExW(m_hkey, m_idx++, name, &cchName, 0, className, &cchClass, NULL)) - return S_FALSE; - - name[cchName] = 0; - className[cchClass] = 0; - - REG_ENTRY_TYPE otype = REG_ENTRY_KEY; - - DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); - - if (cchClass > 0) - { - entryBufferLength += sizeof(WCHAR) + cchClass * sizeof(WCHAR); - } - - // allocate space for the terminator - entryBufferLength += 2; - - RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength); - if (!entry) - return E_OUTOFMEMORY; - - memset(entry, 0, entryBufferLength); - - entry->cb = FIELD_OFFSET(RegPidlEntry, entryName); - entry->magic = REGISTRY_PIDL_MAGIC; - entry->entryType = otype; - - if (cchName > 0) - { - entry->entryNameLength = cchName * sizeof(WCHAR); - StringCbCopyNW(entry->entryName, entryBufferLength, name, entry->entryNameLength); - entry->cb += entry->entryNameLength + sizeof(WCHAR); - } - else - { - entry->entryNameLength = 0; - entry->entryName[0] = 0; - entry->cb += sizeof(WCHAR); - } - - if (cchClass) - { - PWSTR contentData = (PWSTR) ((PBYTE) entry + entry->cb); - DWORD remainingSpace = entryBufferLength - entry->cb; - - entry->contentsLength = cchClass * sizeof(WCHAR); - StringCbCopyNW(contentData, remainingSpace, className, entry->contentsLength); - - entry->cb += entry->contentsLength + sizeof(WCHAR); - } - - *ppidl = (LPITEMIDLIST) entry; - return S_OK; - } - - HRESULT NextValue(LPITEMIDLIST* ppidl) - { - WCHAR name[MAX_PATH]; - DWORD cchName = _countof(name); - DWORD type = 0; - DWORD dataSize = 0; - - if (RegEnumValueW(m_hkey, m_idx++, name, &cchName, 0, &type, NULL, &dataSize)) - return S_FALSE; - - REG_ENTRY_TYPE otype = REG_ENTRY_VALUE; - - DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); - - BOOL copyData = dataSize < 32; - if (copyData) - { - entryBufferLength += dataSize + sizeof(WCHAR); - - otype = REG_ENTRY_VALUE_WITH_CONTENT; - } - - RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength + 2); - if (!entry) - return E_OUTOFMEMORY; - - memset(entry, 0, entryBufferLength); - - entry->cb = FIELD_OFFSET(RegPidlEntry, entryName); - entry->magic = REGISTRY_PIDL_MAGIC; - entry->entryType = otype; - entry->contentType = type; - - if (cchName > 0) - { - entry->entryNameLength = cchName * sizeof(WCHAR); - StringCbCopyNW(entry->entryName, entryBufferLength, name, entry->entryNameLength); - entry->cb += entry->entryNameLength + sizeof(WCHAR); - } - else - { - entry->entryNameLength = 0; - entry->entryName[0] = 0; - entry->cb += sizeof(WCHAR); - } - - if (copyData) - { - PBYTE contentData = (PBYTE) ((PBYTE) entry + entry->cb); - - entry->contentsLength = dataSize; - - // In case it's an unterminated string, RegGetValue will add the NULL termination - dataSize += sizeof(WCHAR); - - if (!RegQueryValueExW(m_hkey, name, NULL, NULL, contentData, &dataSize)) - { - entry->cb += entry->contentsLength + sizeof(WCHAR); - } - else - { - entry->contentsLength = 0; - entry->cb += sizeof(WCHAR); - } - - } - - *ppidl = (LPITEMIDLIST) entry; - return S_OK; - } - - HRESULT EnumerateNext(LPITEMIDLIST* ppidl) - { - if (!m_values) - { - HRESULT hr = NextKey(ppidl); - if (hr != S_FALSE) - return hr; - - // switch to values. - m_values = TRUE; - m_idx = 0; - } - - return NextValue(ppidl); - } - - virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) - { - if (pceltFetched) - *pceltFetched = 0; - - while (celt-- > 0) - { - HRESULT hr = EnumerateNext(rgelt); - if (hr != S_OK) - return hr; - - if (pceltFetched) - (*pceltFetched)++; - if (rgelt) - rgelt++; - } - - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) - { - while (celt > 0) - { - HRESULT hr = EnumerateNext(NULL); - if (FAILED(hr)) - return hr; - if (hr != S_OK) - break; - } - - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Reset() - { - return E_NOTIMPL; - } - - virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) - { - return E_NOTIMPL; - } - - DECLARE_NOT_AGGREGATABLE(CEnumRegKey) - DECLARE_PROTECT_FINAL_CONSTRUCT() - - BEGIN_COM_MAP(CEnumRegKey) - COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) - END_COM_MAP() -}; - -class CEnumNTDirectory : - public CComObjectRootEx<CComMultiThreadModelNoCS>, - public IEnumIDList -{ - WCHAR buffer[MAX_PATH]; - HANDLE m_directory; - BOOL m_first; - ULONG m_enumContext; - PWSTR m_pend; - -public: - CEnumNTDirectory() - : m_directory(NULL), m_first(TRUE), m_enumContext(0), m_pend(NULL) - { - } - - ~CEnumNTDirectory() - { - NtClose(m_directory); - } - - HRESULT Initialize(PCWSTR path) - { - StringCbCopyExW(buffer, sizeof(buffer), path, &m_pend, NULL, 0); - - DWORD err = NtOpenObject(DIRECTORY_OBJECT, &m_directory, FILE_LIST_DIRECTORY, buffer); - if (!NT_SUCCESS(err)) - { - ERR("NtOpenDirectoryObject failed for path %S with status=%x\n", buffer, err); - return HRESULT_FROM_NT(err); - } - - if (m_pend[-1] != '\\') - *m_pend++ = '\\'; - - return S_OK; - } - - HRESULT EnumerateNext(LPITEMIDLIST* ppidl) - { - BYTE dirbuffer[2048]; - if (!NT_SUCCESS(NtQueryDirectoryObject(m_directory, dirbuffer, 2048, TRUE, m_first, &m_enumContext, NULL))) - return S_FALSE; - - // if ppidl is NULL, assume the caller was Skip(), - // so we don't care about the info - if (!ppidl) - return S_OK; - - m_first = FALSE; - POBJECT_DIRECTORY_INFORMATION info = (POBJECT_DIRECTORY_INFORMATION) dirbuffer; - - if (info->Name.Buffer) - { - StringCbCopyNW(m_pend, sizeof(buffer), info->Name.Buffer, info->Name.Length); - } - - OBJECT_TYPE otype = MapTypeNameToType(info->TypeName.Buffer, info->TypeName.Length); - - DWORD entryBufferLength = FIELD_OFFSET(NtPidlEntry, entryName) + sizeof(WCHAR); - if (info->Name.Buffer) - entryBufferLength += info->Name.Length; - - if (otype < 0) - { - entryBufferLength += FIELD_OFFSET(NtPidlTypeData, typeName) + sizeof(WCHAR); - - if (info->TypeName.Buffer) - { - entryBufferLength += info->TypeName.Length; - } - } - - // allocate space for the terminator - entryBufferLength += 2; - - NtPidlEntry* entry = (NtPidlEntry*) CoTaskMemAlloc(entryBufferLength); - if (!entry) - return E_OUTOFMEMORY; - - memset(entry, 0, entryBufferLength); - - entry->cb = FIELD_OFFSET(NtPidlEntry, entryName); - entry->magic = NT_OBJECT_PIDL_MAGIC; - entry->objectType = otype; - - if (info->Name.Buffer) - { - entry->entryNameLength = info->Name.Length; - StringCbCopyNW(entry->entryName, entryBufferLength, info->Name.Buffer, info->Name.Length); - entry->cb += entry->entryNameLength + sizeof(WCHAR); - } - else - { - entry->entryNameLength = 0; - entry->entryName[0] = 0; - entry->cb += sizeof(WCHAR); - } - - if (otype < 0) - { - NtPidlTypeData * typedata = (NtPidlTypeData*) ((PBYTE) entry + entry->cb); - DWORD remainingSpace = entryBufferLength - ((PBYTE) (typedata->typeName) - (PBYTE) entry); - - if (info->TypeName.Buffer) - { - typedata->typeNameLength = info->TypeName.Length; - StringCbCopyNW(typedata->typeName, remainingSpace, info->TypeName.Buffer, info->TypeName.Length); - - entry->cb += typedata->typeNameLength + sizeof(WCHAR); - } - else - { - typedata->typeNameLength = 0; - typedata->typeName[0] = 0; - entry->cb += typedata->typeNameLength + sizeof(WCHAR); - } - } - - *ppidl = (LPITEMIDLIST) entry; - - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) - { - if (pceltFetched) - *pceltFetched = 0; - - while (celt-- > 0) - { - HRESULT hr = EnumerateNext(rgelt); - if (hr != S_OK) - return hr; - - if (pceltFetched) - (*pceltFetched)++; - if (rgelt) - rgelt++; - } - - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) - { - while (celt > 0) - { - HRESULT hr = EnumerateNext(NULL); - if (FAILED(hr)) - return hr; - if (hr != S_OK) - break; - } - - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Reset() - { - return E_NOTIMPL; - } - - virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) - { - return E_NOTIMPL; - } - - DECLARE_NOT_AGGREGATABLE(CEnumNTDirectory) - DECLARE_PROTECT_FINAL_CONSTRUCT() - - BEGIN_COM_MAP(CEnumNTDirectory) - COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) - END_COM_MAP() -}; - -HRESULT GetEnumRegistryRoot(IEnumIDList ** ppil) -{ - return ShellObjectCreator<CEnumRegRoot>(IID_PPV_ARG(IEnumIDList, ppil)); -} - -HRESULT GetEnumRegistryKey(LPCWSTR path, HKEY root, IEnumIDList ** ppil) -{ - return ShellObjectCreatorInit<CEnumRegKey>(path, root, IID_PPV_ARG(IEnumIDList, ppil)); -} - -HRESULT GetEnumNTDirectory(LPCWSTR path, IEnumIDList ** ppil) -{ - return ShellObjectCreatorInit<CEnumNTDirectory>(path, IID_PPV_ARG(IEnumIDList, ppil)); -} Removed: trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h (removed) @@ -1,107 +0,0 @@ -/* - * Copyright 2004 Martin Fuchs - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -extern "C" { -#define NTOS_MODE_USER -#include <ndk/ntndk.h> -#include <ndk/rtlfuncs.h> -} - -// All the possible values are defined here because I want the type field to be -// "persistable" and not change if more types are added in the future. -enum OBJECT_TYPE { - DIRECTORY_OBJECT, SYMBOLICLINK_OBJECT, - MUTANT_OBJECT, SECTION_OBJECT, EVENT_OBJECT, SEMAPHORE_OBJECT, - TIMER_OBJECT, KEY_OBJECT, EVENTPAIR_OBJECT, IOCOMPLETITION_OBJECT, - DEVICE_OBJECT, FILE_OBJECT, CONTROLLER_OBJECT, PROFILE_OBJECT, - TYPE_OBJECT, DESKTOP_OBJECT, WINDOWSTATION_OBJECT, DRIVER_OBJECT, - TOKEN_OBJECT, PROCESS_OBJECT, THREAD_OBJECT, ADAPTER_OBJECT, PORT_OBJECT, - - UNKNOWN_OBJECT_TYPE = -1 -}; -extern const LPCWSTR ObjectTypeNames[]; - -#define NT_OBJECT_PIDL_MAGIC (USHORT)0x9A03 -#define REGISTRY_PIDL_MAGIC (USHORT)0x5364 - -#include <pshpack1.h> - -// NT OBJECT browser -struct NtPidlEntry -{ - USHORT cb; - USHORT magic; // 0x9A03 ~~~ "NTOB" - - // If this is -1, there will be a NtPidlTypeData following this, and before any other extensions - OBJECT_TYPE objectType; - - USHORT entryNameLength; - WCHAR entryName[ANYSIZE_ARRAY]; -}; - -struct NtPidlTypeData -{ - USHORT typeNameLength; - WCHAR typeName[ANYSIZE_ARRAY]; -}; - -// REGISTRY browser -enum REG_ENTRY_TYPE -{ - REG_ENTRY_ROOT, - REG_ENTRY_KEY, - REG_ENTRY_VALUE, - REG_ENTRY_VALUE_WITH_CONTENT - // any more? -}; -extern const LPCWSTR RegistryTypeNames []; - -struct RegPidlEntry -{ - USHORT cb; - USHORT magic; // 0x5364 ~~~ "REGK" - - REG_ENTRY_TYPE entryType; - - USHORT entryNameLength; - - union { - struct { - // For Value entries, this contains the value contents, if it's resonably small. - // For Key entries, this contains the custom class name - DWORD contentType; - USHORT contentsLength; - }; - - HKEY rootKey; - }; - - WCHAR entryName[ANYSIZE_ARRAY]; - -}; - - -#include <poppack.h> - -HRESULT ReadRegistryValue(HKEY root, PCWSTR path, PCWSTR valueName, PVOID * valueData, PDWORD valueLength); - -HRESULT GetEnumRegistryRoot(IEnumIDList ** ppil); -HRESULT GetEnumRegistryKey(LPCWSTR path, HKEY root, IEnumIDList ** ppil); -HRESULT GetEnumNTDirectory(LPCWSTR path, IEnumIDList ** ppil); - -HRESULT GetNTObjectSymbolicLinkTarget(LPCWSTR path, LPCWSTR entryName, PUNICODE_STRING LinkTarget); Modified: trunk/reactos/dll/shellext/ntobjshex/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/pre…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/precomp.h [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/precomp.h [iso-8859-1] Fri Aug 21 15:01:04 2015 @@ -46,5 +46,5 @@ DEFINE_GUID(CLSID_NtObjectFolder, 0x845b0fb2, 0x66e0, 0x416b, 0x8f, 0x91, 0x31, 0x4e, 0x23, 0xf7, 0xc1, 0x2d); -#include "ntobjns.h" +#include "ntobjfolder.h" #include "regfolder.h" Modified: trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/reg…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] Fri Aug 21 15:01:04 2015 @@ -7,7 +7,7 @@ */ #include "precomp.h" -#include "ntobjutil.h" +#include "ntobjenum.h" #include <ntquery.h> #include "util.h"
9 years, 4 months
1
0
0
0
[dquintana] 68784: Oops. That was a debug change. Wasn't meant to make it into the commit.
by dquintana@svn.reactos.org
Author: dquintana Date: Fri Aug 21 14:31:07 2015 New Revision: 68784 URL:
http://svn.reactos.org/svn/reactos?rev=68784&view=rev
Log: Oops. That was a debug change. Wasn't meant to make it into the commit. Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] Fri Aug 21 14:31:07 2015 @@ -296,7 +296,7 @@ (entry->objectType == KEY_OBJECT); } - virtual HRESULT GetInfoFromPidl(LPCITEMIDLIST pcidl, const NtPidlEntry ** pentry) + HRESULT GetInfoFromPidl(LPCITEMIDLIST pcidl, const NtPidlEntry ** pentry) { NtPidlEntry * entry = (NtPidlEntry*) &(pcidl->mkid);
9 years, 4 months
1
0
0
0
[dquintana] 68783: [NTOBJSHEX] * Use lazy enumeration of the nt objects and registry keys, as intended for the IEnumIDList interface. * Display of the NT Object creation date has been lost in the p...
by dquintana@svn.reactos.org
Author: dquintana Date: Fri Aug 21 14:26:25 2015 New Revision: 68783 URL:
http://svn.reactos.org/svn/reactos?rev=68783&view=rev
Log: [NTOBJSHEX] * Use lazy enumeration of the nt objects and registry keys, as intended for the IEnumIDList interface. * Display of the NT Object creation date has been lost in the process, but it was only really used by symlinks. * Symlink target display doesn't appear to work at the moment, will fix later. Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] Fri Aug 21 14:26:25 2015 @@ -34,7 +34,6 @@ { NTOBJECT_COLUMN_NAME = 0, NTOBJECT_COLUMN_TYPE, - NTOBJECT_COLUMN_CREATEDATE, NTOBJECT_COLUMN_LINKTARGET, NTOBJECT_COLUMN_END }; @@ -43,28 +42,25 @@ public CComObjectRootEx<CComMultiThreadModelNoCS>, public IExtractIconW { - PCIDLIST_ABSOLUTE m_pcidlFolder; - PCITEMID_CHILD m_pcidlChild; + PCITEMID_CHILD m_pcidlChild; + LPCWSTR m_NtPath; public: CNtObjectFolderExtractIcon() : - m_pcidlFolder(NULL), - m_pcidlChild(NULL) + m_pcidlChild(NULL), m_NtPath(NULL) { } virtual ~CNtObjectFolderExtractIcon() { - if (m_pcidlFolder) - ILFree((LPITEMIDLIST) m_pcidlFolder); if (m_pcidlChild) ILFree((LPITEMIDLIST) m_pcidlChild); } - HRESULT Initialize(PCIDLIST_ABSOLUTE parent, UINT cidl, PCUITEMID_CHILD_ARRAY apidl) - { - m_pcidlFolder = ILClone(parent); + HRESULT Initialize(LPCWSTR ntPath, UINT cidl, PCUITEMID_CHILD_ARRAY apidl) + { + m_NtPath = ntPath; if (cidl != 1) return E_INVALIDARG; m_pcidlChild = ILClone(apidl[0]); @@ -85,11 +81,6 @@ UINT flags = 0; -#define GIL_CHECKSHIELD 0x0200 -#define GIL_SHIELD 0x0200 - if (uFlags & GIL_CHECKSHIELD && !(entry->objectInformation.GrantedAccess & STANDARD_RIGHTS_READ)) - flags |= GIL_SHIELD; - switch (entry->objectType) { case DIRECTORY_OBJECT: @@ -145,193 +136,21 @@ private: PWSTR m_ntPath; - HDPA m_hDpa; - UINT m_hDpaCount; - - int DpaDeleteCallback(NtPidlEntry * info) - { - CoTaskMemFree(info); - return 0; - } - - static int CALLBACK s_DpaDeleteCallback(void *pItem, void *pData) - { - CNtObjectPidlManager * mf = (CNtObjectPidlManager*) pData; - NtPidlEntry * item = (NtPidlEntry*) pItem; - return mf->DpaDeleteCallback(item); - } - public: CNtObjectPidlManager() : - m_ntPath(NULL), - m_hDpa(NULL), - m_hDpaCount(0) + m_ntPath(NULL) { } ~CNtObjectPidlManager() { - DPA_DestroyCallback(m_hDpa, s_DpaDeleteCallback, this); } HRESULT Initialize(PWSTR ntPath) { m_ntPath = ntPath; - m_hDpa = NULL; - - return S_OK; - } - - HRESULT Enumerate() - { - if (m_hDpa) - return S_OK; - - m_hDpa = DPA_Create(10); - - if (!m_hDpa) - return E_OUTOFMEMORY; - - HRESULT hr = EnumerateNtDirectory(m_hDpa, m_ntPath, &m_hDpaCount); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - return S_OK; - } - - HRESULT FindPidlInList(PCUITEMID_CHILD pcidl, const NtPidlEntry ** pinfo) - { - HRESULT hr; - - if (!m_hDpa) - { - hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - const NtPidlEntry * info = (const NtPidlEntry *) pcidl; - if ((info->cb < sizeof(NtPidlEntry)) || (info->magic != NT_OBJECT_PIDL_MAGIC)) - { - ERR("FindPidlInList: Requested pidl is not of the correct type.\n"); - return E_INVALIDARG; - } - - TRACE("Searching for pidl { name='%S' } in a list of %d items\n", info->entryName, m_hDpaCount); - - for (UINT i = 0; i < m_hDpaCount; i++) - { - const NtPidlEntry * pInfo = (const NtPidlEntry *) DPA_GetPtr(m_hDpa, i); - ASSERT(pInfo); - - hr = CompareIDs(SHCIDS_CANONICALONLY, pInfo, info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (hr == S_OK) - { - *pinfo = pInfo; - return S_OK; - } - else - { - TRACE("Comparison returned %d for '%S'\n", (int) (short) (hr & 0xFFFF), pInfo->entryName); - } - } - - ERR("PIDL NOT FOUND: Requested filename: %S\n", info->entryName); - *pinfo = NULL; - - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - - HRESULT FindByName(LPCWSTR strParsingName, NtPidlEntry ** pinfo) - { - HRESULT hr; - - if (!m_hDpa) - { - hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - TRACE("Searching for '%S' in a list of %d items\n", strParsingName, m_hDpaCount); - - for (int i = 0; i < (int) m_hDpaCount; i++) - { - NtPidlEntry * pInfo = (NtPidlEntry *) DPA_GetPtr(m_hDpa, i); - ASSERT(pInfo); - - int order = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, - pInfo->entryName, wcslen(pInfo->entryName), - strParsingName, wcslen(strParsingName)); - - if (order == CSTR_EQUAL) - { - *pinfo = pInfo; - return S_OK; - } - } - - TRACE("Pidl not found\n"); - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - - HRESULT GetPidl(UINT index, NtPidlEntry ** pEntry) - { - if (!m_hDpa) - { - HRESULT hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - *pEntry = NULL; - - NtPidlEntry * entry = (NtPidlEntry *) DPA_GetPtr(m_hDpa, index); - if (!entry) - { - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - - *pEntry = entry; - return S_OK; - } - - HRESULT GetCount(UINT * count) - { - if (!m_hDpa) - { - HRESULT hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - *count = m_hDpaCount; - return S_OK; - } - - static LPITEMIDLIST CreatePidlFromItem(const NtPidlEntry * entry) - { - LPITEMIDLIST idl = (LPITEMIDLIST) CoTaskMemAlloc(entry->cb + 2); - if (!idl) - return NULL; - memset(idl, 0, entry->cb + 2); - memcpy(idl, entry, entry->cb); - return idl; + + return S_OK; } static HRESULT CompareIDs(LPARAM lParam, const NtPidlEntry * first, const NtPidlEntry * second) @@ -413,16 +232,6 @@ return S_OK; } - case NTOBJECT_COLUMN_CREATEDATE: - { - LONGLONG ord = second->objectInformation.CreateTime.QuadPart - first->objectInformation.CreateTime.QuadPart; - if (ord > 0) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (ord < 0) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - return S_OK; - } case NTOBJECT_COLUMN_LINKTARGET: { // Can't sort by value @@ -478,131 +287,34 @@ BOOL IsFolder(LPCITEMIDLIST pcidl) { - const NtPidlEntry * entry; - HRESULT hr = FindPidlInList(pcidl, &entry); - if (FAILED_UNEXPECTEDLY(hr)) + NtPidlEntry * entry = (NtPidlEntry*) &(pcidl->mkid); + if ((entry->cb < sizeof(NtPidlEntry)) || (entry->magic != NT_OBJECT_PIDL_MAGIC)) return FALSE; return (entry->objectType == DIRECTORY_OBJECT) || (entry->objectType == SYMBOLICLINK_OBJECT) || (entry->objectType == KEY_OBJECT); } -}; - -class CNtObjectFolderEnum : - public CComObjectRootEx<CComMultiThreadModelNoCS>, - public IEnumIDList -{ -private: - CComPtr<CNtObjectFolder> m_Folder; - - HWND m_HwndOwner; - SHCONTF m_Flags; - - UINT m_Index; - UINT m_Count; - -public: - CNtObjectFolderEnum() : - m_HwndOwner(NULL), - m_Flags(0), - m_Index(0), - m_Count(0) - { - } - - virtual ~CNtObjectFolderEnum() - { - } - - HRESULT Initialize(CNtObjectFolder * folder, HWND hwndOwner, SHCONTF flags) - { - m_Folder = folder; - - m_Folder->GetManager().GetCount(&m_Count); - - m_HwndOwner = hwndOwner; - m_Flags = flags; - - return Reset(); - } - - virtual HRESULT STDMETHODCALLTYPE Next( - ULONG celt, - LPITEMIDLIST *rgelt, - ULONG *pceltFetched) - { - if (pceltFetched) - *pceltFetched = 0; - - if (m_Index >= m_Count) - return S_FALSE; - - for (int i = 0; i < (int) celt;) - { - NtPidlEntry * tinfo; - BOOL flagsOk = FALSE; - - do { - HRESULT hr = m_Folder->GetManager().GetPidl(m_Index++, &tinfo); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - switch (tinfo->objectType) - { - case SYMBOLICLINK_OBJECT: - case DIRECTORY_OBJECT: - case KEY_OBJECT: - flagsOk = (m_Flags & SHCONTF_FOLDERS) != 0; - break; - default: - flagsOk = (m_Flags & SHCONTF_NONFOLDERS) != 0; - break; - } - } while (m_Index < m_Count && !flagsOk); - - if (flagsOk) - { - if (rgelt) - rgelt[i] = m_Folder->GetManager().CreatePidlFromItem(tinfo); - i++; - } - - if (m_Index == m_Count) - { - if (pceltFetched) - *pceltFetched = i; - return (i == (int) celt) ? S_OK : S_FALSE; - } - } - - if (pceltFetched) *pceltFetched = celt; - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) - { - return Next(celt, NULL, NULL); - } - - virtual HRESULT STDMETHODCALLTYPE Reset() - { - m_Index = 0; - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) - { - return ShellObjectCreatorInit<CNtObjectFolderEnum>(m_Folder, m_HwndOwner, m_Flags, IID_PPV_ARG(IEnumIDList, ppenum)); - } - - DECLARE_NOT_AGGREGATABLE(CNtObjectFolderEnum) - DECLARE_PROTECT_FINAL_CONSTRUCT() - - BEGIN_COM_MAP(CNtObjectFolderEnum) - COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) - END_COM_MAP() - + + virtual HRESULT GetInfoFromPidl(LPCITEMIDLIST pcidl, const NtPidlEntry ** pentry) + { + NtPidlEntry * entry = (NtPidlEntry*) &(pcidl->mkid); + + if (entry->cb < sizeof(NtPidlEntry)) + { + DbgPrint("PCIDL too small %l (required %l)\n", entry->cb, sizeof(NtPidlEntry)); + return E_INVALIDARG; + } + + if (entry->magic != NT_OBJECT_PIDL_MAGIC) + { + DbgPrint("PCIDL magic mismatch %04x (expected %04x)\n", entry->magic, NT_OBJECT_PIDL_MAGIC); + return E_INVALIDARG; + } + + *pentry = entry; + return S_OK; + } }; //----------------------------------------------------------------------------- @@ -631,8 +343,6 @@ LPITEMIDLIST *ppidl, ULONG *pdwAttributes) { - NtPidlEntry * info; - if (!ppidl) return E_POINTER; @@ -644,19 +354,43 @@ TRACE("CNtObjectFolder::ParseDisplayName name=%S (ntPath=%S)\n", lpszDisplayName, m_NtPath); - HRESULT hr = m_PidlManager->FindByName(lpszDisplayName, &info); + const NtPidlEntry * info; + IEnumIDList * it; + HRESULT hr = GetEnumNTDirectory(m_NtPath, &it); if (FAILED(hr)) + return hr; + + while (TRUE) + { + hr = it->Next(1, ppidl, NULL); + + if (FAILED(hr)) + return hr; + + if (hr != S_OK) + break; + + hr = m_PidlManager->GetInfoFromPidl(*ppidl, &info); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (StrCmpW(info->entryName, lpszDisplayName) == 0) + break; + } + + if (hr != S_OK) { return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); } - *ppidl = m_PidlManager->CreatePidlFromItem(info); - - if (pchEaten) - *pchEaten = wcslen(info->entryName); - - if (pdwAttributes) - *pdwAttributes = m_PidlManager->ConvertAttributes(info, pdwAttributes); + if (pchEaten || pdwAttributes) + { + if (pchEaten) + *pchEaten = wcslen(info->entryName); + + if (pdwAttributes) + *pdwAttributes = m_PidlManager->ConvertAttributes(info, pdwAttributes); + } return S_OK; } @@ -666,7 +400,7 @@ SHCONTF grfFlags, IEnumIDList **ppenumIDList) { - return ShellObjectCreatorInit<CNtObjectFolderEnum>(this, hwndOwner, grfFlags, IID_PPV_ARG(IEnumIDList, ppenumIDList)); + return GetEnumNTDirectory(m_NtPath, ppenumIDList); } HRESULT STDMETHODCALLTYPE CNtObjectFolder::BindToObject( @@ -679,13 +413,10 @@ if (IsEqualIID(riid, IID_IShellFolder)) { - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; - if (!(info->objectInformation.GrantedAccess & (STANDARD_RIGHTS_READ | FILE_LIST_DIRECTORY))) - return E_ACCESSDENIED; - WCHAR path[MAX_PATH]; StringCbCopyW(path, _countof(path), m_NtPath); @@ -699,18 +430,32 @@ if (info->objectType == SYMBOLICLINK_OBJECT) { - NtPidlSymlinkData * symlink = (NtPidlSymlinkData*) (((PBYTE) info) + FIELD_OFFSET(NtPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); - - if (symlink->targetNameLength > 0) - { - if (symlink->targetName[1] == L':' && isalphaW(symlink->targetName[0])) + WCHAR wbLink[MAX_PATH] = { 0 }; + UNICODE_STRING link; + RtlInitEmptyUnicodeString(&link, wbLink, sizeof(wbLink)); + + hr = GetNTObjectSymbolicLinkTarget(m_NtPath, info->entryName, &link); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (link.Length > 0) + { + if (link.Buffer[1] == L':' && isalphaW(link.Buffer[0])) { - ERR("TODO: Navigating to WIN32 PATH from NT PATH.\n"); - return E_NOTIMPL; + CComPtr<IShellFolder> psfDesktop; + hr = SHGetDesktopFolder(&psfDesktop); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + hr = psfDesktop->ParseDisplayName(NULL, NULL, path, NULL, &first, NULL); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + return psfDesktop->BindToObject(rest, pbcReserved, riid, ppvOut); } StringCbCopyW(path, _countof(path), L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{845B0FB2-66E0-416B-8F91-314E23F7C12D}"); - PathAppend(path, symlink->targetName); + PathAppend(path, link.Buffer); CComPtr<IShellFolder> psfDesktop; hr = SHGetDesktopFolder(&psfDesktop); @@ -731,7 +476,7 @@ if (info->objectType == KEY_OBJECT) { - hr = ShellObjectCreatorInit<CRegistryFolder>(fullPidl, path, (HKEY)NULL, IID_PPV_ARG(IShellFolder, &psfChild)); + hr = ShellObjectCreatorInit<CRegistryFolder>(fullPidl, path, (HKEY) NULL, IID_PPV_ARG(IShellFolder, &psfChild)); } else { @@ -824,7 +569,7 @@ { const NtPidlEntry * info; - TRACE("GetAttributesOf\n"); + TRACE("GetAttributesOf %d\n", cidl); if (cidl == 0) { @@ -836,7 +581,7 @@ { PCUITEMID_CHILD pidl = apidl[i]; - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -855,6 +600,7 @@ UINT *prgfInOut, void **ppvOut) { + DWORD res; TRACE("GetUIObjectOf\n"); if (IsEqualIID(riid, IID_IContextMenu) || @@ -863,12 +609,14 @@ { CComPtr<IContextMenu> pcm; - HKEY keys [1]; + HKEY keys[1]; int nkeys = _countof(keys); if (cidl == 1 && m_PidlManager->IsFolder(apidl[0])) { - RegOpenKey(HKEY_CLASSES_ROOT, L"Folder", keys + 0); + res = RegOpenKey(HKEY_CLASSES_ROOT, L"Folder", keys + 0); + if (!NT_SUCCESS(res)) + return HRESULT_FROM_NT(res); } else { @@ -884,12 +632,12 @@ if (IsEqualIID(riid, IID_IExtractIconW)) { - return ShellObjectCreatorInit<CNtObjectFolderExtractIcon>(m_shellPidl, cidl, apidl, riid, ppvOut); + return ShellObjectCreatorInit<CNtObjectFolderExtractIcon>(m_NtPath, cidl, apidl, riid, ppvOut); } if (IsEqualIID(riid, IID_IDataObject)) { - return CIDLData_CreateFromIDArray(m_shellPidl, cidl, apidl, (IDataObject**)ppvOut); + return CIDLData_CreateFromIDArray(m_shellPidl, cidl, apidl, (IDataObject**) ppvOut); } if (IsEqualIID(riid, IID_IQueryAssociations)) @@ -921,7 +669,7 @@ TRACE("GetDisplayNameOf %p\n", pidl); - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -964,7 +712,7 @@ PathAppendW(path, temp); } - ILFree((LPITEMIDLIST)pidlFirst); + ILFree((LPITEMIDLIST) pidlFirst); } else { @@ -1073,11 +821,8 @@ case NTOBJECT_COLUMN_TYPE: *pcsFlags = SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT; return S_OK; - case NTOBJECT_COLUMN_CREATEDATE: - *pcsFlags = SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT; - return S_OK; case NTOBJECT_COLUMN_LINKTARGET: - *pcsFlags = SHCOLSTATE_TYPE_STR; + *pcsFlags = SHCOLSTATE_TYPE_STR | SHCOLSTATE_SLOW; return S_OK; } @@ -1095,7 +840,7 @@ if (pidl) { - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -1126,35 +871,25 @@ return MakeVariantString(pv, ObjectTypeNames[info->objectType]); } } - else if (pscid->pid == PID_STG_WRITETIME) - { - DOUBLE varTime; - SYSTEMTIME stime; - FileTimeToSystemTime((FILETIME*) &(info->objectInformation.CreateTime), &stime); - SystemTimeToVariantTime(&stime, &varTime); - - V_VT(pv) = VT_DATE; - V_DATE(pv) = varTime; - return S_OK; - } } else if (IsEqualGUID(pscid->fmtid, GUID_NtObjectColumns)) { - if (pscid->pid == NTOBJECT_COLUMN_LINKTARGET) - { - if (info->objectType == SYMBOLICLINK_OBJECT) + if (pscid->pid == NTOBJECT_COLUMN_LINKTARGET && info->objectType == SYMBOLICLINK_OBJECT) + { + WCHAR wbLink[MAX_PATH] = { 0 }; + UNICODE_STRING link; + RtlInitEmptyUnicodeString(&link, wbLink, sizeof(wbLink)); + + HRESULT hr = GetNTObjectSymbolicLinkTarget(m_NtPath, info->entryName, &link); + + if (!FAILED_UNEXPECTEDLY(hr) && link.Length > 0) { - NtPidlSymlinkData * symlink = (NtPidlSymlinkData*) (((PBYTE) info) + FIELD_OFFSET(NtPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); - - if (symlink->targetNameLength > 0) - { - return MakeVariantString(pv, symlink->targetName); - } + return MakeVariantString(pv, link.Buffer); } - - V_VT(pv) = VT_EMPTY; - return S_OK; - } + } + + V_VT(pv) = VT_EMPTY; + return S_OK; } } @@ -1172,7 +907,7 @@ if (pidl) { - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -1198,43 +933,28 @@ else MakeStrRetFromString(ObjectTypeNames[info->objectType], &(psd->str)); return S_OK; - case NTOBJECT_COLUMN_CREATEDATE: + case NTOBJECT_COLUMN_LINKTARGET: + { psd->fmt = LVCFMT_LEFT; - if (info->objectInformation.CreateTime.QuadPart != 0) - { - WCHAR dbuff[128]; - PWSTR tbuff; - SYSTEMTIME stime; - FileTimeToSystemTime((LPFILETIME) &(info->objectInformation.CreateTime), &stime); - GetDateFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, dbuff, _countof(dbuff)); - tbuff = dbuff + wcslen(dbuff); - *tbuff++ = L' '; - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, tbuff, _countof(dbuff) - (tbuff - dbuff)); - - MakeStrRetFromString(dbuff, &(psd->str)); - return S_OK; - } - - MakeStrRetFromString(L"", &(psd->str)); - return S_OK; - - case NTOBJECT_COLUMN_LINKTARGET: - psd->fmt = LVCFMT_LEFT; - if (info->objectType == SYMBOLICLINK_OBJECT) { - NtPidlSymlinkData * symlink = (NtPidlSymlinkData*) (((PBYTE) info) + FIELD_OFFSET(NtPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); - - if (symlink->targetNameLength > 0) + WCHAR wbLink[MAX_PATH] = { 0 }; + UNICODE_STRING link; + RtlInitEmptyUnicodeString(&link, wbLink, sizeof(wbLink)); + + HRESULT hr = GetNTObjectSymbolicLinkTarget(m_NtPath, info->entryName, &link); + + if (!FAILED_UNEXPECTEDLY(hr) && link.Length > 0) { - MakeStrRetFromString(symlink->targetName, symlink->targetNameLength, &(psd->str)); + MakeStrRetFromString(link.Buffer, link.Length, &(psd->str)); return S_OK; } } MakeStrRetFromString(L"", &(psd->str)); return S_OK; + } } } else @@ -1255,13 +975,6 @@ // TODO: Make localizable MakeStrRetFromString(L"Object Type", &(psd->str)); return S_OK; - case NTOBJECT_COLUMN_CREATEDATE: - psd->fmt = LVCFMT_LEFT; - psd->cxChar = 20; - - // TODO: Make localizable - MakeStrRetFromString(L"Creation Time", &(psd->str)); - return S_OK; case NTOBJECT_COLUMN_LINKTARGET: psd->fmt = LVCFMT_LEFT; psd->cxChar = 30; @@ -1290,10 +1003,6 @@ pscid->fmtid = storage; pscid->pid = PID_STG_STORAGETYPE; return S_OK; - case NTOBJECT_COLUMN_CREATEDATE: - pscid->fmtid = storage; - pscid->pid = PID_STG_WRITETIME; - return S_OK; case NTOBJECT_COLUMN_LINKTARGET: pscid->fmtid = GUID_NtObjectColumns; pscid->pid = NTOBJECT_COLUMN_LINKTARGET; @@ -1316,8 +1025,6 @@ return S_FALSE; case SFVM_BACKGROUNDENUM: return S_OK; - case SFVM_DEFITEMCOUNT: - return m_PidlManager->GetCount((UINT*) lParam); } return E_NOTIMPL; } Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjutil.cpp [iso-8859-1] Fri Aug 21 14:26:25 2015 @@ -23,6 +23,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(ntobjshex); +static struct RootKeyEntry { + HKEY key; + PCWSTR keyName; +} RootKeys [] = { + { HKEY_CLASSES_ROOT, L"HKEY_CLASSES_ROOT" }, + { HKEY_CURRENT_USER, L"HKEY_CURRENT_USER" }, + { HKEY_LOCAL_MACHINE, L"HKEY_LOCAL_MACHINE" }, + { HKEY_USERS, L"HKEY_USERS" }, + { HKEY_CURRENT_CONFIG, L"HKEY_CURRENT_CONFIG" } +}; + typedef NTSTATUS(__stdcall* pfnNtGenericOpen)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES); typedef NTSTATUS(__stdcall* pfnNtOpenFile)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, ULONG, ULONG); @@ -36,7 +47,7 @@ 0 }; -const LPCWSTR RegistryTypeNames[] = { +const LPCWSTR RegistryTypeNames [] = { L"REG_NONE", L"REG_SZ", L"REG_EXPAND_SZ", @@ -99,218 +110,132 @@ return UNKNOWN_OBJECT_TYPE; } -HRESULT EnumerateNtDirectory(HDPA hdpa, PCWSTR path, UINT * hdpaCount) -{ +HRESULT ReadRegistryValue(HKEY root, PCWSTR path, PCWSTR valueName, PVOID * valueData, PDWORD valueLength) +{ + HKEY hkey; + + DWORD res; + if (root) + { + res = RegOpenKeyExW(root, *path == '\\' ? path + 1 : path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, &hkey); + } + else + { + res = NtOpenObject(KEY_OBJECT, (PHANDLE) &hkey, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, path); + } + if (!NT_SUCCESS(res)) + { + ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); + return HRESULT_FROM_NT(res); + } + + res = RegQueryValueExW(hkey, valueName, NULL, NULL, NULL, valueLength); + if (!NT_SUCCESS(res)) + { + ERR("RegQueryValueExW failed for path %S with status=%x\n", path, res); + return HRESULT_FROM_NT(res); + } + + if (*valueLength > 0) + { + PBYTE data = (PBYTE) CoTaskMemAlloc(*valueLength);; + *valueData = data; + + res = RegQueryValueExW(hkey, valueName, NULL, NULL, data, valueLength); + if (!NT_SUCCESS(res)) + { + CoTaskMemFree(data); + *valueData = NULL; + + RegCloseKey(hkey); + + ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); + return HRESULT_FROM_NT(res); + } + } + else + { + *valueData = NULL; + } + + RegCloseKey(hkey); + + return S_OK; +} + +HRESULT GetNTObjectSymbolicLinkTarget(LPCWSTR path, LPCWSTR entryName, PUNICODE_STRING LinkTarget) +{ + HANDLE handle; WCHAR buffer[MAX_PATH]; - PWSTR pend; - - *hdpaCount = 0; + LPWSTR pend = buffer; StringCbCopyExW(buffer, sizeof(buffer), path, &pend, NULL, 0); - - ULONG enumContext = 0; - HANDLE directory = NULL; - - DWORD err = NtOpenObject(DIRECTORY_OBJECT, &directory, FILE_LIST_DIRECTORY, buffer); - if (!NT_SUCCESS(err)) - { - ERR("NtOpenDirectoryObject failed for path %S with status=%x\n", buffer, err); - return HRESULT_FROM_NT(err); - } if (pend[-1] != '\\') *pend++ = '\\'; - - BYTE dirbuffer[2048]; - - BOOL first = TRUE; - while (NtQueryDirectoryObject(directory, dirbuffer, 2048, TRUE, first, &enumContext, NULL) == STATUS_SUCCESS) - { - first = FALSE; - POBJECT_DIRECTORY_INFORMATION info = (POBJECT_DIRECTORY_INFORMATION) dirbuffer; - //for (; info->Name.Buffer != NULL; info++) - { - if (info->Name.Buffer) - { - StringCbCopyNW(pend, sizeof(buffer), info->Name.Buffer, info->Name.Length); - } - - OBJECT_TYPE otype = MapTypeNameToType(info->TypeName.Buffer, info->TypeName.Length); - OBJECT_BASIC_INFORMATION object = { 0 }; - - WCHAR wbLink[_MAX_PATH] = { 0 }; - UNICODE_STRING link; - RtlInitEmptyUnicodeString(&link, wbLink, sizeof(wbLink)); - - DWORD entryBufferLength = FIELD_OFFSET(NtPidlEntry,entryName) + sizeof(WCHAR); - if (info->Name.Buffer) - entryBufferLength += info->Name.Length; - - if (otype < 0) - { - entryBufferLength += FIELD_OFFSET(NtPidlTypeData,typeName) + sizeof(WCHAR); - - if (info->TypeName.Buffer) - { - entryBufferLength += info->TypeName.Length; - } - } - - if (otype == SYMBOLICLINK_OBJECT) - { - entryBufferLength += FIELD_OFFSET(NtPidlSymlinkData,targetName) + sizeof(WCHAR); - } - - DWORD access = STANDARD_RIGHTS_READ; - if ((otype == DIRECTORY_OBJECT) || - (otype == SYMBOLICLINK_OBJECT)) - access |= FILE_LIST_DIRECTORY; - - HANDLE handle; - if (!NtOpenObject(otype, &handle, access, buffer)) - { - DWORD read; - - if (!NT_SUCCESS(NtQueryObject(handle, ObjectBasicInformation, &object, sizeof(OBJECT_BASIC_INFORMATION), &read))) - { - ZeroMemory(&object, sizeof(OBJECT_BASIC_INFORMATION)); - } - - if (otype == SYMBOLICLINK_OBJECT) - { - if (NtQuerySymbolicLinkObject(handle, &link, NULL) == STATUS_SUCCESS) - { - entryBufferLength += link.Length; - } - else - { - link.Length = 0; - } - } - - NtClose(handle); - } - - NtPidlEntry* entry = (NtPidlEntry*) CoTaskMemAlloc(entryBufferLength); - if (!entry) - return E_OUTOFMEMORY; - - memset(entry, 0, entryBufferLength); - - entry->cb = FIELD_OFFSET(NtPidlEntry,entryName); - entry->magic = NT_OBJECT_PIDL_MAGIC; - entry->objectType = otype; - entry->objectInformation = object; - memset(entry->objectInformation.Reserved, 0, sizeof(entry->objectInformation.Reserved)); - - if (info->Name.Buffer) - { - entry->entryNameLength = info->Name.Length; - StringCbCopyNW(entry->entryName, entryBufferLength, info->Name.Buffer, info->Name.Length); - entry->cb += entry->entryNameLength + sizeof(WCHAR); - } - else - { - entry->entryNameLength = 0; - entry->entryName[0] = 0; - entry->cb += sizeof(WCHAR); - } - - if (otype < 0) - { - NtPidlTypeData * typedata = (NtPidlTypeData*) ((PBYTE) entry + entry->cb); - DWORD remainingSpace = entryBufferLength - ((PBYTE) (typedata->typeName) - (PBYTE) entry); - - if (info->TypeName.Buffer) - { - typedata->typeNameLength = info->TypeName.Length; - StringCbCopyNW(typedata->typeName, remainingSpace, info->TypeName.Buffer, info->TypeName.Length); - - entry->cb += typedata->typeNameLength + sizeof(WCHAR); - } - else - { - typedata->typeNameLength = 0; - typedata->typeName[0] = 0; - entry->cb += typedata->typeNameLength + sizeof(WCHAR); - } - } - - if (otype == SYMBOLICLINK_OBJECT) - { - NtPidlSymlinkData * symlink = (NtPidlSymlinkData*) ((PBYTE) entry + entry->cb); - DWORD remainingSpace = entryBufferLength - ((PBYTE) (symlink->targetName) - (PBYTE) entry); - - symlink->targetNameLength = link.Length; - StringCbCopyNW(symlink->targetName, remainingSpace, link.Buffer, link.Length); - - entry->cb += symlink->targetNameLength + sizeof(WCHAR); - } - - DPA_AppendPtr(hdpa, entry); - (*hdpaCount)++; - } - } - - NtClose(directory); + StringCbCatW(buffer, sizeof(buffer), entryName); + + DbgPrint("GetNTObjectSymbolicLinkTarget %d\n", buffer); + + LinkTarget->Length = 0; + + DWORD err = NtOpenObject(SYMBOLICLINK_OBJECT, &handle, 0, buffer); + if (!NT_SUCCESS(err)) + return HRESULT_FROM_NT(err); + + err = NT_SUCCESS(NtQuerySymbolicLinkObject(handle, LinkTarget, NULL)); + if (!NT_SUCCESS(err)) + return HRESULT_FROM_NT(err); + + NtClose(handle); return S_OK; } -HRESULT EnumerateRegistryKey(HDPA hdpa, PCWSTR path, HKEY root, UINT * hdpaCount) -{ - *hdpaCount = 0; - - HKEY hkey; - - DWORD res; - if (root) - { - res = RegOpenKeyExW(root, *path == '\\' ? path + 1 : path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hkey); - } - else - { - res = NtOpenObject(KEY_OBJECT, (PHANDLE)&hkey, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, path); - } - if (!NT_SUCCESS(res)) - { - ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); - return HRESULT_FROM_NT(res); - } - - for (int idx = 0;; ++idx) - { - WCHAR name[MAX_PATH]; - DWORD cchName = _countof(name); - - WCHAR className[MAX_PATH]; - DWORD cchClass = _countof(className); - - if (RegEnumKeyExW(hkey, idx, name, &cchName, 0, className, &cchClass, NULL)) - break; - - name[cchName] = 0; - className[cchClass] = 0; - - REG_ENTRY_TYPE otype = REG_ENTRY_KEY; - - DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry,entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); - - if (cchClass > 0) - { - entryBufferLength += sizeof(WCHAR) + cchClass * sizeof(WCHAR); - } - +class CEnumRegRoot : + public CComObjectRootEx<CComMultiThreadModelNoCS>, + public IEnumIDList +{ + UINT m_idx; + +public: + CEnumRegRoot() + : m_idx(0) + { + } + + ~CEnumRegRoot() + { + } + + HRESULT EnumerateNext(LPITEMIDLIST* ppidl) + { + if (m_idx >= _countof(RootKeys)) + return S_FALSE; + + RootKeyEntry& key = RootKeys[m_idx++]; + + PCWSTR name = key.keyName; + DWORD cchName = wcslen(name); + + REG_ENTRY_TYPE otype = REG_ENTRY_ROOT; + + DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); + + // allocate space for the terminator + entryBufferLength += 2; + RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength); if (!entry) return E_OUTOFMEMORY; memset(entry, 0, entryBufferLength); - entry->cb = FIELD_OFFSET(NtPidlEntry,entryName); + entry->cb = FIELD_OFFSET(RegPidlEntry, entryName); entry->magic = REGISTRY_PIDL_MAGIC; entry->entryType = otype; + entry->rootKey = key.key; if (cchName > 0) { @@ -325,6 +250,154 @@ entry->cb += sizeof(WCHAR); } + *ppidl = (LPITEMIDLIST) entry; + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) + { + if (pceltFetched) + *pceltFetched = 0; + + while (celt-- > 0) + { + HRESULT hr = EnumerateNext(rgelt); + if (hr != S_OK) + return hr; + + if (pceltFetched) + (*pceltFetched)++; + if (rgelt) + rgelt++; + } + + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) + { + while (celt > 0) + { + HRESULT hr = EnumerateNext(NULL); + if (FAILED(hr)) + return hr; + if (hr != S_OK) + break; + } + + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Reset() + { + return E_NOTIMPL; + } + + virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) + { + return E_NOTIMPL; + } + + DECLARE_NOT_AGGREGATABLE(CEnumRegRoot) + DECLARE_PROTECT_FINAL_CONSTRUCT() + + BEGIN_COM_MAP(CEnumRegRoot) + COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) + END_COM_MAP() + +}; + +class CEnumRegKey : + public CComObjectRootEx<CComMultiThreadModelNoCS>, + public IEnumIDList +{ + PCWSTR m_path; + HKEY m_hkey; + BOOL m_values; + int m_idx; + +public: + CEnumRegKey() + : m_path(NULL), m_hkey(NULL), m_values(FALSE), m_idx(0) + { + } + + ~CEnumRegKey() + { + RegCloseKey(m_hkey); + } + + HRESULT Initialize(PCWSTR path, HKEY root) + { + m_path = path; + + DWORD res; + if (root) + { + res = RegOpenKeyExW(root, *path == '\\' ? path + 1 : path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &m_hkey); + } + else + { + res = NtOpenObject(KEY_OBJECT, (PHANDLE) &m_hkey, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, path); + } + if (!NT_SUCCESS(res)) + { + ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); + return HRESULT_FROM_NT(res); + } + + return S_OK; + } + + HRESULT NextKey(LPITEMIDLIST* ppidl) + { + WCHAR name[MAX_PATH]; + DWORD cchName = _countof(name); + + WCHAR className[MAX_PATH]; + DWORD cchClass = _countof(className); + + if (RegEnumKeyExW(m_hkey, m_idx++, name, &cchName, 0, className, &cchClass, NULL)) + return S_FALSE; + + name[cchName] = 0; + className[cchClass] = 0; + + REG_ENTRY_TYPE otype = REG_ENTRY_KEY; + + DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); + + if (cchClass > 0) + { + entryBufferLength += sizeof(WCHAR) + cchClass * sizeof(WCHAR); + } + + // allocate space for the terminator + entryBufferLength += 2; + + RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength); + if (!entry) + return E_OUTOFMEMORY; + + memset(entry, 0, entryBufferLength); + + entry->cb = FIELD_OFFSET(RegPidlEntry, entryName); + entry->magic = REGISTRY_PIDL_MAGIC; + entry->entryType = otype; + + if (cchName > 0) + { + entry->entryNameLength = cchName * sizeof(WCHAR); + StringCbCopyNW(entry->entryName, entryBufferLength, name, entry->entryNameLength); + entry->cb += entry->entryNameLength + sizeof(WCHAR); + } + else + { + entry->entryNameLength = 0; + entry->entryName[0] = 0; + entry->cb += sizeof(WCHAR); + } + if (cchClass) { PWSTR contentData = (PWSTR) ((PBYTE) entry + entry->cb); @@ -336,24 +409,23 @@ entry->cb += entry->contentsLength + sizeof(WCHAR); } - DPA_AppendPtr(hdpa, entry); - (*hdpaCount)++; - - } - - for (int idx = 0;; ++idx) + *ppidl = (LPITEMIDLIST) entry; + return S_OK; + } + + HRESULT NextValue(LPITEMIDLIST* ppidl) { WCHAR name[MAX_PATH]; DWORD cchName = _countof(name); - DWORD type; - DWORD dataSize; - - if (RegEnumValueW(hkey, idx, name, &cchName, 0, &type, NULL, &dataSize)) - break; + DWORD type = 0; + DWORD dataSize = 0; + + if (RegEnumValueW(m_hkey, m_idx++, name, &cchName, 0, &type, NULL, &dataSize)) + return S_FALSE; REG_ENTRY_TYPE otype = REG_ENTRY_VALUE; - DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry,entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); + DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); BOOL copyData = dataSize < 32; if (copyData) @@ -362,8 +434,8 @@ otype = REG_ENTRY_VALUE_WITH_CONTENT; } - - RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength); + + RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength + 2); if (!entry) return E_OUTOFMEMORY; @@ -396,7 +468,7 @@ // In case it's an unterminated string, RegGetValue will add the NULL termination dataSize += sizeof(WCHAR); - if (!RegQueryValueExW(hkey, name, NULL, NULL, contentData, &dataSize)) + if (!RegQueryValueExW(m_hkey, name, NULL, NULL, contentData, &dataSize)) { entry->cb += entry->contentsLength + sizeof(WCHAR); } @@ -408,54 +480,168 @@ } - DPA_AppendPtr(hdpa, entry); - (*hdpaCount)++; - } - - RegCloseKey(hkey); - - return S_OK; -} - -HRESULT EnumerateRootKeys(HDPA hdpa, UINT * hdpaCount) -{ - *hdpaCount = 0; - - static struct { - HKEY key; - PCWSTR keyName; - } rootKeys [] = { - { HKEY_CLASSES_ROOT, L"HKEY_CLASSES_ROOT" }, - { HKEY_CURRENT_USER, L"HKEY_CURRENT_USER" }, - { HKEY_LOCAL_MACHINE, L"HKEY_LOCAL_MACHINE" }, - { HKEY_USERS, L"HKEY_USERS" }, - { HKEY_CURRENT_CONFIG, L"HKEY_CURRENT_CONFIG" } - }; - - for (UINT i = 0; i < _countof(rootKeys); i++) - { - PCWSTR name = rootKeys[i].keyName; - DWORD cchName = wcslen(rootKeys[i].keyName); - - REG_ENTRY_TYPE otype = REG_ENTRY_ROOT; - - DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR); - - RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength); + *ppidl = (LPITEMIDLIST) entry; + return S_OK; + } + + HRESULT EnumerateNext(LPITEMIDLIST* ppidl) + { + if (!m_values) + { + HRESULT hr = NextKey(ppidl); + if (hr != S_FALSE) + return hr; + + // switch to values. + m_values = TRUE; + m_idx = 0; + } + + return NextValue(ppidl); + } + + virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) + { + if (pceltFetched) + *pceltFetched = 0; + + while (celt-- > 0) + { + HRESULT hr = EnumerateNext(rgelt); + if (hr != S_OK) + return hr; + + if (pceltFetched) + (*pceltFetched)++; + if (rgelt) + rgelt++; + } + + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) + { + while (celt > 0) + { + HRESULT hr = EnumerateNext(NULL); + if (FAILED(hr)) + return hr; + if (hr != S_OK) + break; + } + + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Reset() + { + return E_NOTIMPL; + } + + virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) + { + return E_NOTIMPL; + } + + DECLARE_NOT_AGGREGATABLE(CEnumRegKey) + DECLARE_PROTECT_FINAL_CONSTRUCT() + + BEGIN_COM_MAP(CEnumRegKey) + COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) + END_COM_MAP() +}; + +class CEnumNTDirectory : + public CComObjectRootEx<CComMultiThreadModelNoCS>, + public IEnumIDList +{ + WCHAR buffer[MAX_PATH]; + HANDLE m_directory; + BOOL m_first; + ULONG m_enumContext; + PWSTR m_pend; + +public: + CEnumNTDirectory() + : m_directory(NULL), m_first(TRUE), m_enumContext(0), m_pend(NULL) + { + } + + ~CEnumNTDirectory() + { + NtClose(m_directory); + } + + HRESULT Initialize(PCWSTR path) + { + StringCbCopyExW(buffer, sizeof(buffer), path, &m_pend, NULL, 0); + + DWORD err = NtOpenObject(DIRECTORY_OBJECT, &m_directory, FILE_LIST_DIRECTORY, buffer); + if (!NT_SUCCESS(err)) + { + ERR("NtOpenDirectoryObject failed for path %S with status=%x\n", buffer, err); + return HRESULT_FROM_NT(err); + } + + if (m_pend[-1] != '\\') + *m_pend++ = '\\'; + + return S_OK; + } + + HRESULT EnumerateNext(LPITEMIDLIST* ppidl) + { + BYTE dirbuffer[2048]; + if (!NT_SUCCESS(NtQueryDirectoryObject(m_directory, dirbuffer, 2048, TRUE, m_first, &m_enumContext, NULL))) + return S_FALSE; + + // if ppidl is NULL, assume the caller was Skip(), + // so we don't care about the info + if (!ppidl) + return S_OK; + + m_first = FALSE; + POBJECT_DIRECTORY_INFORMATION info = (POBJECT_DIRECTORY_INFORMATION) dirbuffer; + + if (info->Name.Buffer) + { + StringCbCopyNW(m_pend, sizeof(buffer), info->Name.Buffer, info->Name.Length); + } + + OBJECT_TYPE otype = MapTypeNameToType(info->TypeName.Buffer, info->TypeName.Length); + + DWORD entryBufferLength = FIELD_OFFSET(NtPidlEntry, entryName) + sizeof(WCHAR); + if (info->Name.Buffer) + entryBufferLength += info->Name.Length; + + if (otype < 0) + { + entryBufferLength += FIELD_OFFSET(NtPidlTypeData, typeName) + sizeof(WCHAR); + + if (info->TypeName.Buffer) + { + entryBufferLength += info->TypeName.Length; + } + } + + // allocate space for the terminator + entryBufferLength += 2; + + NtPidlEntry* entry = (NtPidlEntry*) CoTaskMemAlloc(entryBufferLength); if (!entry) return E_OUTOFMEMORY; memset(entry, 0, entryBufferLength); entry->cb = FIELD_OFFSET(NtPidlEntry, entryName); - entry->magic = REGISTRY_PIDL_MAGIC; - entry->entryType = otype; - entry->rootKey = rootKeys[i].key; - - if (cchName > 0) - { - entry->entryNameLength = cchName * sizeof(WCHAR); - StringCbCopyNW(entry->entryName, entryBufferLength, name, entry->entryNameLength); + entry->magic = NT_OBJECT_PIDL_MAGIC; + entry->objectType = otype; + + if (info->Name.Buffer) + { + entry->entryNameLength = info->Name.Length; + StringCbCopyNW(entry->entryName, entryBufferLength, info->Name.Buffer, info->Name.Length); entry->cb += entry->entryNameLength + sizeof(WCHAR); } else @@ -464,58 +650,95 @@ entry->entryName[0] = 0; entry->cb += sizeof(WCHAR); } - - DPA_AppendPtr(hdpa, entry); - (*hdpaCount)++; - - } - - return S_OK; + + if (otype < 0) + { + NtPidlTypeData * typedata = (NtPidlTypeData*) ((PBYTE) entry + entry->cb); + DWORD remainingSpace = entryBufferLength - ((PBYTE) (typedata->typeName) - (PBYTE) entry); + + if (info->TypeName.Buffer) + { + typedata->typeNameLength = info->TypeName.Length; + StringCbCopyNW(typedata->typeName, remainingSpace, info->TypeName.Buffer, info->TypeName.Length); + + entry->cb += typedata->typeNameLength + sizeof(WCHAR); + } + else + { + typedata->typeNameLength = 0; + typedata->typeName[0] = 0; + entry->cb += typedata->typeNameLength + sizeof(WCHAR); + } + } + + *ppidl = (LPITEMIDLIST) entry; + + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched) + { + if (pceltFetched) + *pceltFetched = 0; + + while (celt-- > 0) + { + HRESULT hr = EnumerateNext(rgelt); + if (hr != S_OK) + return hr; + + if (pceltFetched) + (*pceltFetched)++; + if (rgelt) + rgelt++; + } + + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) + { + while (celt > 0) + { + HRESULT hr = EnumerateNext(NULL); + if (FAILED(hr)) + return hr; + if (hr != S_OK) + break; + } + + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE Reset() + { + return E_NOTIMPL; + } + + virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) + { + return E_NOTIMPL; + } + + DECLARE_NOT_AGGREGATABLE(CEnumNTDirectory) + DECLARE_PROTECT_FINAL_CONSTRUCT() + + BEGIN_COM_MAP(CEnumNTDirectory) + COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) + END_COM_MAP() +}; + +HRESULT GetEnumRegistryRoot(IEnumIDList ** ppil) +{ + return ShellObjectCreator<CEnumRegRoot>(IID_PPV_ARG(IEnumIDList, ppil)); } -HRESULT ReadRegistryValue(HKEY root, PCWSTR path, PCWSTR valueName, PVOID * valueData, PDWORD valueLength) -{ - HKEY hkey; - - DWORD res; - if (root) - { - res = RegOpenKeyExW(root, *path == '\\' ? path + 1 : path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, &hkey); - } - else - { - res = NtOpenObject(KEY_OBJECT, (PHANDLE) &hkey, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, path); - } - if (!NT_SUCCESS(res)) - { - ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); - return HRESULT_FROM_NT(res); - } - - res = RegQueryValueExW(hkey, valueName, NULL, NULL, NULL, valueLength); - - if (*valueLength > 0) - { - *valueData = (PBYTE) CoTaskMemAlloc(*valueLength); - - res = RegQueryValueExW(hkey, valueName, NULL, NULL, (PBYTE) *valueData, valueLength); - if (!NT_SUCCESS(res)) - { - CoTaskMemFree(*valueData); - *valueData = NULL; - - RegCloseKey(hkey); - - ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res); - return HRESULT_FROM_NT(res); - } - } - else - { - *valueData = NULL; - } - - RegCloseKey(hkey); - - return S_OK; +HRESULT GetEnumRegistryKey(LPCWSTR path, HKEY root, IEnumIDList ** ppil) +{ + return ShellObjectCreatorInit<CEnumRegKey>(path, root, IID_PPV_ARG(IEnumIDList, ppil)); +} + +HRESULT GetEnumNTDirectory(LPCWSTR path, IEnumIDList ** ppil) +{ + return ShellObjectCreatorInit<CEnumNTDirectory>(path, IID_PPV_ARG(IEnumIDList, ppil)); } Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/nto…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjutil.h [iso-8859-1] Fri Aug 21 14:26:25 2015 @@ -50,23 +50,14 @@ // If this is -1, there will be a NtPidlTypeData following this, and before any other extensions OBJECT_TYPE objectType; - OBJECT_BASIC_INFORMATION objectInformation; - USHORT entryNameLength; WCHAR entryName[ANYSIZE_ARRAY]; - }; struct NtPidlTypeData { USHORT typeNameLength; WCHAR typeName[ANYSIZE_ARRAY]; -}; - -struct NtPidlSymlinkData -{ - USHORT targetNameLength; - WCHAR targetName[ANYSIZE_ARRAY]; }; // REGISTRY browser @@ -107,8 +98,10 @@ #include <poppack.h> -HRESULT EnumerateNtDirectory(HDPA hdpa, PCWSTR path, UINT * hdpaCount); -HRESULT EnumerateRegistryKey(HDPA hdpa, PCWSTR path, HKEY root, UINT * hdpaCount); -HRESULT EnumerateRootKeys(HDPA hdpa, UINT * hdpaCount); +HRESULT ReadRegistryValue(HKEY root, PCWSTR path, PCWSTR valueName, PVOID * valueData, PDWORD valueLength); -HRESULT ReadRegistryValue(HKEY root, PCWSTR path, PCWSTR valueName, PVOID * valueData, PDWORD valueLength); +HRESULT GetEnumRegistryRoot(IEnumIDList ** ppil); +HRESULT GetEnumRegistryKey(LPCWSTR path, HKEY root, IEnumIDList ** ppil); +HRESULT GetEnumNTDirectory(LPCWSTR path, IEnumIDList ** ppil); + +HRESULT GetNTObjectSymbolicLinkTarget(LPCWSTR path, LPCWSTR entryName, PUNICODE_STRING LinkTarget); Modified: trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/reg…
============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] Fri Aug 21 14:26:25 2015 @@ -23,6 +23,7 @@ #define GET_SHGDN_RELATION(dwFlags) ((DWORD)dwFlags & (DWORD)0x000000FF) WINE_DEFAULT_DEBUG_CHANNEL(ntobjshex); + // {1C6D6E08-2332-4A7B-A94D-6432DB2B5AE6} const GUID CLSID_RegistryFolder = { 0x1c6d6e08, 0x2332, 0x4a7b, { 0xa9, 0x4d, 0x64, 0x32, 0xdb, 0x2b, 0x5a, 0xe6 } }; @@ -130,9 +131,6 @@ PWSTR m_ntPath; HKEY m_hRoot; - HDPA m_hDpa; - UINT m_hDpaCount; - int DpaDeleteCallback(RegPidlEntry * info) { CoTaskMemFree(info); @@ -149,186 +147,20 @@ public: CRegistryPidlManager() : m_ntPath(NULL), - m_hRoot(NULL), - m_hDpa(NULL), - m_hDpaCount(0) + m_hRoot(NULL) { } ~CRegistryPidlManager() { - DPA_DestroyCallback(m_hDpa, s_DpaDeleteCallback, this); } HRESULT Initialize(PWSTR ntPath, HKEY hRoot) { m_ntPath = ntPath; m_hRoot = hRoot; - m_hDpa = NULL; - - return S_OK; - } - - HRESULT Enumerate() - { - if (m_hDpa) - return S_OK; - - m_hDpa = DPA_Create(10); - - if (!m_hDpa) - return E_OUTOFMEMORY; - - if (wcslen(m_ntPath) == 0 && m_hRoot == NULL) - { - HRESULT hr = EnumerateRootKeys(m_hDpa, &m_hDpaCount); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - } - else - { - HRESULT hr = EnumerateRegistryKey(m_hDpa, m_ntPath, m_hRoot, &m_hDpaCount); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - } - return S_OK; - } - - HRESULT FindPidlInList(PCUITEMID_CHILD pcidl, const RegPidlEntry ** pinfo) - { - HRESULT hr; - - if (!m_hDpa) - { - hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - const RegPidlEntry * info = (const RegPidlEntry *) pcidl; - if ((info->cb < sizeof(RegPidlEntry)) || (info->magic != REGISTRY_PIDL_MAGIC)) - { - ERR("FindPidlInList: Requested pidl is not of the correct type.\n"); - return E_INVALIDARG; - } - - TRACE("Searching for pidl { name='%S' } in a list of %d items\n", info->entryName, m_hDpaCount); - - for (UINT i = 0; i < m_hDpaCount; i++) - { - const RegPidlEntry * pInfo = (const RegPidlEntry *) DPA_GetPtr(m_hDpa, i); - ASSERT(pInfo); - - hr = CompareIDs(SHCIDS_CANONICALONLY, pInfo, info); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (hr == S_OK) - { - *pinfo = pInfo; - return S_OK; - } - else - { - TRACE("Comparison returned %d for '%S'\n", (int) (short) (hr & 0xFFFF), pInfo->entryName); - } - } - - ERR("PIDL NOT FOUND: Requested filename: %S\n", info->entryName); - *pinfo = NULL; - - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - - HRESULT FindByName(LPCWSTR strParsingName, RegPidlEntry ** pinfo) - { - HRESULT hr; - - if (!m_hDpa) - { - hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - - TRACE("Searching for '%S' in a list of %d items\n", strParsingName, m_hDpaCount); - - for (int i = 0; i < (int) m_hDpaCount; i++) - { - RegPidlEntry * pInfo = (RegPidlEntry *) DPA_GetPtr(m_hDpa, i); - ASSERT(pInfo); - - int order = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, - pInfo->entryName, wcslen(pInfo->entryName), - strParsingName, wcslen(strParsingName)); - - if (order == CSTR_EQUAL) - { - *pinfo = pInfo; - return S_OK; - } - } - - TRACE("Pidl not found\n"); - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - - HRESULT GetPidl(UINT index, RegPidlEntry ** pEntry) - { - if (!m_hDpa) - { - HRESULT hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - *pEntry = NULL; - - RegPidlEntry * entry = (RegPidlEntry *) DPA_GetPtr(m_hDpa, index); - if (!entry) - { - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - - *pEntry = entry; - return S_OK; - } - - HRESULT GetCount(UINT * count) - { - if (!m_hDpa) - { - HRESULT hr = Enumerate(); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - if (!m_hDpa) - return E_FAIL; - } - - *count = m_hDpaCount; - return S_OK; - } - - - static LPITEMIDLIST CreatePidlFromItem(const RegPidlEntry * entry) - { - LPITEMIDLIST idl = (LPITEMIDLIST) CoTaskMemAlloc(entry->cb + 2); - if (!idl) - return NULL; - memset(idl, 0, entry->cb + 2); - memcpy(idl, entry, entry->cb); - return idl; + + return S_OK; } static HRESULT CompareIDs(LPARAM lParam, const RegPidlEntry * first, const RegPidlEntry * second) @@ -460,13 +292,32 @@ BOOL IsFolder(LPCITEMIDLIST pcidl) { - const RegPidlEntry * entry; - HRESULT hr = FindPidlInList(pcidl, &entry); - if (FAILED_UNEXPECTEDLY(hr)) + RegPidlEntry * entry = (RegPidlEntry*) &(pcidl->mkid); + if ((entry->cb < sizeof(RegPidlEntry)) || (entry->magic != REGISTRY_PIDL_MAGIC)) return FALSE; return (entry->entryType == REG_ENTRY_KEY) || (entry->entryType == REG_ENTRY_ROOT); + } + + HRESULT GetInfoFromPidl(LPCITEMIDLIST pcidl, const RegPidlEntry ** pentry) + { + RegPidlEntry * entry = (RegPidlEntry*) &(pcidl->mkid); + + if (entry->cb < sizeof(RegPidlEntry)) + { + DbgPrint("PCIDL too small %l (required %l)\n", entry->cb, sizeof(RegPidlEntry)); + return E_INVALIDARG; + } + + if (entry->magic != REGISTRY_PIDL_MAGIC) + { + DbgPrint("PCIDL magic mismatch %04x (expected %04x)\n", entry->magic, REGISTRY_PIDL_MAGIC); + return E_INVALIDARG; + } + + *pentry = entry; + return S_OK; } static HRESULT FormatValueData(DWORD contentType, PVOID td, DWORD contentsLength, PCWSTR * strContents) @@ -572,121 +423,6 @@ *strContents = strValue; return S_OK; } -}; - -class CRegistryFolderEnum : - public CComObjectRootEx<CComMultiThreadModelNoCS>, - public IEnumIDList -{ -private: - CComPtr<CRegistryFolder> m_Folder; - - HWND m_HwndOwner; - SHCONTF m_Flags; - - UINT m_Index; - UINT m_Count; - -public: - CRegistryFolderEnum() : - m_HwndOwner(NULL), - m_Flags(0), - m_Index(0), - m_Count(0) - { - } - - virtual ~CRegistryFolderEnum() - { - } - - HRESULT Initialize(CRegistryFolder * folder, HWND hwndOwner, SHCONTF flags) - { - m_Folder = folder; - - m_Folder->GetManager().GetCount(&m_Count); - - m_HwndOwner = hwndOwner; - m_Flags = flags; - - return Reset(); - } - - virtual HRESULT STDMETHODCALLTYPE Next( - ULONG celt, - LPITEMIDLIST *rgelt, - ULONG *pceltFetched) - { - if (pceltFetched) - *pceltFetched = 0; - - if (m_Index >= m_Count) - return S_FALSE; - - for (int i = 0; i < (int) celt;) - { - RegPidlEntry * tinfo; - BOOL flagsOk = FALSE; - - do { - HRESULT hr = m_Folder->GetManager().GetPidl(m_Index++, &tinfo); - if (FAILED_UNEXPECTEDLY(hr)) - return hr; - - switch (tinfo->entryType) - { - case REG_ENTRY_KEY: - case REG_ENTRY_ROOT: - flagsOk = (m_Flags & SHCONTF_FOLDERS) != 0; - break; - default: - flagsOk = (m_Flags & SHCONTF_NONFOLDERS) != 0; - break; - } - } while (m_Index < m_Count && !flagsOk); - - if (flagsOk) - { - if (rgelt) - rgelt[i] = m_Folder->GetManager().CreatePidlFromItem(tinfo); - i++; - } - - if (m_Index == m_Count) - { - if (pceltFetched) - *pceltFetched = i; - return (i == (int) celt) ? S_OK : S_FALSE; - } - } - - if (pceltFetched) *pceltFetched = celt; - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) - { - return Next(celt, NULL, NULL); - } - - virtual HRESULT STDMETHODCALLTYPE Reset() - { - m_Index = 0; - return S_OK; - } - - virtual HRESULT STDMETHODCALLTYPE Clone(IEnumIDList **ppenum) - { - return ShellObjectCreatorInit<CRegistryFolderEnum>(m_Folder, m_HwndOwner, m_Flags, IID_PPV_ARG(IEnumIDList, ppenum)); - } - - DECLARE_NOT_AGGREGATABLE(CRegistryFolderEnum) - DECLARE_PROTECT_FINAL_CONSTRUCT() - - BEGIN_COM_MAP(CRegistryFolderEnum) - COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList) - END_COM_MAP() - }; //----------------------------------------------------------------------------- @@ -715,8 +451,6 @@ LPITEMIDLIST *ppidl, ULONG *pdwAttributes) { - RegPidlEntry * info; - if (!ppidl) return E_POINTER; @@ -728,19 +462,45 @@ TRACE("CRegistryFolder::ParseDisplayName name=%S (ntPath=%S)\n", lpszDisplayName, m_NtPath); - HRESULT hr = m_PidlManager->FindByName(lpszDisplayName, &info); + const RegPidlEntry * info; + IEnumIDList * it; + HRESULT hr = GetEnumNTDirectory(m_NtPath, &it); if (FAILED(hr)) { return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); } - *ppidl = m_PidlManager->CreatePidlFromItem(info); - - if (pchEaten) - *pchEaten = wcslen(info->entryName); - - if (pdwAttributes) - *pdwAttributes = m_PidlManager->ConvertAttributes(info, pdwAttributes); + while (TRUE) + { + hr = it->Next(1, ppidl, NULL); + + if (FAILED(hr)) + return hr; + + if (hr != S_OK) + break; + + hr = m_PidlManager->GetInfoFromPidl(*ppidl, &info); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (StrCmpW(info->entryName, lpszDisplayName) == 0) + break; + } + + if (hr != S_OK) + { + return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); + } + + if (pchEaten || pdwAttributes) + { + if (pchEaten) + *pchEaten = wcslen(info->entryName); + + if (pdwAttributes) + *pdwAttributes = m_PidlManager->ConvertAttributes(info, pdwAttributes); + } return S_OK; } @@ -750,7 +510,14 @@ SHCONTF grfFlags, IEnumIDList **ppenumIDList) { - return ShellObjectCreatorInit<CRegistryFolderEnum>(this, hwndOwner, grfFlags, IID_PPV_ARG(IEnumIDList, ppenumIDList)); + if (wcslen(m_NtPath) == 0 && m_hRoot == NULL) + { + return GetEnumRegistryRoot(ppenumIDList); + } + else + { + return GetEnumRegistryKey(m_NtPath, m_hRoot, ppenumIDList); + } } HRESULT STDMETHODCALLTYPE CRegistryFolder::BindToObject( @@ -763,7 +530,7 @@ if (IsEqualIID(riid, IID_IShellFolder)) { - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -886,7 +653,7 @@ { PCUITEMID_CHILD pidl = apidl[i]; - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -913,12 +680,15 @@ { CComPtr<IContextMenu> pcm; - HKEY keys [1]; + DWORD res; + HKEY keys[1]; int nkeys = _countof(keys); if (cidl == 1 && m_PidlManager->IsFolder(apidl[0])) { - RegOpenKey(HKEY_CLASSES_ROOT, L"Folder", keys + 0); + res = RegOpenKey(HKEY_CLASSES_ROOT, L"Folder", keys + 0); + if (!NT_SUCCESS(res)) + return HRESULT_FROM_NT(res); } else { @@ -971,7 +741,7 @@ TRACE("GetDisplayNameOf %p\n", pidl); - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -1144,7 +914,7 @@ if (pidl) { - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -1170,7 +940,7 @@ { if (info->contentsLength > 0) { - PWSTR td = (PWSTR)(((PBYTE) info) + FIELD_OFFSET(RegPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); + PWSTR td = (PWSTR) (((PBYTE) info) + FIELD_OFFSET(RegPidlEntry, entryName) + info->entryNameLength + sizeof(WCHAR)); return MakeVariantString(pv, td); } @@ -1217,7 +987,7 @@ if (pidl) { - HRESULT hr = m_PidlManager->FindPidlInList(pidl, &info); + HRESULT hr = m_PidlManager->GetInfoFromPidl(pidl, &info); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -1343,8 +1113,6 @@ return S_FALSE; case SFVM_BACKGROUNDENUM: return S_OK; - case SFVM_DEFITEMCOUNT: - return m_PidlManager->GetCount((UINT*) lParam); } return E_NOTIMPL; }
9 years, 4 months
1
0
0
0
[pschweitzer] 68782: [NTOSKRNL] Addendum to r68759: don't forget to initialize semaphore.
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Fri Aug 21 11:21:14 2015 New Revision: 68782 URL:
http://svn.reactos.org/svn/reactos?rev=68782&view=rev
Log: [NTOSKRNL] Addendum to r68759: don't forget to initialize semaphore. Modified: trunk/reactos/ntoskrnl/fsrtl/fsrtlpc.c Modified: trunk/reactos/ntoskrnl/fsrtl/fsrtlpc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/fsrtl/fsrtlpc.c?r…
============================================================================== --- trunk/reactos/ntoskrnl/fsrtl/fsrtlpc.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/fsrtl/fsrtlpc.c [iso-8859-1] Fri Aug 21 11:21:14 2015 @@ -17,6 +17,7 @@ PERESOURCE FsRtlPagingIoResources; ULONG FsRtlPagingIoResourceSelector; NTSTATUS NTAPI INIT_FUNCTION FsRtlInitializeWorkerThread(VOID); +extern KSEMAPHORE FsRtlpUncSemaphore; static const UCHAR LegalAnsiCharacterArray[] = { @@ -172,6 +173,7 @@ FsRtlInitializeTunnels(); FsRtlInitializeLargeMcbs(); + KeInitializeSemaphore(&FsRtlpUncSemaphore, 1, MAXLONG); /* Allocate the Resource Buffer */ FsRtlPagingIoResources = FsRtlAllocatePoolWithTag(NonPagedPool,
9 years, 4 months
1
0
0
0
[pschweitzer] 68781: [NTOSKRNL] Define UNC tag in tag header
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Fri Aug 21 08:17:48 2015 New Revision: 68781 URL:
http://svn.reactos.org/svn/reactos?rev=68781&view=rev
Log: [NTOSKRNL] Define UNC tag in tag header Modified: trunk/reactos/ntoskrnl/fsrtl/unc.c trunk/reactos/ntoskrnl/include/internal/tag.h Modified: trunk/reactos/ntoskrnl/fsrtl/unc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/fsrtl/unc.c?rev=6…
============================================================================== --- trunk/reactos/ntoskrnl/fsrtl/unc.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/fsrtl/unc.c [iso-8859-1] Fri Aug 21 08:17:48 2015 @@ -11,8 +11,6 @@ #include <ntoskrnl.h> #define NDEBUG #include <debug.h> - -#define TAG_UNC 'nuSF' KSEMAPHORE FsRtlpUncSemaphore; Modified: trunk/reactos/ntoskrnl/include/internal/tag.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
============================================================================== --- trunk/reactos/ntoskrnl/include/internal/tag.h [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/include/internal/tag.h [iso-8859-1] Fri Aug 21 08:17:48 2015 @@ -28,6 +28,9 @@ /* formerly located in fs/notify.c */ #define FSRTL_NOTIFY_TAG 'ITON' + +/* formerly located in fsrtl/unc.c */ +#define TAG_UNC 'nuSF' /* formerly located in io/device.c */ #define TAG_DEVICE_EXTENSION 'TXED'
9 years, 4 months
1
0
0
0
[pschweitzer] 68780: [ROSVBOXMGMT] Add missing L for help
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Fri Aug 21 08:10:53 2015 New Revision: 68780 URL:
http://svn.reactos.org/svn/reactos?rev=68780&view=rev
Log: [ROSVBOXMGMT] Add missing L for help Modified: trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c Modified: trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/cmdutils/rosv…
============================================================================== --- trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c [iso-8859-1] (original) +++ trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c [iso-8859-1] Fri Aug 21 08:10:53 2015 @@ -138,11 +138,11 @@ void printUsage(void) { - wprintf("ReactOS VBox Shared Folders Management\n"); - wprintf("\tstart: start the VBox Shared folders (mandatory prior any operation!)\n"); - wprintf("\taddconn <letter> <share name>: add a connection\n"); - wprintf("\tgetlist: list connections\n"); - wprintf("\tgetgloballist: list available shares\n"); + wprintf(L"ReactOS VBox Shared Folders Management\n"); + wprintf(L"\tstart: start the VBox Shared folders (mandatory prior any operation!)\n"); + wprintf(L"\taddconn <letter> <share name>: add a connection\n"); + wprintf(L"\tgetlist: list connections\n"); + wprintf(L"\tgetgloballist: list available shares\n"); } int wmain(int argc, wchar_t *argv[])
9 years, 4 months
1
0
0
0
[pschweitzer] 68779: Erm. Addendum to r68778: don't reveal my secret plans to world (yet!)
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Fri Aug 21 08:08:10 2015 New Revision: 68779 URL:
http://svn.reactos.org/svn/reactos?rev=68779&view=rev
Log: Erm. Addendum to r68778: don't reveal my secret plans to world (yet!) Modified: trunk/rosapps/applications/cmdutils/CMakeLists.txt Modified: trunk/rosapps/applications/cmdutils/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/cmdutils/CMak…
============================================================================== --- trunk/rosapps/applications/cmdutils/CMakeLists.txt [iso-8859-1] (original) +++ trunk/rosapps/applications/cmdutils/CMakeLists.txt [iso-8859-1] Fri Aug 21 08:08:10 2015 @@ -1,6 +1,5 @@ add_subdirectory(appwiz) add_subdirectory(cat) -add_subdirectory(nfi) add_subdirectory(ntfsinfo) add_subdirectory(rosvboxmgmt) add_subdirectory(tee)
9 years, 4 months
1
0
0
0
[pschweitzer] 68777: [NTOSKRNL] Implement the TokenImpersonationLevel case of SeQueryInformationToken(). This fixes VBoxSF driver not being able to expose shared folders in ReactOS
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Fri Aug 21 08:03:11 2015 New Revision: 68777 URL:
http://svn.reactos.org/svn/reactos?rev=68777&view=rev
Log: [NTOSKRNL] Implement the TokenImpersonationLevel case of SeQueryInformationToken(). This fixes VBoxSF driver not being able to expose shared folders in ReactOS Modified: trunk/reactos/ntoskrnl/se/token.c Modified: trunk/reactos/ntoskrnl/se/token.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/se/token.c?rev=68…
============================================================================== --- trunk/reactos/ntoskrnl/se/token.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/se/token.c [iso-8859-1] Fri Aug 21 08:03:11 2015 @@ -1076,8 +1076,40 @@ IN TOKEN_INFORMATION_CLASS TokenInformationClass, OUT PVOID *TokenInformation) { - UNIMPLEMENTED; - return STATUS_NOT_IMPLEMENTED; + NTSTATUS Status; + PSECURITY_IMPERSONATION_LEVEL SeImpersonationLvl; + PAGED_CODE(); + + switch (TokenInformationClass) + { + case TokenImpersonationLevel: + /* It is mandatory to have an impersonation token */ + if (((PTOKEN)Token)->TokenType != TokenImpersonation) + { + Status = STATUS_INVALID_INFO_CLASS; + break; + } + + /* Allocate the output buffer */ + SeImpersonationLvl = ExAllocatePoolWithTag(PagedPool, sizeof(SECURITY_IMPERSONATION_LEVEL), TAG_SE); + if (SeImpersonationLvl == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + break; + } + + /* Set impersonation level and return the structure */ + *SeImpersonationLvl = ((PTOKEN)Token)->ImpersonationLevel; + *TokenInformation = SeImpersonationLvl; + Status = STATUS_SUCCESS; + break; + + default: + UNIMPLEMENTED; + break; + } + + return Status; } /*
9 years, 4 months
1
0
0
0
[pschweitzer] 68778: [ROSVBOXMGMT] Add the "rosvboxmgmt" tool. It's purpose is to allow to interact with the VBoxSF driver as we don't have working MPR yet. In order to have UNC path available, all...
by pschweitzer@svn.reactos.org
Author: pschweitzer Date: Fri Aug 21 08:03:13 2015 New Revision: 68778 URL:
http://svn.reactos.org/svn/reactos?rev=68778&view=rev
Log: [ROSVBOXMGMT] Add the "rosvboxmgmt" tool. It's purpose is to allow to interact with the VBoxSF driver as we don't have working MPR yet. In order to have UNC path available, all you need to do so far is rosvboxmgmt start. All the rest isn't mandatory. Added: trunk/rosapps/applications/cmdutils/rosvboxmgmt/ trunk/rosapps/applications/cmdutils/rosvboxmgmt/CMakeLists.txt (with props) trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c (with props) trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.rc (with props) Modified: trunk/rosapps/applications/cmdutils/CMakeLists.txt Modified: trunk/rosapps/applications/cmdutils/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/cmdutils/CMak…
============================================================================== --- trunk/rosapps/applications/cmdutils/CMakeLists.txt [iso-8859-1] (original) +++ trunk/rosapps/applications/cmdutils/CMakeLists.txt [iso-8859-1] Fri Aug 21 08:03:13 2015 @@ -1,6 +1,8 @@ add_subdirectory(appwiz) add_subdirectory(cat) +add_subdirectory(nfi) add_subdirectory(ntfsinfo) +add_subdirectory(rosvboxmgmt) add_subdirectory(tee) add_subdirectory(touch) add_subdirectory(uptime) Added: trunk/rosapps/applications/cmdutils/rosvboxmgmt/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/cmdutils/rosv…
============================================================================== --- trunk/rosapps/applications/cmdutils/rosvboxmgmt/CMakeLists.txt (added) +++ trunk/rosapps/applications/cmdutils/rosvboxmgmt/CMakeLists.txt [iso-8859-1] Fri Aug 21 08:03:13 2015 @@ -0,0 +1,4 @@ +add_executable(rosvboxmgmt rosvboxmgmt.c rosvboxmgmt.rc) +set_module_type(rosvboxmgmt win32cui UNICODE) +add_importlibs(rosvboxmgmt msvcrt kernel32) +add_cd_file(TARGET rosvboxmgmt DESTINATION reactos/bin FOR all) Propchange: trunk/rosapps/applications/cmdutils/rosvboxmgmt/CMakeLists.txt ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/cmdutils/rosv…
============================================================================== --- trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c (added) +++ trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c [iso-8859-1] Fri Aug 21 08:03:13 2015 @@ -0,0 +1,187 @@ +#include <stdio.h> +#include <wchar.h> +#include <windows.h> + +/* DON'T CHANGE ORDER!!!! */ +PCWSTR devices[3] = { L"\\\\.\\VBoxMiniRdrDN", L"\\??\\VBoxMiniRdrDN", L"\\Device\\VBoxMiniRdr" }; + +/* Taken from VBox header */ +#define _MRX_MAX_DRIVE_LETTERS 26 +#define IOCTL_MRX_VBOX_BASE FILE_DEVICE_NETWORK_FILE_SYSTEM +#define _MRX_VBOX_CONTROL_CODE(request, method, access) \ + CTL_CODE(IOCTL_MRX_VBOX_BASE, request, method, access) +#define IOCTL_MRX_VBOX_ADDCONN _MRX_VBOX_CONTROL_CODE(100, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_MRX_VBOX_GETLIST _MRX_VBOX_CONTROL_CODE(103, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_MRX_VBOX_GETGLOBALLIST _MRX_VBOX_CONTROL_CODE(104, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_MRX_VBOX_START _MRX_VBOX_CONTROL_CODE(106, METHOD_BUFFERED, FILE_ANY_ACCESS) + +BOOL performDevIoCtl(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize) +{ + short i; + BOOL ret; + DWORD lpBytesReturned; + HANDLE dev = INVALID_HANDLE_VALUE; + + wprintf(L"Trying to open a VBoxSRV device\n"); + for (i = 0; i < 3; ++i) + { + dev = CreateFile(devices[i], + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + if (dev != INVALID_HANDLE_VALUE) + { + break; + } + } + + if (dev == INVALID_HANDLE_VALUE) + { + return FALSE; + } + + wprintf(L"%s opened.\n", devices[i]); + + ret = DeviceIoControl(dev, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, &lpBytesReturned, NULL); + wprintf(L"Done: it %s with error: %lx\n", (ret != 0 ? L"succeed" : L"failed"), (ret != 0 ? ERROR_SUCCESS : GetLastError())); + + CloseHandle(dev); + + return ret; +} + +int startVBoxSrv(void) +{ + return (performDevIoCtl(IOCTL_MRX_VBOX_START, NULL, 0, NULL, 0) == FALSE); +} + +int addConn(PCWSTR letter, PCWSTR path) +{ + BOOL ret; + PWSTR inputBuffer; + DWORD inputBufferSize; + + if (iswalpha(letter[0]) == 0) + { + wprintf(L"Invalid letter provided\n"); + return 1; + } + + if (wcschr(path, L'\\') != NULL) + { + wprintf(L"Only give the name of a share\n"); + return 1; + } + + inputBufferSize = (wcslen(path) + wcslen(devices[2]) + wcslen(L"\\;Z:\\vboxsvr\\")) * sizeof(WCHAR) + sizeof(UNICODE_NULL); + inputBuffer = malloc(inputBufferSize); + if (inputBuffer == NULL) + { + wprintf(L"Memory failure\n"); + return 1; + } + + swprintf(inputBuffer, L"%s\\;%c:\\vboxsvr\\%s", devices[2], towupper(letter[0]), path); + wprintf(L"Will create the following connection: %s\n", inputBuffer); + ret = performDevIoCtl(IOCTL_MRX_VBOX_ADDCONN, inputBuffer, inputBufferSize, NULL, 0); + free(inputBuffer); + + return (ret == FALSE); +} + +int getList(void) +{ + short i; + BOOL ret; + DWORD outputBufferSize; + char outputBuffer[_MRX_MAX_DRIVE_LETTERS]; + + outputBufferSize = sizeof(outputBuffer); + ret = performDevIoCtl(IOCTL_MRX_VBOX_GETLIST, NULL, 0, &outputBuffer, outputBufferSize); + if (ret == FALSE) + { + return 1; + } + + for (i = 0; i < _MRX_MAX_DRIVE_LETTERS; i += 2) + { + wprintf(L"%c: %s\t%c: %s\n", 'A' + i, (outputBuffer[i] == 0 ? L"FALSE" : L"TRUE"), + 'A' + (i + 1), (outputBuffer[i + 1] == 0 ? L"FALSE" : L"TRUE")); + } + + return 0; +} + +int getGlobalList(void) +{ + short i; + BOOL ret; + DWORD outputBufferSize; + char outputBuffer[_MRX_MAX_DRIVE_LETTERS]; + + outputBufferSize = sizeof(outputBuffer); + memset(outputBuffer, 0, outputBufferSize); + ret = performDevIoCtl(IOCTL_MRX_VBOX_GETGLOBALLIST, NULL, 0, &outputBuffer, outputBufferSize); + if (ret == FALSE) + { + return 1; + } + + for (i = 0; i < _MRX_MAX_DRIVE_LETTERS; i += 2) + { + wprintf(L"%c: %s\t%c: %s\n", 'A' + i, (outputBuffer[i] & 0x80 ? L"Active" : L"Inactive"), + 'A' + (i + 1), (outputBuffer[i + 1] & 0x80 ? L"Active" : L"Inactive")); + } + + return 0; +} + +void printUsage(void) +{ + wprintf("ReactOS VBox Shared Folders Management\n"); + wprintf("\tstart: start the VBox Shared folders (mandatory prior any operation!)\n"); + wprintf("\taddconn <letter> <share name>: add a connection\n"); + wprintf("\tgetlist: list connections\n"); + wprintf("\tgetgloballist: list available shares\n"); +} + +int wmain(int argc, wchar_t *argv[]) +{ + PCWSTR cmd; + + if (argc == 1) + { + printUsage(); + return 0; + } + + cmd = argv[1]; + + if (_wcsicmp(cmd, L"start") == 0) + { + return startVBoxSrv(); + } + else if (_wcsicmp(cmd, L"addconn") == 0) + { + if (argc < 4) + { + printUsage(); + return 0; + } + + return addConn(argv[2], argv[3]); + } + else if (_wcsicmp(cmd, L"getlist") == 0) + { + return getList(); + } + else if (_wcsicmp(cmd, L"getgloballist") == 0) + { + return getGlobalList(); + } + else + { + printUsage(); + return 0; + } +} Propchange: trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.c ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.rc URL:
http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/cmdutils/rosv…
============================================================================== --- trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.rc (added) +++ trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.rc [iso-8859-1] Fri Aug 21 08:03:13 2015 @@ -0,0 +1,5 @@ + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS VBoxSRV management tool\0" +#define REACTOS_STR_INTERNAL_NAME "rosvboxmgmt\0" +#define REACTOS_STR_ORIGINAL_FILENAME "rosvboxmgmt.exe\0" +#include <reactos/version.rc> Propchange: trunk/rosapps/applications/cmdutils/rosvboxmgmt/rosvboxmgmt.rc ------------------------------------------------------------------------------ svn:eol-style = native
9 years, 4 months
1
0
0
0
[hbelusca] 68776: [SDK:SCRNSAVE] - Add support for specifying a parent window handle for the screensaver configuration dialog, adapted from patch by Timo Kreuzer, see CORE-5718. - Fix failure retur...
by hbelusca@svn.reactos.org
Author: hbelusca Date: Thu Aug 20 19:44:13 2015 New Revision: 68776 URL:
http://svn.reactos.org/svn/reactos?rev=68776&view=rev
Log: [SDK:SCRNSAVE] - Add support for specifying a parent window handle for the screensaver configuration dialog, adapted from patch by Timo Kreuzer, see CORE-5718. - Fix failure return values from the helper functions. - Add TranslateMessage call in the message pump. - Get the correct left/top coordinates for the screensaver, being multi-screen aware. - Use Win-compatible window names & styles for the screensaver preview dialog & screensaver window, compatible MS' scrnsave.lib. Modified: trunk/reactos/lib/sdk/scrnsave/scrnsave.c Modified: trunk/reactos/lib/sdk/scrnsave/scrnsave.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/scrnsave/scrnsave.…
============================================================================== --- trunk/reactos/lib/sdk/scrnsave/scrnsave.c [iso-8859-1] (original) +++ trunk/reactos/lib/sdk/scrnsave/scrnsave.c [iso-8859-1] Thu Aug 20 19:44:13 2015 @@ -2,7 +2,8 @@ * PROJECT: ReactOS Screen Saver Library * LICENSE: GPL v2 or any later version * FILE: lib/sdk/scrnsave/scrnsave.c - * PURPOSE: Library for writing screen savers, compatible with MS' scrnsave.lib + * PURPOSE: Library for writing screen savers, compatible with + * MS' scrnsave.lib without Win9x support. * PROGRAMMERS: Anders Norlander <anorland(a)hem2.passagen.se> * Colin Finck <mail(a)colinfinck.de> */ @@ -38,7 +39,7 @@ return (c == ' ' || c == '\t'); } -#define ISNUM(c) ((c) >= '0' && c <= '9') +#define ISNUM(c) ((c) >= '0' && (c) <= '9') static ULONG_PTR _toulptr(const TCHAR *s) { @@ -78,9 +79,11 @@ { switch (wParam) { - case SC_CLOSE: - case SC_SCREENSAVE: - return FALSE; + case SC_CLOSE: // - Closing the screen saver, or... + case SC_NEXTWINDOW: // - Switching to + case SC_PREVWINDOW: // different windows, or... + case SC_SCREENSAVE: // - Starting another screen saver: + return FALSE; // Fail it! } } break; @@ -102,7 +105,7 @@ case WM_ACTIVATEAPP: if (!wParam) { - // wParam is FALSE, so the screensaver is losing the focus. + // wParam is FALSE, so the screen saver is losing the focus. PostMessage(hWnd, WM_CLOSE, 0, 0); } break; @@ -111,6 +114,8 @@ { POINT pt; GetCursorPos(&pt); + // TODO: Implement mouse move threshold. See: + //
http://svn.reactos.org/svn/reactos/trunk/rosapps/applications/screensavers/…
if (pt.x == pt_orig.x && pt.y == pt_orig.y) break; @@ -118,11 +123,14 @@ } case WM_LBUTTONDOWN: + case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: - case WM_MBUTTONDOWN: + case WM_XBUTTONDOWN: case WM_KEYDOWN: case WM_KEYUP: - // Send a WM_CLOSE to close the screen saver (allows the screensaver author to do clean-up tasks) + case WM_SYSKEYDOWN: + // Send a WM_CLOSE to close the screen saver (allows + // the screen saver to perform clean-up tasks) PostMessage(hWnd, WM_CLOSE, 0, 0); break; @@ -137,60 +145,81 @@ // Registers the screen saver window class static BOOL RegisterScreenSaverClass(void) { - WNDCLASS cls = {0,}; - - cls.hIcon = LoadIcon(hMainInstance, MAKEINTATOM(ID_APP)); + WNDCLASS cls; + + cls.hCursor = NULL; + cls.hIcon = LoadIcon(hMainInstance, MAKEINTATOM(ID_APP)); + cls.lpszMenuName = NULL; cls.lpszClassName = CLASS_SCRNSAVE; cls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - cls.hInstance = hMainInstance; - cls.style = CS_VREDRAW | CS_HREDRAW | CS_SAVEBITS | CS_PARENTDC; - cls.lpfnWndProc = SysScreenSaverProc; - - return RegisterClass(&cls) != 0; -} - -static void LaunchConfig(void) + cls.hInstance = hMainInstance; + cls.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_SAVEBITS | CS_PARENTDC; + cls.lpfnWndProc = SysScreenSaverProc; + cls.cbWndExtra = 0; + cls.cbClsExtra = 0; + + return (RegisterClass(&cls) != 0); +} + +static int LaunchConfig(HWND hParent) { // Only show the dialog if the RegisterDialogClasses function succeeded. // This is the same behaviour as MS' scrnsave.lib. - if( RegisterDialogClasses(hMainInstance) ) - DialogBox(hMainInstance, MAKEINTRESOURCE(DLG_SCRNSAVECONFIGURE), GetForegroundWindow(), (DLGPROC) ScreenSaverConfigureDialog); + if (!RegisterDialogClasses(hMainInstance)) + return -1; + + return DialogBox(hMainInstance, MAKEINTRESOURCE(DLG_SCRNSAVECONFIGURE), + hParent, (DLGPROC)ScreenSaverConfigureDialog); } static int LaunchScreenSaver(HWND hParent) { - UINT style; + LPCTSTR lpWindowName; + UINT style, exstyle; RECT rc; MSG msg; if (!RegisterScreenSaverClass()) { MessageBox(NULL, TEXT("RegisterClass() failed"), NULL, MB_ICONHAND); - return 1; + return -1; } // A slightly different approach needs to be used when displaying in a preview window if (hParent) { - style = WS_CHILD; + fChildPreview = TRUE; + lpWindowName = TEXT("Preview"); + + style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN; + exstyle = 0; + GetClientRect(hParent, &rc); + rc.left = 0; + rc.top = 0; } else { - style = WS_POPUP; - rc.right = GetSystemMetrics(SM_CXVIRTUALSCREEN); + fChildPreview = FALSE; + lpWindowName = TEXT("Screen Saver"); + + style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; + exstyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST; + + // Get the left & top side coordinates of the virtual screen + rc.left = GetSystemMetrics(SM_XVIRTUALSCREEN); + rc.top = GetSystemMetrics(SM_YVIRTUALSCREEN); + // Get the width and height of the virtual screen + rc.right = GetSystemMetrics(SM_CXVIRTUALSCREEN); rc.bottom = GetSystemMetrics(SM_CYVIRTUALSCREEN); - style |= WS_VISIBLE; } // Create the main screen saver window - hMainWindow = CreateWindowEx(hParent ? 0 : WS_EX_TOPMOST, CLASS_SCRNSAVE, - TEXT("SCREENSAVER"), style, - 0, 0, rc.right, rc.bottom, hParent, NULL, - hMainInstance, NULL); - - if(!hMainWindow) - return 1; + hMainWindow = CreateWindowEx(exstyle, CLASS_SCRNSAVE, lpWindowName, style, + rc.left, rc.top, rc.right, rc.bottom, + hParent, NULL, hMainInstance, NULL); + if (!hMainWindow) + return -1; // Display window and start pumping messages ShowWindow(hMainWindow, SW_SHOW); @@ -198,7 +227,10 @@ SetCursor(NULL); while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); DispatchMessage(&msg); + } return msg.wParam; } @@ -208,12 +240,16 @@ { LPTSTR p; - UNREFERENCED_PARAMETER(nCmdShow); - UNREFERENCED_PARAMETER(hPrevInst); + UNREFERENCED_PARAMETER(nCmdShow); + UNREFERENCED_PARAMETER(hPrevInst); hMainInstance = hInst; - // Parse the arguments + // Parse the arguments: + // -a <hwnd> (Change the password; only for Win9x, unused on WinNT) + // -s (Run the screensaver) + // -p <hwnd> (Preview) + // -c <hwnd> (Configure) for (p = CmdLine; *p; p++) { switch (*p) @@ -226,23 +262,34 @@ case 'P': case 'p': { + HWND hParent; + + while (ISSPACE(*++p)); + hParent = (HWND)_toulptr(p); + // Start the screen saver in preview mode - HWND hParent; - fChildPreview = TRUE; - - while (ISSPACE(*++p)); - hParent = (HWND) _toulptr(p); - if (hParent && IsWindow(hParent)) return LaunchScreenSaver(hParent); + else + return -1; } - return 0; case 'C': case 'c': + { + HWND hParent; + + if (p[1] == ':') + hParent = (HWND)_toulptr(p + 2); + else + hParent = GetForegroundWindow(); + // Display the configuration dialog - LaunchConfig(); - return 0; + if (hParent && IsWindow(hParent)) + return LaunchConfig(hParent); + else + return -1; + } case '-': case '/': @@ -252,7 +299,5 @@ } } - LaunchConfig(); - - return 0; -} + return LaunchConfig(NULL); +}
9 years, 4 months
1
0
0
0
← Newer
1
...
8
9
10
11
12
13
14
...
31
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Results per page:
10
25
50
100
200