ReactOS 0.4.15-dev-5875-g7c755d9
CShellCommandDir Class Reference

#include <ShellCommandDir.h>

Inheritance diagram for CShellCommandDir:
Collaboration diagram for CShellCommandDir:

Public Member Functions

 CShellCommandDir (CRegistryTree &rTree)
 
virtual ~CShellCommandDir ()
 
virtual BOOL Match (const TCHAR *pchCommand)
 
virtual int Execute (CConsole &rConsole, CArgumentParser &rArguments)
 
virtual const TCHARGetHelpString ()
 
virtual const TCHARGetHelpShortDescriptionString ()
 
- Public Member Functions inherited from CShellCommand
 CShellCommand ()
 
virtual ~CShellCommand ()
 
virtual BOOL Match (const TCHAR *pchCommand)=0
 
virtual int Execute (CConsole &rConsole, CArgumentParser &rArguments)=0
 
virtual const TCHARGetHelpString ()=0
 
virtual const TCHARGetHelpShortDescriptionString ()=0
 

Private Attributes

CRegistryTreem_rTree
 

Detailed Description

Definition at line 12 of file ShellCommandDir.h.

Constructor & Destructor Documentation

◆ CShellCommandDir()

CShellCommandDir::CShellCommandDir ( CRegistryTree rTree)

Definition at line 51 of file ShellCommandDir.cpp.

51 :m_rTree(rTree)
52{
53}
CRegistryTree & m_rTree

◆ ~CShellCommandDir()

CShellCommandDir::~CShellCommandDir ( )
virtual

Definition at line 55 of file ShellCommandDir.cpp.

56{
57}

Member Function Documentation

◆ Execute()

int CShellCommandDir::Execute ( CConsole rConsole,
CArgumentParser rArguments 
)
virtual

Implements CShellCommand.

Definition at line 72 of file ShellCommandDir.cpp.

73{
74 rArguments.ResetArgumentIteration();
75
76 BOOL blnDo = TRUE,blnBadParameter, blnHelp = FALSE;
77 TCHAR *pszParameter;
78 TCHAR *pszCommandItself = rArguments.GetNextArgument();
79 TCHAR *pszKey = NULL;
80
81 if ((_tcsnicmp(pszCommandItself,DIR_CMD _T(".."),DIR_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
82 (_tcsnicmp(pszCommandItself,DIR_CMD _T("\\"),DIR_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
83 {
84 pszKey = pszCommandItself + DIR_CMD_LENGTH;
85 }
86 else if (_tcsnicmp(pszCommandItself,DIR_CMD _T("/"),DIR_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
87 {
88 pszParameter = pszCommandItself + DIR_CMD_LENGTH;
89 goto CheckDirArgument;
90 }
91
92 while((pszParameter = rArguments.GetNextArgument()) != NULL)
93 {
94CheckDirArgument:
95 blnBadParameter = FALSE;
96 if ((_tcsicmp(pszParameter,_T("/?")) == 0)
97 ||(_tcsicmp(pszParameter,_T("-?")) == 0))
98 {
99 blnHelp = TRUE;
100 blnDo = pszKey != NULL;
101 }
102 else if (!pszKey)
103 {
104 pszKey = pszParameter;
105 blnDo = TRUE;
106 }
107 else
108 {
109 blnBadParameter = TRUE;
110 }
111 if (blnBadParameter)
112 {
113 rConsole.Write(_T("Bad parameter: "));
114 rConsole.Write(pszParameter);
115 rConsole.Write(_T("\n"));
116 }
117 }
118
119 const TCHAR *pszPattern = PATTERN_MATCH_ALL;
120 const TCHAR *pszPath = _T(".");
121
122 if (pszKey)
123 {
124 pszPath = pszKey;
125
126 TCHAR *pch = pszKey;
127 while(*pch) // search end of string
128 pch++;
129
130 if (pch > pszKey) // last non-null char
131 pch--;
132
133 if (*pch != _T('\\'))
134 {
135 while ((pch > pszKey) && (*pch != _T('\\')))
136 pch--;
137
138 if (*pch == _T('\\'))
139 {
140 pszPattern = pch+1;
141
142 if (pch > pszKey)
143 {
144 ASSERT(*pch == _T('\\'));
145 *pch = 0;
146 }
147 else if (*pch == _T('\\'))
148 {
149 pszPath = _T("\\");
150 }
151 }
152 else
153 {
154 pszPattern = pszKey;
155 pszPath = _T(".");
156 }
157 }
158 }
159
161
163 {
164 const TCHAR *pszErrorMsg = m_rTree.GetLastErrorDescription();
165 rConsole.Write(pszErrorMsg);
166 blnDo = FALSE;
167 }
168
169 if (blnHelp)
170 {
171 rConsole.Write(GetHelpString());
172 }
173
174 LONG nError;
175
176 if (!blnDo)
177 return 0;
178
179 rConsole.Write(_T("\n Key is "));
180 rConsole.Write(Key.GetKeyName());
181
182 if (!Key.IsRoot())
183 {
184 rConsole.Write(_T("\n Last modify time is "));
185 rConsole.Write(Key.GetLastWriteTime());
186 }
187
188 rConsole.Write(_T("\n\n"));
189 unsigned __int64 nTotalItems = 0;
190
191 try
192 {
193 ASSERT(nTotalItems == 0);
194 rConsole.Write(_T("\t(KEY)\t\t\t\t..\\\n")); // parent key abstraction
195 nTotalItems = 1;
196
197 DWORD dwMaxSubkeyNameLength;
198 nError = Key.GetSubkeyNameMaxLength(dwMaxSubkeyNameLength);
199 if (nError != ERROR_SUCCESS)
200 throw nError;
201
202 TCHAR *pszSubkeyNameBuffer = new (std::nothrow) TCHAR[dwMaxSubkeyNameLength];
203 if (!pszSubkeyNameBuffer)
204 throw ERROR_OUTOFMEMORY;
205
206 Key.InitSubkeyEnumeration(pszSubkeyNameBuffer,dwMaxSubkeyNameLength);
207 while ((nError = Key.GetNextSubkeyName()) == ERROR_SUCCESS)
208 {
209 if (PatternMatch(pszPattern,pszSubkeyNameBuffer))
210 {
211 rConsole.Write(_T("\t(KEY)\t\t\t\t"));
212 rConsole.Write(pszSubkeyNameBuffer);
213 rConsole.Write(_T("\\\n"));
214 nTotalItems++;
215 }
216 }
217
218 delete[] pszSubkeyNameBuffer;
219
220 if (nError != ERROR_NO_MORE_ITEMS)
221 throw nError;
222
223 DWORD dwMaxValueNameBufferSize;
224 nError = Key.GetMaxValueNameLength(dwMaxValueNameBufferSize);
225 if (nError != ERROR_SUCCESS)
226 throw nError;
227
228 TCHAR *pchValueNameBuffer = new (std::nothrow) TCHAR[dwMaxValueNameBufferSize];
229 if (!pchValueNameBuffer)
230 throw ERROR_OUTOFMEMORY;
231
232
233 DWORD Type;
234 Key.InitValueEnumeration(pchValueNameBuffer,
235 dwMaxValueNameBufferSize,
236 NULL,
237 0,
238 &Type);
239
240 DWORD dwValueNameActualLength;
241 const TCHAR *pszValueTypeName;
242 unsigned int nTabSize = rConsole.GetTabWidth();
243 unsigned int nTabs;
244 while((nError = Key.GetNextValue(&dwValueNameActualLength)) == ERROR_SUCCESS)
245 {
246 if (PatternMatch(pszPattern,pchValueNameBuffer))
247 {
248 rConsole.Write(_T("\t"));
249 pszValueTypeName = CRegistryKey::GetValueTypeName(Type);
250 nTabs = _tcslen(pszValueTypeName)/nTabSize;
251 nTabs = (nTabs < 4)?(4-nTabs):1;
252 rConsole.Write(pszValueTypeName);
253 while(nTabs--)
254 rConsole.Write(_T("\t"));
255 rConsole.Write((dwValueNameActualLength == 0)?_T("(Default)"):pchValueNameBuffer);
256 rConsole.Write(_T("\n"));
257 nTotalItems++;
258 }
259 }
260
261 delete[] pchValueNameBuffer;
262
263 if (nError != ERROR_NO_MORE_ITEMS)
264 throw nError;
265
266 } // try
267 catch (LONG nError)
268 {
269 rConsole.Write(_T("Error "));
270 TCHAR Buffer[256];
271 rConsole.Write(_itoa(nError,Buffer,10));
272 rConsole.Write(_T("\n"));
273 }
274
275 rConsole.Write(_T("\n Total: "));
276 TCHAR Buffer[256];
277 rConsole.Write(_ui64tot(nTotalItems,Buffer,10));
278 rConsole.Write(_T(" item(s) listed.\n"));
279
280 return 0;
281}
BOOL PatternMatch(const TCHAR *pszPattern, const TCHAR *pszTry)
Definition: Pattern.cpp:28
#define PATTERN_MATCH_ALL
Definition: Pattern.h:7
#define _ui64tot
#define DIR_CMD_LENGTH
#define DIR_CMD
Type
Definition: Type.h:7
#define __int64
Definition: basetyps.h:16
Definition: bufpool.h:45
void ResetArgumentIteration()
TCHAR * GetNextArgument()
unsigned int GetTabWidth()
Definition: Console.cpp:217
BOOL Write(const TCHAR *p, DWORD dwChars=0)
Definition: Console.cpp:90
static const TCHAR * GetValueTypeName(DWORD dwType)
BOOL GetKey(const TCHAR *pchRelativePath, REGSAM DesiredAccess, CRegistryKey &rKey)
const TCHAR * GetLastErrorDescription()
virtual const TCHAR * GetHelpString()
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP char *__cdecl _itoa(_In_ int _Value, _Pre_notnull_ _Post_z_ char *_Dest, _In_ int _Radix)
#define pch(ap)
Definition: match.c:418
#define ASSERT(a)
Definition: mode.c:44
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
long LONG
Definition: pedump.c:60
#define _T(x)
Definition: vfdio.h:22
char TCHAR
Definition: xmlstorage.h:189
#define _tcsnicmp
Definition: xmlstorage.h:207
#define _tcslen
Definition: xmlstorage.h:198
#define _tcsicmp
Definition: xmlstorage.h:205

◆ GetHelpShortDescriptionString()

const TCHAR * CShellCommandDir::GetHelpShortDescriptionString ( )
virtual

Implements CShellCommand.

Definition at line 293 of file ShellCommandDir.cpp.

294{
295 return DIR_CMD_SHORT_DESC;
296}
#define DIR_CMD_SHORT_DESC

◆ GetHelpString()

const TCHAR * CShellCommandDir::GetHelpString ( )
virtual

Implements CShellCommand.

Definition at line 283 of file ShellCommandDir.cpp.

284{
285 return DIR_CMD_SHORT_DESC
286 _T("Syntax: ") DIR_CMD _T(" [<PATH>\\][<PATTERN>] [/?]\n\n")
287 _T(" <PATH> - Optional relative path to the key on which command will be executed\n")
288 _T(" <PATTERN> - Optional pattern. Default is the all matching pattern.")
289 _T(" /? - This help.\n\n")
290 _T("Without parameters, command lists keys and values of current key.\n");
291}
int help
Definition: sort.c:20
GLdouble n
Definition: glext.h:7729
GLubyte * pattern
Definition: glext.h:7787
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666
GLsizei GLenum const GLvoid * lists
Definition: glfuncs.h:14
struct task_struct * current
Definition: linux.c:32
Definition: path.h:35
Definition: copy.c:22
static GLenum which
Definition: wgl_font.c:159

Referenced by Execute().

◆ Match()

BOOL CShellCommandDir::Match ( const TCHAR pchCommand)
virtual

Implements CShellCommand.

Definition at line 59 of file ShellCommandDir.cpp.

60{
61 if (_tcsicmp(pchCommand,DIR_CMD) == 0)
62 return TRUE;
63 if (_tcsnicmp(pchCommand,DIR_CMD _T(".."),DIR_CMD_LENGTH+2*sizeof(TCHAR)) == 0)
64 return TRUE;
65 if (_tcsnicmp(pchCommand,DIR_CMD _T("/"),DIR_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
66 return TRUE;
67 if (_tcsnicmp(pchCommand,DIR_CMD _T("\\"),DIR_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
68 return TRUE;
69 return FALSE;
70}

Member Data Documentation

◆ m_rTree

CRegistryTree& CShellCommandDir::m_rTree
private

Definition at line 22 of file ShellCommandDir.h.

Referenced by Execute().


The documentation for this class was generated from the following files: