- Correctly detect volume changes when querying in multiple directories

- "dir directory" displays the contents of a directory

svn path=/trunk/; revision=28075
This commit is contained in:
Thomas Bluemel 2007-08-01 17:48:08 +00:00
parent 1f6dec06f4
commit e098f7d858

View file

@ -869,7 +869,6 @@ PrintSummary(LPTSTR szPath,
TCHAR szMsg[RC_STRING_MAX_SIZE]; TCHAR szMsg[RC_STRING_MAX_SIZE];
TCHAR szBuffer[64]; TCHAR szBuffer[64];
ULARGE_INTEGER uliFree; ULARGE_INTEGER uliFree;
TCHAR szRoot[] = _T("A:\\");
/* Here we check if we didn't find anything */ /* Here we check if we didn't find anything */
@ -914,15 +913,18 @@ PrintSummary(LPTSTR szPath,
} }
} }
/* Print total directories and freespace */
szRoot[0] = szPath[0]; if (ulDirs != 2)
GetUserDiskFreeSpace(szRoot, &uliFree); {
ConvertULargeInteger(uliFree, szBuffer, sizeof(szBuffer), lpFlags->bTSeperator); /* Print total directories and freespace */
LoadString(CMD_ModuleHandle, STRING_DIR_HELP6, (LPTSTR) szMsg, RC_STRING_MAX_SIZE); GetUserDiskFreeSpace(szPath, &uliFree);
if(lpFlags->bPause) ConvertULargeInteger(uliFree, szBuffer, sizeof(szBuffer), lpFlags->bTSeperator);
ConOutPrintfPaging(FALSE,szMsg,ulDirs, szBuffer); LoadString(CMD_ModuleHandle, STRING_DIR_HELP6, (LPTSTR) szMsg, RC_STRING_MAX_SIZE);
else if(lpFlags->bPause)
ConOutPrintf(szMsg,ulDirs, szBuffer); ConOutPrintfPaging(FALSE,szMsg,ulDirs, szBuffer);
else
ConOutPrintf(szMsg,ulDirs, szBuffer);
}
return 0; return 0;
} }
@ -1565,6 +1567,15 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
pszFilePart = NULL; pszFilePart = NULL;
} }
/* If no wildcard or file was specified and this is a directory, then
display all files in it */
wfdFileInfo.dwFileAttributes = GetFileAttributes(szFullPath);
if (wfdFileInfo.dwFileAttributes != INVALID_FILE_ATTRIBUTES &&
(wfdFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
_tcscat(szFullPath, _T("\\*"));
}
/* Prepare the linked list, first node is allocated */ /* Prepare the linked list, first node is allocated */
ptrStartNode = cmd_alloc(sizeof(DIRFINDLISTNODE)); ptrStartNode = cmd_alloc(sizeof(DIRFINDLISTNODE));
if (ptrStartNode == NULL) if (ptrStartNode == NULL)
@ -1767,19 +1778,14 @@ INT
CommandDir(LPTSTR first, LPTSTR rest) CommandDir(LPTSTR first, LPTSTR rest)
{ {
TCHAR dircmd[256]; /* A variable to store the DIRCMD enviroment variable */ TCHAR dircmd[256]; /* A variable to store the DIRCMD enviroment variable */
TCHAR cDrive; TCHAR volume[MAX_PATH];
TCHAR szPath[MAX_PATH]; TCHAR prev_volume[MAX_PATH];
LPTSTR* params = NULL; LPTSTR* params = NULL;
INT entries = 0; INT entries = 0;
UINT loop = 0; UINT loop = 0;
DIRSWITCHFLAGS stFlags; DIRSWITCHFLAGS stFlags;
INT ret = 1; INT ret = 1;
BOOL ChangedVolume;
/* Initialize variables */
cDrive = 0;
recurse_dir_cnt = 0L;
recurse_file_cnt = 0L;
recurse_bytes.QuadPart = 0;
/* Initialize Switch Flags < Default switches are setted here!> */ /* Initialize Switch Flags < Default switches are setted here!> */
stFlags.b4Digit = TRUE; stFlags.b4Digit = TRUE;
@ -1825,7 +1831,8 @@ CommandDir(LPTSTR first, LPTSTR rest)
goto cleanup; goto cleanup;
} }
} }
szPath[0] = _T('\0');
prev_volume[0] = _T('\0');
for(loop = 0; loop < entries; loop++) for(loop = 0; loop < entries; loop++)
{ {
@ -1835,7 +1842,9 @@ CommandDir(LPTSTR first, LPTSTR rest)
goto cleanup; goto cleanup;
} }
_tcscpy(szPath, params[loop]); recurse_dir_cnt = 0L;
recurse_file_cnt = 0L;
recurse_bytes.QuadPart = 0;
/* <Debug :> /* <Debug :>
Uncomment this to show the final state of switch flags*/ Uncomment this to show the final state of switch flags*/
@ -1861,17 +1870,25 @@ CommandDir(LPTSTR first, LPTSTR rest)
} }
#endif #endif
/* Print the drive header if the drive changed */ /* Print the drive header if the volume changed */
if(cDrive != params[loop][0] && !stFlags.bBareFormat) { ChangedVolume = TRUE;
if (!stFlags.bBareFormat &&
GetVolumePathName(params[loop], volume, sizeof(volume) / sizeof(TCHAR)))
{
if (!_tcscmp(volume, prev_volume))
ChangedVolume = FALSE;
else
_tcscpy(prev_volume, volume);
}
if (ChangedVolume && !stFlags.bBareFormat) {
if (!PrintDirectoryHeader (params[loop], &stFlags)) { if (!PrintDirectoryHeader (params[loop], &stFlags)) {
nErrorLevel = 1; nErrorLevel = 1;
goto cleanup; goto cleanup;
} }
cDrive = params[loop][0];
} }
/* do the actual dir */ /* do the actual dir */
if (DirList (params[loop], &stFlags)) if (DirList (params[loop], &stFlags))
{ {
@ -1879,15 +1896,14 @@ CommandDir(LPTSTR first, LPTSTR rest)
goto cleanup; goto cleanup;
} }
/* print the footer */
PrintSummary(params[loop],
recurse_file_cnt,
recurse_dir_cnt,
recurse_bytes,
&stFlags);
} }
/* print the footer */
PrintSummary(szPath, // FIXME: root of initial dir?
recurse_file_cnt,
recurse_dir_cnt,
recurse_bytes,
&stFlags);
ret = 0; ret = 0;
cleanup: cleanup: