1999-06-06 17:24:04 +02:00
|
|
|
/*
|
2006-09-04 06:13:08 +02:00
|
|
|
* CMD - Wine-compatible command line interface - Directory functions.
|
1999-06-06 17:24:04 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright (C) 1999 D A Pickles
|
1999-06-06 17:24:04 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTES:
|
1999-06-06 17:24:04 +02:00
|
|
|
* On entry, global variables quals, param1, param2 contain
|
|
|
|
* the qualifiers (uppercased and concatenated) and parameters entered, with
|
|
|
|
* environment-variable and batch parameter substitution already done.
|
|
|
|
*/
|
|
|
|
|
2006-01-16 20:41:34 +01:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
1999-06-06 17:24:04 +02:00
|
|
|
#include "wcmd.h"
|
2007-03-18 22:55:49 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(cmd);
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
int WCMD_dir_sort (const void *a, const void *b);
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR * WCMD_filesize64 (ULONGLONG free);
|
|
|
|
WCHAR * WCMD_strrev (WCHAR *buff);
|
|
|
|
static void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen);
|
|
|
|
static void WCMD_dir_trailer(WCHAR drive);
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
extern int echo_mode;
|
2007-06-03 23:07:42 +02:00
|
|
|
extern WCHAR quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
|
2000-08-02 00:02:18 +02:00
|
|
|
extern DWORD errorlevel;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-03-13 01:12:44 +01:00
|
|
|
typedef enum _DISPLAYTIME
|
|
|
|
{
|
|
|
|
Creation = 0,
|
|
|
|
Access,
|
|
|
|
Written
|
|
|
|
} DISPLAYTIME;
|
|
|
|
|
2007-03-13 21:27:46 +01:00
|
|
|
typedef enum _DISPLAYORDER
|
|
|
|
{
|
|
|
|
Name = 0,
|
|
|
|
Extension,
|
|
|
|
Size,
|
|
|
|
Date
|
|
|
|
} DISPLAYORDER;
|
|
|
|
|
2007-04-05 23:47:57 +02:00
|
|
|
static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *parms, int level);
|
2007-03-13 02:08:19 +01:00
|
|
|
static int file_total, dir_total, recurse, wide, bare, max_width, lower;
|
2007-03-13 21:27:45 +01:00
|
|
|
static int shortname, usernames;
|
2003-02-25 04:58:42 +01:00
|
|
|
static ULONGLONG byte_total;
|
2007-03-13 01:12:44 +01:00
|
|
|
static DISPLAYTIME dirTime;
|
2007-03-13 21:27:46 +01:00
|
|
|
static DISPLAYORDER dirOrder;
|
2007-03-18 22:55:49 +01:00
|
|
|
static BOOL orderReverse, orderGroupDirs, orderGroupDirsReverse, orderByCol;
|
2007-03-28 10:01:52 +02:00
|
|
|
static BOOL separator;
|
2007-03-18 22:55:52 +01:00
|
|
|
static ULONG showattrs, attrsbits;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR dotW[] = {'.','\0'};
|
|
|
|
static const WCHAR dotdotW[] = {'.','.','\0'};
|
|
|
|
static const WCHAR starW[] = {'*','\0'};
|
|
|
|
static const WCHAR slashW[] = {'\\','\0'};
|
|
|
|
static const WCHAR emptyW[] = {'\0'};
|
2007-06-03 23:07:47 +02:00
|
|
|
static const WCHAR spaceW[] = {' ','\0'};
|
2007-06-03 23:07:42 +02:00
|
|
|
|
1999-06-06 17:24:04 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* WCMD_directory
|
|
|
|
*
|
|
|
|
* List a file directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_directory (WCHAR *cmd) {
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR path[MAX_PATH], cwd[MAX_PATH];
|
2007-03-01 12:43:19 +01:00
|
|
|
int status, paged_mode;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR *p;
|
|
|
|
WCHAR string[MAXSTRING];
|
2007-04-05 23:47:56 +02:00
|
|
|
int argno = 0;
|
|
|
|
int argsProcessed = 0;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR *argN = cmd;
|
|
|
|
WCHAR lastDrive;
|
2007-04-05 23:47:56 +02:00
|
|
|
BOOL trailerReqd = FALSE;
|
|
|
|
DIRECTORY_STACK *fullParms = NULL;
|
|
|
|
DIRECTORY_STACK *prevEntry = NULL;
|
|
|
|
DIRECTORY_STACK *thisEntry = NULL;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR drive[10];
|
|
|
|
WCHAR dir[MAX_PATH];
|
|
|
|
WCHAR fname[MAX_PATH];
|
|
|
|
WCHAR ext[MAX_PATH];
|
|
|
|
static const WCHAR dircmdW[] = {'D','I','R','C','M','D','\0'};
|
2007-03-18 22:55:51 +01:00
|
|
|
|
2007-03-18 22:55:53 +01:00
|
|
|
errorlevel = 0;
|
|
|
|
|
2007-03-18 22:55:51 +01:00
|
|
|
/* Prefill Quals with (uppercased) DIRCMD env var */
|
2007-06-03 23:07:42 +02:00
|
|
|
if (GetEnvironmentVariable (dircmdW, string, sizeof(string)/sizeof(WCHAR))) {
|
2007-03-18 22:55:51 +01:00
|
|
|
p = string;
|
|
|
|
while ( (*p = toupper(*p)) ) ++p;
|
2007-06-03 23:07:42 +02:00
|
|
|
strcatW(string,quals);
|
|
|
|
strcpyW(quals, string);
|
2007-03-18 22:55:51 +01:00
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2001-06-21 00:52:12 +02:00
|
|
|
byte_total = 0;
|
|
|
|
file_total = dir_total = 0;
|
2007-03-18 22:55:51 +01:00
|
|
|
|
|
|
|
/* Initialize all flags to their defaults as if no DIRCMD or quals */
|
|
|
|
paged_mode = FALSE;
|
|
|
|
recurse = FALSE;
|
|
|
|
wide = FALSE;
|
|
|
|
bare = FALSE;
|
|
|
|
lower = FALSE;
|
|
|
|
shortname = FALSE;
|
|
|
|
usernames = FALSE;
|
|
|
|
orderByCol = FALSE;
|
2007-03-28 10:01:52 +02:00
|
|
|
separator = TRUE;
|
2007-03-13 01:12:44 +01:00
|
|
|
dirTime = Written;
|
2007-03-13 21:27:46 +01:00
|
|
|
dirOrder = Name;
|
|
|
|
orderReverse = FALSE;
|
|
|
|
orderGroupDirs = FALSE;
|
|
|
|
orderGroupDirsReverse = FALSE;
|
2007-03-18 22:55:52 +01:00
|
|
|
showattrs = 0;
|
|
|
|
attrsbits = 0;
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-03-18 22:55:51 +01:00
|
|
|
/* Handle args - Loop through so right most is the effective one */
|
|
|
|
/* Note: /- appears to be a negate rather than an off, eg. dir
|
|
|
|
/-W is wide, or dir /w /-w /-w is also wide */
|
|
|
|
p = quals;
|
|
|
|
while (*p && (*p=='/' || *p==' ')) {
|
|
|
|
BOOL negate = FALSE;
|
|
|
|
if (*p++==' ') continue; /* Skip / and blanks introduced through DIRCMD */
|
2007-03-13 01:12:44 +01:00
|
|
|
|
2007-03-18 22:55:51 +01:00
|
|
|
if (*p=='-') {
|
|
|
|
negate = TRUE;
|
2007-03-13 21:27:46 +01:00
|
|
|
p++;
|
|
|
|
}
|
2007-03-18 22:55:51 +01:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Processing arg '%c' (in %s)\n", *p, wine_dbgstr_w(quals));
|
2007-03-18 22:55:51 +01:00
|
|
|
switch (*p) {
|
|
|
|
case 'P': if (negate) paged_mode = !paged_mode;
|
|
|
|
else paged_mode = TRUE;
|
|
|
|
break;
|
|
|
|
case 'S': if (negate) recurse = !recurse;
|
|
|
|
else recurse = TRUE;
|
|
|
|
break;
|
|
|
|
case 'W': if (negate) wide = !wide;
|
|
|
|
else wide = TRUE;
|
|
|
|
break;
|
|
|
|
case 'B': if (negate) bare = !bare;
|
|
|
|
else bare = TRUE;
|
|
|
|
break;
|
|
|
|
case 'L': if (negate) lower = !lower;
|
|
|
|
else lower = TRUE;
|
|
|
|
break;
|
|
|
|
case 'X': if (negate) shortname = !shortname;
|
|
|
|
else shortname = TRUE;
|
|
|
|
break;
|
|
|
|
case 'Q': if (negate) usernames = !usernames;
|
|
|
|
else usernames = TRUE;
|
|
|
|
break;
|
|
|
|
case 'D': if (negate) orderByCol = !orderByCol;
|
|
|
|
else orderByCol = TRUE;
|
|
|
|
break;
|
2007-03-28 10:01:52 +02:00
|
|
|
case 'C': if (negate) separator = !separator;
|
|
|
|
else separator = TRUE;
|
2007-03-18 22:55:51 +01:00
|
|
|
break;
|
|
|
|
case 'T': p = p + 1;
|
|
|
|
if (*p==':') p++; /* Skip optional : */
|
|
|
|
|
|
|
|
if (*p == 'A') dirTime = Access;
|
|
|
|
else if (*p == 'C') dirTime = Creation;
|
|
|
|
else if (*p == 'W') dirTime = Written;
|
|
|
|
|
|
|
|
/* Support /T and /T: with no parms, default to written */
|
|
|
|
else if (*p == 0x00 || *p == '/') {
|
|
|
|
dirTime = Written;
|
|
|
|
p = p - 1; /* So when step on, move to '/' */
|
|
|
|
} else {
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
WCMD_print_error();
|
2007-03-18 22:55:53 +01:00
|
|
|
errorlevel = 1;
|
2007-03-18 22:55:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'O': p = p + 1;
|
|
|
|
if (*p==':') p++; /* Skip optional : */
|
|
|
|
while (*p && *p != '/') {
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Processing subparm '%c' (in %s)\n", *p, wine_dbgstr_w(quals));
|
2007-03-18 22:55:51 +01:00
|
|
|
switch (*p) {
|
|
|
|
case 'N': dirOrder = Name; break;
|
|
|
|
case 'E': dirOrder = Extension; break;
|
|
|
|
case 'S': dirOrder = Size; break;
|
|
|
|
case 'D': dirOrder = Date; break;
|
|
|
|
case '-': if (*(p+1)=='G') orderGroupDirsReverse=TRUE;
|
|
|
|
else orderReverse = TRUE;
|
|
|
|
break;
|
|
|
|
case 'G': orderGroupDirs = TRUE; break;
|
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
WCMD_print_error();
|
2007-03-18 22:55:53 +01:00
|
|
|
errorlevel = 1;
|
2007-03-18 22:55:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
p = p - 1; /* So when step on, move to '/' */
|
|
|
|
break;
|
2007-03-18 22:55:52 +01:00
|
|
|
case 'A': p = p + 1;
|
|
|
|
showattrs = 0;
|
|
|
|
attrsbits = 0;
|
|
|
|
if (*p==':') p++; /* Skip optional : */
|
|
|
|
while (*p && *p != '/') {
|
|
|
|
BOOL anegate = FALSE;
|
|
|
|
ULONG mask;
|
|
|
|
|
|
|
|
/* Note /A: - options are 'offs' not toggles */
|
|
|
|
if (*p=='-') {
|
|
|
|
anegate = TRUE;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Processing subparm '%c' (in %s)\n", *p, wine_dbgstr_w(quals));
|
2007-03-18 22:55:52 +01:00
|
|
|
switch (*p) {
|
|
|
|
case 'D': mask = FILE_ATTRIBUTE_DIRECTORY; break;
|
|
|
|
case 'H': mask = FILE_ATTRIBUTE_HIDDEN; break;
|
|
|
|
case 'S': mask = FILE_ATTRIBUTE_SYSTEM; break;
|
|
|
|
case 'R': mask = FILE_ATTRIBUTE_READONLY; break;
|
|
|
|
case 'A': mask = FILE_ATTRIBUTE_ARCHIVE; break;
|
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
WCMD_print_error();
|
2007-03-18 22:55:53 +01:00
|
|
|
errorlevel = 1;
|
2007-03-18 22:55:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep running list of bits we care about */
|
|
|
|
attrsbits |= mask;
|
|
|
|
|
|
|
|
/* Mask shows what MUST be in the bits we care about */
|
|
|
|
if (anegate) showattrs = showattrs & ~mask;
|
|
|
|
else showattrs |= mask;
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
p = p - 1; /* So when step on, move to '/' */
|
|
|
|
WINE_TRACE("Result: showattrs %x, bits %x\n", showattrs, attrsbits);
|
|
|
|
break;
|
2007-03-18 22:55:51 +01:00
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
WCMD_print_error();
|
2007-03-18 22:55:53 +01:00
|
|
|
errorlevel = 1;
|
2007-03-18 22:55:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
p = p + 1;
|
2007-03-13 21:27:46 +01:00
|
|
|
}
|
|
|
|
|
2002-04-30 01:33:09 +02:00
|
|
|
/* Handle conflicting args and initialization */
|
2007-03-13 02:09:05 +01:00
|
|
|
if (bare || shortname) wide = FALSE;
|
|
|
|
if (bare) shortname = FALSE;
|
2007-03-13 21:27:45 +01:00
|
|
|
if (wide) usernames = FALSE;
|
2007-03-18 22:55:49 +01:00
|
|
|
if (orderByCol) wide = TRUE;
|
2002-04-30 01:33:09 +02:00
|
|
|
|
|
|
|
if (wide) {
|
2003-02-27 02:41:21 +01:00
|
|
|
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleInfo))
|
|
|
|
max_width = consoleInfo.dwSize.X;
|
|
|
|
else
|
|
|
|
max_width = 80;
|
2002-04-30 01:33:09 +02:00
|
|
|
}
|
2003-02-25 04:58:42 +01:00
|
|
|
if (paged_mode) {
|
2007-04-13 22:34:05 +02:00
|
|
|
WCMD_enter_paged_mode(NULL);
|
2003-02-25 04:58:42 +01:00
|
|
|
}
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:56 +02:00
|
|
|
argno = 0;
|
|
|
|
argsProcessed = 0;
|
|
|
|
argN = cmd;
|
2007-06-03 23:07:42 +02:00
|
|
|
GetCurrentDirectory (MAX_PATH, cwd);
|
|
|
|
strcatW(cwd, slashW);
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
/* Loop through all args, calculating full effective directory */
|
|
|
|
fullParms = NULL;
|
|
|
|
prevEntry = NULL;
|
|
|
|
while (argN) {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR fullname[MAXSTRING];
|
|
|
|
WCHAR *thisArg = WCMD_parameter (cmd, argno++, &argN);
|
2007-04-05 23:47:56 +02:00
|
|
|
if (argN && argN[0] != '/') {
|
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Found parm '%s'\n", wine_dbgstr_w(thisArg));
|
2007-04-05 23:47:56 +02:00
|
|
|
if (thisArg[1] == ':' && thisArg[2] == '\\') {
|
2007-06-03 23:07:42 +02:00
|
|
|
strcpyW(fullname, thisArg);
|
2007-04-05 23:47:56 +02:00
|
|
|
} else if (thisArg[1] == ':' && thisArg[2] != '\\') {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR envvar[4];
|
|
|
|
static const WCHAR envFmt[] = {'=','%','c',':','\0'};
|
|
|
|
wsprintf(envvar, envFmt, thisArg[0]);
|
2007-04-05 23:47:56 +02:00
|
|
|
if (!GetEnvironmentVariable(envvar, fullname, MAX_PATH)) {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR noEnvFmt[] = {'%','c',':','\0'};
|
|
|
|
wsprintf(fullname, noEnvFmt, thisArg[0]);
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
2007-06-03 23:07:42 +02:00
|
|
|
strcatW(fullname, slashW);
|
|
|
|
strcatW(fullname, &thisArg[2]);
|
2007-04-05 23:47:56 +02:00
|
|
|
} else if (thisArg[0] == '\\') {
|
2007-06-03 23:07:42 +02:00
|
|
|
memcpy(fullname, cwd, 2 * sizeof(WCHAR));
|
|
|
|
strcpyW(fullname+2, thisArg);
|
2007-04-05 23:47:56 +02:00
|
|
|
} else {
|
2007-06-03 23:07:42 +02:00
|
|
|
strcpyW(fullname, cwd);
|
|
|
|
strcatW(fullname, thisArg);
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Using location '%s'\n", wine_dbgstr_w(fullname));
|
2007-04-05 23:47:56 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
status = GetFullPathName (fullname, sizeof(path)/sizeof(WCHAR), path, NULL);
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the path supplied does not include a wildcard, and the endpoint of the
|
|
|
|
* path references a directory, we need to list the *contents* of that
|
|
|
|
* directory not the directory file itself.
|
|
|
|
*/
|
2007-06-03 23:07:42 +02:00
|
|
|
if ((strchrW(path, '*') == NULL) && (strchrW(path, '%') == NULL)) {
|
2007-04-05 23:47:56 +02:00
|
|
|
status = GetFileAttributes (path);
|
|
|
|
if ((status != INVALID_FILE_ATTRIBUTES) && (status & FILE_ATTRIBUTE_DIRECTORY)) {
|
2007-06-03 23:07:42 +02:00
|
|
|
if (path[strlenW(path)-1] == '\\') {
|
|
|
|
strcatW (path, starW);
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
|
|
|
else {
|
2007-06-03 23:07:42 +02:00
|
|
|
const WCHAR slashStarW[] = {'\\','*','\0'};
|
|
|
|
strcatW (path, slashStarW);
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
|
|
|
}
|
2007-04-05 23:47:58 +02:00
|
|
|
} else {
|
|
|
|
/* Special case wildcard search with no extension (ie parameters ending in '.') as
|
|
|
|
GetFullPathName strips off the additional '.' */
|
2007-06-03 23:07:42 +02:00
|
|
|
if (fullname[strlenW(fullname)-1] == '.') strcatW(path, dotW);
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Using path '%s'\n", wine_dbgstr_w(path));
|
2007-04-05 23:47:56 +02:00
|
|
|
thisEntry = (DIRECTORY_STACK *) HeapAlloc(GetProcessHeap(),0,sizeof(DIRECTORY_STACK));
|
|
|
|
if (fullParms == NULL) fullParms = thisEntry;
|
|
|
|
if (prevEntry != NULL) prevEntry->next = thisEntry;
|
|
|
|
prevEntry = thisEntry;
|
|
|
|
thisEntry->next = NULL;
|
|
|
|
|
|
|
|
/* Split into components */
|
|
|
|
WCMD_splitpath(path, drive, dir, fname, ext);
|
|
|
|
WINE_TRACE("Path Parts: drive: '%s' dir: '%s' name: '%s' ext:'%s'\n",
|
2007-06-03 23:07:42 +02:00
|
|
|
wine_dbgstr_w(drive), wine_dbgstr_w(dir),
|
|
|
|
wine_dbgstr_w(fname), wine_dbgstr_w(ext));
|
2007-04-05 23:47:56 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
thisEntry->dirName = HeapAlloc(GetProcessHeap(),0,
|
|
|
|
sizeof(WCHAR) * (strlenW(drive)+strlenW(dir)+1));
|
|
|
|
strcpyW(thisEntry->dirName, drive);
|
|
|
|
strcatW(thisEntry->dirName, dir);
|
2007-04-05 23:47:56 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
thisEntry->fileName = HeapAlloc(GetProcessHeap(),0,
|
|
|
|
sizeof(WCHAR) * (strlenW(fname)+strlenW(ext)+1));
|
|
|
|
strcpyW(thisEntry->fileName, fname);
|
|
|
|
strcatW(thisEntry->fileName, ext);
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
}
|
2000-08-02 00:02:18 +02:00
|
|
|
}
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:56 +02:00
|
|
|
/* If just 'dir' entered, a '*' parameter is assumed */
|
|
|
|
if (fullParms == NULL) {
|
|
|
|
WINE_TRACE("Inserting default '*'\n");
|
|
|
|
fullParms = (DIRECTORY_STACK *) HeapAlloc(GetProcessHeap(),0, sizeof(DIRECTORY_STACK));
|
|
|
|
fullParms->next = NULL;
|
2007-06-03 23:07:42 +02:00
|
|
|
fullParms->dirName = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * (strlenW(cwd)+1));
|
|
|
|
strcpyW(fullParms->dirName, cwd);
|
|
|
|
fullParms->fileName = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR) * 2);
|
|
|
|
strcpyW(fullParms->fileName, starW);
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:56 +02:00
|
|
|
lastDrive = '?';
|
|
|
|
prevEntry = NULL;
|
|
|
|
thisEntry = fullParms;
|
|
|
|
trailerReqd = FALSE;
|
|
|
|
|
|
|
|
while (thisEntry != NULL) {
|
|
|
|
|
|
|
|
/* Output disk free (trailer) and volume information (header) if the drive
|
|
|
|
letter changes */
|
|
|
|
if (lastDrive != toupper(thisEntry->dirName[0])) {
|
|
|
|
|
|
|
|
/* Trailer Information */
|
|
|
|
if (lastDrive != '?') {
|
|
|
|
trailerReqd = FALSE;
|
|
|
|
WCMD_dir_trailer(prevEntry->dirName[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
lastDrive = toupper(thisEntry->dirName[0]);
|
|
|
|
|
|
|
|
if (!bare) {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR drive[3];
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
WINE_TRACE("Writing volume for '%c:'\n", thisEntry->dirName[0]);
|
2007-06-03 23:07:42 +02:00
|
|
|
memcpy(drive, thisEntry->dirName, 2 * sizeof(WCHAR));
|
2007-04-05 23:47:56 +02:00
|
|
|
drive[2] = 0x00;
|
|
|
|
status = WCMD_volume (0, drive);
|
|
|
|
trailerReqd = TRUE;
|
|
|
|
if (!status) {
|
|
|
|
errorlevel = 1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR newLine2[] = {'\n','\n','\0'};
|
|
|
|
if (!bare) WCMD_output (newLine2);
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear any errors from previous invocations, and process it */
|
|
|
|
errorlevel = 0;
|
|
|
|
prevEntry = thisEntry;
|
2007-04-05 23:47:57 +02:00
|
|
|
thisEntry = WCMD_list_directory (thisEntry, 0);
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Trailer Information */
|
|
|
|
if (trailerReqd) {
|
|
|
|
WCMD_dir_trailer(prevEntry->dirName[0]);
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
exit:
|
2003-02-25 04:58:42 +01:00
|
|
|
if (paged_mode) WCMD_leave_paged_mode();
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
/* Free storage allocated for parms */
|
|
|
|
while (fullParms != NULL) {
|
|
|
|
prevEntry = fullParms;
|
|
|
|
fullParms = prevEntry->next;
|
|
|
|
HeapFree(GetProcessHeap(),0,prevEntry->dirName);
|
|
|
|
HeapFree(GetProcessHeap(),0,prevEntry->fileName);
|
|
|
|
HeapFree(GetProcessHeap(),0,prevEntry);
|
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WCMD_list_directory
|
|
|
|
*
|
|
|
|
* List a single file directory. This function (and those below it) can be called
|
|
|
|
* recursively when the /S switch is used.
|
|
|
|
*
|
|
|
|
* FIXME: Assumes 24-line display for the /P qualifier.
|
|
|
|
*/
|
|
|
|
|
2007-04-05 23:47:57 +02:00
|
|
|
static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int level) {
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR string[1024], datestring[32], timestring[32];
|
|
|
|
WCHAR real_path[MAX_PATH];
|
2007-03-01 12:43:19 +01:00
|
|
|
WIN32_FIND_DATA *fd;
|
|
|
|
FILETIME ft;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
HANDLE hff;
|
2007-04-05 23:47:56 +02:00
|
|
|
int dir_count, file_count, entry_count, i, widest, cur_width, tmp_width;
|
2007-03-18 22:55:49 +01:00
|
|
|
int numCols, numRows;
|
|
|
|
int rows, cols;
|
2007-03-01 12:43:19 +01:00
|
|
|
ULARGE_INTEGER byte_count, file_size;
|
2007-04-05 23:47:57 +02:00
|
|
|
DIRECTORY_STACK *parms;
|
|
|
|
int concurrentDirs = 0;
|
|
|
|
BOOL done_header = FALSE;
|
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmtDir[] = {'%','1','0','s',' ',' ','%','8','s',' ',' ',
|
|
|
|
'<','D','I','R','>',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
|
|
|
|
static const WCHAR fmtFile[] = {'%','1','0','s',' ',' ','%','8','s',' ',' ',
|
|
|
|
' ',' ','%','1','0','s',' ',' ','\0'};
|
|
|
|
static const WCHAR fmt2[] = {'%','-','1','3','s','\0'};
|
|
|
|
static const WCHAR fmt3[] = {'%','-','2','3','s','\0'};
|
|
|
|
static const WCHAR fmt4[] = {'%','s','\0'};
|
|
|
|
static const WCHAR fmt5[] = {'%','s','%','s','\0'};
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
dir_count = 0;
|
|
|
|
file_count = 0;
|
|
|
|
entry_count = 0;
|
2001-06-04 04:55:38 +02:00
|
|
|
byte_count.QuadPart = 0;
|
2002-04-30 01:33:09 +02:00
|
|
|
widest = 0;
|
|
|
|
cur_width = 0;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-04-05 23:47:57 +02:00
|
|
|
/* Loop merging all the files from consecutive parms which relate to the
|
|
|
|
same directory. Note issuing a directory header with no contents
|
|
|
|
mirrors what windows does */
|
|
|
|
parms = inputparms;
|
2007-03-13 21:27:45 +01:00
|
|
|
fd = HeapAlloc(GetProcessHeap(),0,sizeof(WIN32_FIND_DATA));
|
2007-06-03 23:07:42 +02:00
|
|
|
while (parms && strcmpW(inputparms->dirName, parms->dirName) == 0) {
|
2007-04-05 23:47:57 +02:00
|
|
|
concurrentDirs++;
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:57 +02:00
|
|
|
/* Work out the full path + filename */
|
2007-06-03 23:07:42 +02:00
|
|
|
strcpyW(real_path, parms->dirName);
|
|
|
|
strcatW(real_path, parms->fileName);
|
2007-03-18 22:55:52 +01:00
|
|
|
|
2007-04-05 23:47:57 +02:00
|
|
|
/* Load all files into an in memory structure */
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Looking for matches to '%s'\n", wine_dbgstr_w(real_path));
|
2007-04-05 23:47:57 +02:00
|
|
|
hff = FindFirstFile (real_path, (fd+entry_count));
|
|
|
|
if (hff != INVALID_HANDLE_VALUE) {
|
|
|
|
do {
|
|
|
|
/* Skip any which are filtered out by attribute */
|
|
|
|
if (((fd+entry_count)->dwFileAttributes & attrsbits) != showattrs) continue;
|
|
|
|
|
|
|
|
entry_count++;
|
|
|
|
|
|
|
|
/* Keep running track of longest filename for wide output */
|
|
|
|
if (wide || orderByCol) {
|
2007-06-03 23:07:42 +02:00
|
|
|
int tmpLen = strlenW((fd+(entry_count-1))->cFileName) + 3;
|
2007-04-05 23:47:57 +02:00
|
|
|
if ((fd+(entry_count-1))->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) tmpLen = tmpLen + 2;
|
|
|
|
if (tmpLen > widest) widest = tmpLen;
|
|
|
|
}
|
2007-04-05 23:47:56 +02:00
|
|
|
|
2007-04-05 23:47:57 +02:00
|
|
|
fd = HeapReAlloc(GetProcessHeap(),0,fd,(entry_count+1)*sizeof(WIN32_FIND_DATA));
|
|
|
|
if (fd == NULL) {
|
|
|
|
FindClose (hff);
|
2007-06-06 10:44:04 +02:00
|
|
|
WINE_ERR("Out of memory\n");
|
2007-04-05 23:47:57 +02:00
|
|
|
errorlevel = 1;
|
|
|
|
return parms->next;
|
|
|
|
}
|
|
|
|
} while (FindNextFile(hff, (fd+entry_count)) != 0);
|
|
|
|
FindClose (hff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Work out the actual current directory name without a trailing \ */
|
2007-06-03 23:07:42 +02:00
|
|
|
strcpyW(real_path, parms->dirName);
|
|
|
|
real_path[strlenW(parms->dirName)-1] = 0x00;
|
2007-04-05 23:47:57 +02:00
|
|
|
|
|
|
|
/* Output the results */
|
|
|
|
if (!bare) {
|
2007-06-03 23:07:39 +02:00
|
|
|
if (level != 0 && (entry_count > 0)) WCMD_output (newline);
|
2007-04-05 23:47:57 +02:00
|
|
|
if (!recurse || ((entry_count > 0) && done_header==FALSE)) {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR headerW[] = {'D','i','r','e','c','t','o','r','y',' ','o','f',
|
|
|
|
' ','%','s','\n','\n','\0'};
|
|
|
|
WCMD_output (headerW, real_path);
|
2007-04-05 23:47:57 +02:00
|
|
|
done_header = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to next parm */
|
|
|
|
parms = parms->next;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
/* Handle case where everything is filtered out */
|
|
|
|
if (entry_count > 0) {
|
2007-03-18 22:55:49 +01:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
/* Sort the list of files */
|
|
|
|
qsort (fd, entry_count, sizeof(WIN32_FIND_DATA), WCMD_dir_sort);
|
2007-03-13 02:08:19 +01:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
/* Work out the number of columns */
|
|
|
|
WINE_TRACE("%d entries, maxwidth=%d, widest=%d\n", entry_count, max_width, widest);
|
|
|
|
if (wide || orderByCol) {
|
|
|
|
numCols = max(1, (int)max_width / widest);
|
|
|
|
numRows = entry_count / numCols;
|
|
|
|
if (entry_count % numCols) numRows++;
|
2007-03-18 22:55:49 +01:00
|
|
|
} else {
|
2007-04-05 23:47:55 +02:00
|
|
|
numCols = 1;
|
|
|
|
numRows = entry_count;
|
2007-03-18 22:55:49 +01:00
|
|
|
}
|
2007-04-05 23:47:55 +02:00
|
|
|
WINE_TRACE("cols=%d, rows=%d\n", numCols, numRows);
|
2007-03-18 22:55:49 +01:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
for (rows=0; rows<numRows; rows++) {
|
|
|
|
BOOL addNewLine = TRUE;
|
|
|
|
for (cols=0; cols<numCols; cols++) {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR username[24];
|
2007-03-13 02:08:19 +01:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
/* Work out the index of the entry being pointed to */
|
|
|
|
if (orderByCol) {
|
|
|
|
i = (cols * numRows) + rows;
|
|
|
|
if (i >= entry_count) continue;
|
2002-04-30 01:33:09 +02:00
|
|
|
} else {
|
2007-04-05 23:47:55 +02:00
|
|
|
i = (rows * numCols) + cols;
|
|
|
|
if (i >= entry_count) continue;
|
2002-04-30 01:33:09 +02:00
|
|
|
}
|
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
/* /L convers all names to lower case */
|
|
|
|
if (lower) {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR *p = (fd+i)->cFileName;
|
2007-04-05 23:47:55 +02:00
|
|
|
while ( (*p = tolower(*p)) ) ++p;
|
2002-04-30 01:33:09 +02:00
|
|
|
}
|
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
/* /Q gets file ownership information */
|
|
|
|
if (usernames) {
|
2007-06-03 23:07:42 +02:00
|
|
|
strcpyW (string, inputparms->dirName);
|
|
|
|
strcatW (string, (fd+i)->cFileName);
|
|
|
|
WCMD_getfileowner(string, username, sizeof(username)/sizeof(WCHAR));
|
2007-04-05 23:47:55 +02:00
|
|
|
}
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
if (dirTime == Written) {
|
|
|
|
FileTimeToLocalFileTime (&(fd+i)->ftLastWriteTime, &ft);
|
|
|
|
} else if (dirTime == Access) {
|
|
|
|
FileTimeToLocalFileTime (&(fd+i)->ftLastAccessTime, &ft);
|
2002-04-30 01:33:09 +02:00
|
|
|
} else {
|
2007-04-05 23:47:55 +02:00
|
|
|
FileTimeToLocalFileTime (&(fd+i)->ftCreationTime, &ft);
|
2002-04-30 01:33:09 +02:00
|
|
|
}
|
2007-04-05 23:47:55 +02:00
|
|
|
FileTimeToSystemTime (&ft, &st);
|
|
|
|
GetDateFormat (0, DATE_SHORTDATE, &st, NULL, datestring,
|
2007-06-03 23:07:42 +02:00
|
|
|
sizeof(datestring)/sizeof(WCHAR));
|
2007-04-05 23:47:55 +02:00
|
|
|
GetTimeFormat (0, TIME_NOSECONDS, &st,
|
2007-06-03 23:07:42 +02:00
|
|
|
NULL, timestring, sizeof(timestring)/sizeof(WCHAR));
|
2007-04-05 23:47:55 +02:00
|
|
|
|
|
|
|
if (wide) {
|
|
|
|
|
|
|
|
tmp_width = cur_width;
|
|
|
|
if ((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmt[] = {'[','%','s',']','\0'};
|
|
|
|
WCMD_output (fmt, (fd+i)->cFileName);
|
2007-04-05 23:47:55 +02:00
|
|
|
dir_count++;
|
2007-06-03 23:07:42 +02:00
|
|
|
tmp_width = tmp_width + strlenW((fd+i)->cFileName) + 2;
|
2007-04-05 23:47:55 +02:00
|
|
|
} else {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmt[] = {'%','s','\0'};
|
|
|
|
WCMD_output (fmt, (fd+i)->cFileName);
|
|
|
|
tmp_width = tmp_width + strlenW((fd+i)->cFileName) ;
|
2007-04-05 23:47:55 +02:00
|
|
|
file_count++;
|
|
|
|
file_size.u.LowPart = (fd+i)->nFileSizeLow;
|
|
|
|
file_size.u.HighPart = (fd+i)->nFileSizeHigh;
|
|
|
|
byte_count.QuadPart += file_size.QuadPart;
|
|
|
|
}
|
|
|
|
cur_width = cur_width + widest;
|
|
|
|
|
|
|
|
if ((cur_width + widest) > max_width) {
|
|
|
|
cur_width = 0;
|
|
|
|
} else {
|
2007-06-03 23:07:47 +02:00
|
|
|
int padding = cur_width - tmp_width;
|
|
|
|
int toWrite = 0;
|
|
|
|
WCHAR temp[101];
|
|
|
|
|
|
|
|
/* Note: WCMD_output uses wvsprintf which does not allow %*
|
|
|
|
so manually pad with spaces to appropriate width */
|
|
|
|
strcpyW(temp, emptyW);
|
|
|
|
while (padding > 0) {
|
|
|
|
strcatW(&temp[toWrite], spaceW);
|
|
|
|
toWrite++;
|
|
|
|
if (toWrite > 99) {
|
|
|
|
WCMD_output(temp);
|
|
|
|
toWrite = 0;
|
|
|
|
strcpyW(temp, emptyW);
|
|
|
|
}
|
|
|
|
padding--;
|
|
|
|
}
|
|
|
|
WCMD_output(temp);
|
2007-04-05 23:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if ((fd+i)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
|
dir_count++;
|
|
|
|
|
|
|
|
if (!bare) {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCMD_output (fmtDir, datestring, timestring);
|
|
|
|
if (shortname) WCMD_output (fmt2, (fd+i)->cAlternateFileName);
|
|
|
|
if (usernames) WCMD_output (fmt3, username);
|
|
|
|
WCMD_output(fmt4,(fd+i)->cFileName);
|
2007-04-05 23:47:55 +02:00
|
|
|
} else {
|
2007-06-03 23:07:42 +02:00
|
|
|
if (!((strcmpW((fd+i)->cFileName, dotW) == 0) ||
|
|
|
|
(strcmpW((fd+i)->cFileName, dotdotW) == 0))) {
|
|
|
|
WCMD_output (fmt5, recurse?inputparms->dirName:emptyW, (fd+i)->cFileName);
|
2007-04-05 23:47:55 +02:00
|
|
|
} else {
|
|
|
|
addNewLine = FALSE;
|
|
|
|
}
|
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2007-04-05 23:47:55 +02:00
|
|
|
else {
|
|
|
|
file_count++;
|
|
|
|
file_size.u.LowPart = (fd+i)->nFileSizeLow;
|
|
|
|
file_size.u.HighPart = (fd+i)->nFileSizeHigh;
|
|
|
|
byte_count.QuadPart += file_size.QuadPart;
|
|
|
|
if (!bare) {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCMD_output (fmtFile, datestring, timestring,
|
2007-04-05 23:47:55 +02:00
|
|
|
WCMD_filesize64(file_size.QuadPart));
|
2007-06-03 23:07:42 +02:00
|
|
|
if (shortname) WCMD_output (fmt2, (fd+i)->cAlternateFileName);
|
|
|
|
if (usernames) WCMD_output (fmt3, username);
|
|
|
|
WCMD_output(fmt4,(fd+i)->cFileName);
|
2007-04-05 23:47:55 +02:00
|
|
|
} else {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCMD_output (fmt5, recurse?inputparms->dirName:emptyW, (fd+i)->cFileName);
|
2007-04-05 23:47:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-03 23:07:39 +02:00
|
|
|
if (addNewLine) WCMD_output (newline);
|
2007-04-05 23:47:55 +02:00
|
|
|
cur_width = 0;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
if (!bare) {
|
|
|
|
if (file_count == 1) {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmt[] = {' ',' ',' ',' ',' ',' ',' ','1',' ','f','i','l','e',' ',
|
|
|
|
'%','2','5','s',' ','b','y','t','e','s','\n','\0'};
|
|
|
|
WCMD_output (fmt, WCMD_filesize64 (byte_count.QuadPart));
|
2007-04-05 23:47:55 +02:00
|
|
|
}
|
|
|
|
else {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmt[] = {'%','8','d',' ','f','i','l','e','s',' ','%','2','4','s',
|
|
|
|
' ','b','y','t','e','s','\n','\0'};
|
|
|
|
WCMD_output (fmt, file_count, WCMD_filesize64 (byte_count.QuadPart));
|
2007-04-05 23:47:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
byte_total = byte_total + byte_count.QuadPart;
|
|
|
|
file_total = file_total + file_count;
|
|
|
|
dir_total = dir_total + dir_count;
|
2002-04-30 01:33:09 +02:00
|
|
|
|
2007-04-05 23:47:55 +02:00
|
|
|
if (!bare && !recurse) {
|
2007-06-03 23:07:42 +02:00
|
|
|
if (dir_count == 1) {
|
|
|
|
static const WCHAR fmt[] = {'%','8','d',' ','d','i','r','e','c','t','o','r','y',
|
|
|
|
' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
|
|
|
|
WCMD_output (fmt, 1);
|
|
|
|
} else {
|
|
|
|
static const WCHAR fmt[] = {'%','8','d',' ','d','i','r','e','c','t','o','r','i',
|
|
|
|
'e','s','\0'};
|
|
|
|
WCMD_output (fmt, dir_count);
|
|
|
|
}
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
}
|
2007-03-13 21:27:45 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,fd);
|
2007-04-05 23:47:55 +02:00
|
|
|
|
|
|
|
/* When recursing, look in all subdirectories for matches */
|
|
|
|
if (recurse) {
|
2007-04-05 23:47:56 +02:00
|
|
|
DIRECTORY_STACK *dirStack = NULL;
|
|
|
|
DIRECTORY_STACK *lastEntry = NULL;
|
2007-04-05 23:47:55 +02:00
|
|
|
WIN32_FIND_DATA finddata;
|
|
|
|
|
|
|
|
/* Build path to search */
|
2007-06-03 23:07:42 +02:00
|
|
|
strcpyW(string, inputparms->dirName);
|
|
|
|
strcatW(string, starW);
|
2007-04-05 23:47:55 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Recursive, looking for '%s'\n", wine_dbgstr_w(string));
|
2007-04-05 23:47:55 +02:00
|
|
|
hff = FindFirstFile (string, &finddata);
|
|
|
|
if (hff != INVALID_HANDLE_VALUE) {
|
|
|
|
do {
|
|
|
|
if ((finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
|
2007-06-03 23:07:42 +02:00
|
|
|
(strcmpW(finddata.cFileName, dotdotW) != 0) &&
|
|
|
|
(strcmpW(finddata.cFileName, dotW) != 0)) {
|
2007-04-05 23:47:55 +02:00
|
|
|
|
2007-04-05 23:47:56 +02:00
|
|
|
DIRECTORY_STACK *thisDir;
|
2007-04-05 23:47:57 +02:00
|
|
|
int dirsToCopy = concurrentDirs;
|
|
|
|
|
|
|
|
/* Loop creating list of subdirs for all concurrent entries */
|
|
|
|
parms = inputparms;
|
|
|
|
while (dirsToCopy > 0) {
|
|
|
|
dirsToCopy--;
|
|
|
|
|
|
|
|
/* Work out search parameter in sub dir */
|
2007-06-03 23:07:42 +02:00
|
|
|
strcpyW (string, inputparms->dirName);
|
|
|
|
strcatW (string, finddata.cFileName);
|
|
|
|
strcatW (string, slashW);
|
|
|
|
WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(string));
|
2007-04-05 23:47:57 +02:00
|
|
|
|
|
|
|
/* Allocate memory, add to list */
|
|
|
|
thisDir = (DIRECTORY_STACK *) HeapAlloc(GetProcessHeap(),0,sizeof(DIRECTORY_STACK));
|
|
|
|
if (dirStack == NULL) dirStack = thisDir;
|
|
|
|
if (lastEntry != NULL) lastEntry->next = thisDir;
|
|
|
|
lastEntry = thisDir;
|
|
|
|
thisDir->next = NULL;
|
2007-06-03 23:07:42 +02:00
|
|
|
thisDir->dirName = HeapAlloc(GetProcessHeap(),0,
|
|
|
|
sizeof(WCHAR) * (strlenW(string)+1));
|
|
|
|
strcpyW(thisDir->dirName, string);
|
|
|
|
thisDir->fileName = HeapAlloc(GetProcessHeap(),0,
|
|
|
|
sizeof(WCHAR) * (strlenW(parms->fileName)+1));
|
|
|
|
strcpyW(thisDir->fileName, parms->fileName);
|
2007-04-05 23:47:57 +02:00
|
|
|
parms = parms->next;
|
|
|
|
}
|
2007-04-05 23:47:55 +02:00
|
|
|
}
|
|
|
|
} while (FindNextFile(hff, &finddata) != 0);
|
|
|
|
FindClose (hff);
|
|
|
|
|
|
|
|
while (dirStack != NULL) {
|
2007-04-05 23:47:56 +02:00
|
|
|
DIRECTORY_STACK *thisDir = dirStack;
|
2007-04-05 23:47:57 +02:00
|
|
|
dirStack = WCMD_list_directory (thisDir, 1);
|
|
|
|
while (thisDir != dirStack) {
|
|
|
|
DIRECTORY_STACK *tempDir = thisDir->next;
|
|
|
|
HeapFree(GetProcessHeap(),0,thisDir->dirName);
|
|
|
|
HeapFree(GetProcessHeap(),0,thisDir->fileName);
|
|
|
|
HeapFree(GetProcessHeap(),0,thisDir);
|
|
|
|
thisDir = tempDir;
|
|
|
|
}
|
2007-04-05 23:47:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle case where everything is filtered out */
|
|
|
|
if ((file_total + dir_total == 0) && (level == 0)) {
|
|
|
|
SetLastError (ERROR_FILE_NOT_FOUND);
|
|
|
|
WCMD_print_error ();
|
|
|
|
errorlevel = 1;
|
|
|
|
}
|
2007-04-05 23:47:57 +02:00
|
|
|
|
|
|
|
return parms;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WCMD_filesize64
|
|
|
|
*
|
2007-06-03 23:07:42 +02:00
|
|
|
* Convert a 64-bit number into a WCHARacter string, with commas every three digits.
|
1999-06-06 17:24:04 +02:00
|
|
|
* Result is returned in a static string overwritten with each call.
|
|
|
|
* FIXME: There must be a better algorithm!
|
|
|
|
*/
|
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR * WCMD_filesize64 (ULONGLONG n) {
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-03-01 12:43:19 +01:00
|
|
|
ULONGLONG q;
|
|
|
|
unsigned int r, i;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR *p;
|
|
|
|
static WCHAR buff[32];
|
1999-06-06 17:24:04 +02:00
|
|
|
|
|
|
|
p = buff;
|
|
|
|
i = -3;
|
|
|
|
do {
|
2007-03-28 10:01:52 +02:00
|
|
|
if (separator && ((++i)%3 == 1)) *p++ = ',';
|
1999-06-06 17:24:04 +02:00
|
|
|
q = n / 10;
|
|
|
|
r = n - (q * 10);
|
|
|
|
*p++ = r + '0';
|
|
|
|
*p = '\0';
|
|
|
|
n = q;
|
|
|
|
} while (n != 0);
|
|
|
|
WCMD_strrev (buff);
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WCMD_strrev
|
|
|
|
*
|
2007-06-03 23:07:42 +02:00
|
|
|
* Reverse a WCHARacter string in-place (strrev() is not available under unixen :-( ).
|
1999-06-06 17:24:04 +02:00
|
|
|
*/
|
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR * WCMD_strrev (WCHAR *buff) {
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-03-01 12:43:19 +01:00
|
|
|
int r, i;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR b;
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2007-06-03 23:07:42 +02:00
|
|
|
r = strlenW (buff);
|
1999-06-06 17:24:04 +02:00
|
|
|
for (i=0; i<r/2; i++) {
|
|
|
|
b = buff[i];
|
|
|
|
buff[i] = buff[r-i-1];
|
|
|
|
buff[r-i-1] = b;
|
|
|
|
}
|
|
|
|
return (buff);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-13 21:27:46 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* WCMD_dir_sort
|
|
|
|
*
|
|
|
|
* Sort based on the /O options supplied on the command line
|
|
|
|
*/
|
2004-12-06 21:43:55 +01:00
|
|
|
int WCMD_dir_sort (const void *a, const void *b)
|
|
|
|
{
|
2007-03-13 21:27:46 +01:00
|
|
|
WIN32_FIND_DATA *filea = (WIN32_FIND_DATA *)a;
|
|
|
|
WIN32_FIND_DATA *fileb = (WIN32_FIND_DATA *)b;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
/* If /OG or /O-G supplied, dirs go at the top or bottom, ignoring the
|
|
|
|
requested sort order for the directory components */
|
|
|
|
if (orderGroupDirs &&
|
|
|
|
((filea->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
|
|
|
|
(fileb->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)))
|
|
|
|
{
|
|
|
|
BOOL aDir = filea->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
if (aDir) result = -1;
|
|
|
|
else result = 1;
|
|
|
|
if (orderGroupDirsReverse) result = -result;
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* Order by Name: */
|
|
|
|
} else if (dirOrder == Name) {
|
2007-06-03 23:07:42 +02:00
|
|
|
result = lstrcmpiW(filea->cFileName, fileb->cFileName);
|
2007-03-13 21:27:46 +01:00
|
|
|
|
|
|
|
/* Order by Size: */
|
|
|
|
} else if (dirOrder == Size) {
|
|
|
|
ULONG64 sizea = (((ULONG64)filea->nFileSizeHigh) << 32) + filea->nFileSizeLow;
|
|
|
|
ULONG64 sizeb = (((ULONG64)fileb->nFileSizeHigh) << 32) + fileb->nFileSizeLow;
|
|
|
|
if( sizea < sizeb ) result = -1;
|
|
|
|
else if( sizea == sizeb ) result = 0;
|
|
|
|
else result = 1;
|
|
|
|
|
|
|
|
/* Order by Date: (Takes into account which date (/T option) */
|
|
|
|
} else if (dirOrder == Date) {
|
|
|
|
|
|
|
|
FILETIME *ft;
|
|
|
|
ULONG64 timea, timeb;
|
|
|
|
|
|
|
|
if (dirTime == Written) {
|
|
|
|
ft = &filea->ftLastWriteTime;
|
|
|
|
timea = (((ULONG64)ft->dwHighDateTime) << 32) + ft->dwLowDateTime;
|
|
|
|
ft = &fileb->ftLastWriteTime;
|
|
|
|
timeb = (((ULONG64)ft->dwHighDateTime) << 32) + ft->dwLowDateTime;
|
|
|
|
} else if (dirTime == Access) {
|
|
|
|
ft = &filea->ftLastAccessTime;
|
|
|
|
timea = (((ULONG64)ft->dwHighDateTime) << 32) + ft->dwLowDateTime;
|
|
|
|
ft = &fileb->ftLastAccessTime;
|
|
|
|
timeb = (((ULONG64)ft->dwHighDateTime) << 32) + ft->dwLowDateTime;
|
|
|
|
} else {
|
|
|
|
ft = &filea->ftCreationTime;
|
|
|
|
timea = (((ULONG64)ft->dwHighDateTime) << 32) + ft->dwLowDateTime;
|
|
|
|
ft = &fileb->ftCreationTime;
|
|
|
|
timeb = (((ULONG64)ft->dwHighDateTime) << 32) + ft->dwLowDateTime;
|
|
|
|
}
|
|
|
|
if( timea < timeb ) result = -1;
|
|
|
|
else if( timea == timeb ) result = 0;
|
|
|
|
else result = 1;
|
|
|
|
|
|
|
|
/* Order by Extension: (Takes into account which date (/T option) */
|
|
|
|
} else if (dirOrder == Extension) {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR drive[10];
|
|
|
|
WCHAR dir[MAX_PATH];
|
|
|
|
WCHAR fname[MAX_PATH];
|
|
|
|
WCHAR extA[MAX_PATH];
|
|
|
|
WCHAR extB[MAX_PATH];
|
2007-03-13 21:27:46 +01:00
|
|
|
|
|
|
|
/* Split into components */
|
|
|
|
WCMD_splitpath(filea->cFileName, drive, dir, fname, extA);
|
|
|
|
WCMD_splitpath(fileb->cFileName, drive, dir, fname, extB);
|
2007-06-03 23:07:42 +02:00
|
|
|
result = lstrcmpiW(extA, extB);
|
2007-03-13 21:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (orderReverse) result = -result;
|
|
|
|
return result;
|
1999-06-06 17:24:04 +02:00
|
|
|
}
|
2007-03-13 21:27:45 +01:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WCMD_getfileowner
|
|
|
|
*
|
2007-06-03 23:07:42 +02:00
|
|
|
* Reverse a WCHARacter string in-place (strrev() is not available under unixen :-( ).
|
2007-03-13 21:27:45 +01:00
|
|
|
*/
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen) {
|
2007-03-13 21:27:45 +01:00
|
|
|
|
|
|
|
ULONG sizeNeeded = 0;
|
|
|
|
DWORD rc;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR name[MAXSTRING];
|
|
|
|
WCHAR domain[MAXSTRING];
|
2007-03-13 21:27:45 +01:00
|
|
|
|
|
|
|
/* In case of error, return empty string */
|
|
|
|
*owner = 0x00;
|
|
|
|
|
|
|
|
/* Find out how much space we need for the owner security descritpor */
|
|
|
|
GetFileSecurity(filename, OWNER_SECURITY_INFORMATION, 0, 0, &sizeNeeded);
|
|
|
|
rc = GetLastError();
|
|
|
|
|
|
|
|
if(rc == ERROR_INSUFFICIENT_BUFFER && sizeNeeded > 0) {
|
|
|
|
|
|
|
|
LPBYTE secBuffer;
|
|
|
|
PSID pSID = NULL;
|
|
|
|
BOOL defaulted = FALSE;
|
|
|
|
ULONG nameLen = MAXSTRING;
|
|
|
|
ULONG domainLen = MAXSTRING;
|
|
|
|
SID_NAME_USE nameuse;
|
|
|
|
|
|
|
|
secBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(),0,sizeNeeded * sizeof(BYTE));
|
|
|
|
if(!secBuffer) return;
|
|
|
|
|
|
|
|
/* Get the owners security descriptor */
|
|
|
|
if(!GetFileSecurity(filename, OWNER_SECURITY_INFORMATION, secBuffer,
|
|
|
|
sizeNeeded, &sizeNeeded)) {
|
|
|
|
HeapFree(GetProcessHeap(),0,secBuffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the SID from the SD */
|
|
|
|
if(!GetSecurityDescriptorOwner(secBuffer, &pSID, &defaulted)) {
|
|
|
|
HeapFree(GetProcessHeap(),0,secBuffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert to a username */
|
|
|
|
if (LookupAccountSid(NULL, pSID, name, &nameLen, domain, &domainLen, &nameuse)) {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmt[] = {'%','s','%','c','%','s','\0'};
|
|
|
|
snprintfW(owner, ownerlen, fmt, domain, '\\', name);
|
2007-03-13 21:27:45 +01:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(),0,secBuffer);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WCMD_dir_trailer
|
|
|
|
*
|
|
|
|
* Print out the trailer for the supplied drive letter
|
|
|
|
*/
|
2007-06-03 23:07:42 +02:00
|
|
|
static void WCMD_dir_trailer(WCHAR drive) {
|
2007-04-05 23:47:56 +02:00
|
|
|
ULARGE_INTEGER avail, total, freebytes;
|
|
|
|
DWORD status;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR driveName[4] = {'c',':','\\','\0'};
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
driveName[0] = drive;
|
|
|
|
status = GetDiskFreeSpaceEx (driveName, &avail, &total, &freebytes);
|
2007-06-03 23:07:42 +02:00
|
|
|
WINE_TRACE("Writing trailer for '%s' gave %d(%d)\n", wine_dbgstr_w(driveName),
|
|
|
|
status, GetLastError());
|
2007-04-05 23:47:56 +02:00
|
|
|
|
|
|
|
if (errorlevel==0 && !bare) {
|
|
|
|
if (recurse) {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmt1[] = {'\n',' ',' ',' ',' ',' ','T','o','t','a','l',' ','f','i','l','e','s',
|
|
|
|
' ','l','i','s','t','e','d',':','\n','%','8','d',' ','f','i','l','e',
|
|
|
|
's','%','2','5','s',' ','b','y','t','e','s','\n','\0'};
|
|
|
|
static const WCHAR fmt2[] = {'%','8','d',' ','d','i','r','e','c','t','o','r','i','e','s',' ','%',
|
|
|
|
'1','8','s',' ','b','y','t','e','s',' ','f','r','e','e','\n','\n',
|
|
|
|
'\0'};
|
|
|
|
WCMD_output (fmt1, file_total, WCMD_filesize64 (byte_total));
|
|
|
|
WCMD_output (fmt2, dir_total, WCMD_filesize64 (freebytes.QuadPart));
|
2007-04-05 23:47:56 +02:00
|
|
|
} else {
|
2007-06-03 23:07:42 +02:00
|
|
|
static const WCHAR fmt[] = {' ','%','1','8','s',' ','b','y','t','e','s',' ','f','r','e','e',
|
|
|
|
'\n','\n','\0'};
|
|
|
|
WCMD_output (fmt, WCMD_filesize64 (freebytes.QuadPart));
|
2007-04-05 23:47:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|