Line 616... |
Line 616... |
616 |
struct SUBDIRINFO * parent; /* points to parent subdirectory */
|
616 |
struct SUBDIRINFO * parent; /* points to parent subdirectory */
|
617 |
char *currentpath; /* Stores the full path this structure represents */
|
617 |
char *currentpath; /* Stores the full path this structure represents */
|
618 |
char *subdir; /* points to last subdir within currentpath */
|
618 |
char *subdir; /* points to last subdir within currentpath */
|
619 |
char *dsubdir; /* Stores a display ready directory name */
|
619 |
char *dsubdir; /* Stores a display ready directory name */
|
620 |
long subdircnt; /* Initially a count of how many subdirs in this dir */
|
620 |
long subdircnt; /* Initially a count of how many subdirs in this dir */
|
621 |
HANDLE findnexthnd; /* The handle returned by findfirst, used in findnext */
|
621 |
struct FFDTA *findnexthnd; /* The handle returned by findfirst, used in findnext */
|
622 |
struct DIRDATA ddata; /* Maintain directory information, eg attributes */
|
622 |
struct DIRDATA ddata; /* Maintain directory information, eg attributes */
|
623 |
} SUBDIRINFO;
|
623 |
} SUBDIRINFO;
|
624 |
|
624 |
|
625 |
|
625 |
|
626 |
/**
|
626 |
/**
|
Line 630... |
Line 630... |
630 |
* Stores additional directory data in ddata if non-NULL
|
630 |
* Stores additional directory data in ddata if non-NULL
|
631 |
* and path is valid.
|
631 |
* and path is valid.
|
632 |
*/
|
632 |
*/
|
633 |
static long hasSubdirectories(char *path, DIRDATA *ddata) {
|
633 |
static long hasSubdirectories(char *path, DIRDATA *ddata) {
|
634 |
static struct WIN32_FIND_DATA findData;
|
634 |
static struct WIN32_FIND_DATA findData;
|
635 |
HANDLE hnd;
|
635 |
struct FFDTA *hnd;
|
636 |
static char buffer[MAXBUF];
|
636 |
static char buffer[MAXBUF];
|
637 |
int hasSubdirs = 0;
|
637 |
int hasSubdirs = 0;
|
638 |
|
638 |
|
639 |
/* get the handle to start with (using wildcard spec) */
|
639 |
/* get the handle to start with (using wildcard spec) */
|
640 |
strcpy(buffer, path);
|
640 |
strcpy(buffer, path);
|
Line 643... |
Line 643... |
643 |
/* Use FindFirstFileEx when available (falls back to FindFirstFile).
|
643 |
/* Use FindFirstFileEx when available (falls back to FindFirstFile).
|
644 |
* Allows us to limit returned results to just directories
|
644 |
* Allows us to limit returned results to just directories
|
645 |
* if supported by underlying filesystem.
|
645 |
* if supported by underlying filesystem.
|
646 |
*/
|
646 |
*/
|
647 |
hnd = FindFirstFile(buffer, &findData);
|
647 |
hnd = FindFirstFile(buffer, &findData);
|
648 |
if (hnd == INVALID_HANDLE_VALUE)
|
648 |
if (hnd == INVALID_HANDLE_VALUE) {
|
649 |
{
|
- |
|
650 |
showInvalidPath(path); /* Display error message */
|
649 |
showInvalidPath(path); /* Display error message */
|
651 |
return -1L;
|
650 |
return -1L;
|
652 |
}
|
651 |
}
|
653 |
|
652 |
|
654 |
|
653 |
|
Line 889... |
Line 888... |
889 |
* or 1 if files displayed, no errors.
|
888 |
* or 1 if files displayed, no errors.
|
890 |
*/
|
889 |
*/
|
891 |
static int displayFiles(char *path, char *padding, int hasMoreSubdirs, DIRDATA *ddata) {
|
890 |
static int displayFiles(char *path, char *padding, int hasMoreSubdirs, DIRDATA *ddata) {
|
892 |
static char buffer[MAXBUF];
|
891 |
static char buffer[MAXBUF];
|
893 |
struct WIN32_FIND_DATA entry; /* current directory entry info */
|
892 |
struct WIN32_FIND_DATA entry; /* current directory entry info */
|
894 |
HANDLE dir; /* Current directory entry working with */
|
893 |
struct FFDTA *dir; /* Current directory entry working with */
|
895 |
unsigned long filesShown = 0;
|
894 |
unsigned long filesShown = 0;
|
896 |
|
895 |
|
897 |
/* get handle for files in current directory (using wildcard spec) */
|
896 |
/* get handle for files in current directory (using wildcard spec) */
|
898 |
strcpy(buffer, path);
|
897 |
strcpy(buffer, path);
|
899 |
strcat(buffer, "*");
|
898 |
strcat(buffer, "*");
|
Line 969... |
Line 968... |
969 |
* was found, and if so copies appropriate data into subdir and dsubdir.
|
968 |
* was found, and if so copies appropriate data into subdir and dsubdir.
|
970 |
* It will repeat until a valid subdirectory is found or no more
|
969 |
* It will repeat until a valid subdirectory is found or no more
|
971 |
* are found, at which point it closes the FindFile search handle and
|
970 |
* are found, at which point it closes the FindFile search handle and
|
972 |
* return INVALID_HANDLE_VALUE. If successful, returns FindFile handle.
|
971 |
* return INVALID_HANDLE_VALUE. If successful, returns FindFile handle.
|
973 |
*/
|
972 |
*/
|
974 |
static HANDLE cycleFindResults(HANDLE findnexthnd, struct WIN32_FIND_DATA *entry, char *subdir, char *dsubdir) {
|
973 |
static struct FFDTA *cycleFindResults(struct FFDTA *findnexthnd, struct WIN32_FIND_DATA *entry, char *subdir, char *dsubdir) {
|
975 |
/* cycle through directory until 1st non . or .. directory is found. */
|
974 |
/* cycle through directory until 1st non . or .. directory is found. */
|
976 |
do
|
975 |
do
|
977 |
{
|
976 |
{
|
978 |
/* skip files & hidden or system directories */
|
977 |
/* skip files & hidden or system directories */
|
979 |
if ((((entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) ||
|
978 |
if ((((entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) ||
|
Line 1013... |
Line 1012... |
1013 |
* findclose when directory has finished processing, and can be
|
1012 |
* findclose when directory has finished processing, and can be
|
1014 |
* passed to findnextsubdir to find subsequent subdirectories.
|
1013 |
* passed to findnextsubdir to find subsequent subdirectories.
|
1015 |
* Returns INVALID_HANDLE_VALUE on error.
|
1014 |
* Returns INVALID_HANDLE_VALUE on error.
|
1016 |
* currentpath must end in \
|
1015 |
* currentpath must end in \
|
1017 |
*/
|
1016 |
*/
|
1018 |
static HANDLE findFirstSubdir(char *currentpath, char *subdir, char *dsubdir) {
|
1017 |
static struct FFDTA *findFirstSubdir(char *currentpath, char *subdir, char *dsubdir) {
|
1019 |
static char buffer[MAXBUF];
|
1018 |
static char buffer[MAXBUF];
|
1020 |
HANDLE dir; /* Current directory entry working with */
|
1019 |
struct FFDTA *dir; /* Current directory entry working with */
|
1021 |
|
1020 |
|
1022 |
/* get handle for files in current directory (using wildcard spec) */
|
1021 |
/* get handle for files in current directory (using wildcard spec) */
|
1023 |
strcpy(buffer, currentpath);
|
1022 |
strcpy(buffer, currentpath);
|
1024 |
strcat(buffer, "*");
|
1023 |
strcat(buffer, "*");
|
1025 |
|
1024 |
|
1026 |
dir = FindFirstFile(buffer, &findSubdir_entry);
|
1025 |
dir = FindFirstFile(buffer, &findSubdir_entry);
|
1027 |
if (dir == INVALID_HANDLE_VALUE)
|
1026 |
if (dir == INVALID_HANDLE_VALUE) {
|
1028 |
{
|
- |
|
1029 |
showInvalidPath(currentpath);
|
1027 |
showInvalidPath(currentpath);
|
1030 |
return INVALID_HANDLE_VALUE;
|
1028 |
return INVALID_HANDLE_VALUE;
|
1031 |
}
|
1029 |
}
|
1032 |
|
1030 |
|
1033 |
/* clear result path */
|
1031 |
/* clear result path */
|
Line 1042... |
Line 1040... |
1042 |
* dsubdir is the name to display
|
1040 |
* dsubdir is the name to display
|
1043 |
* currentpath must end in \
|
1041 |
* currentpath must end in \
|
1044 |
* If a subdirectory is found, returns 0, otherwise returns 1
|
1042 |
* If a subdirectory is found, returns 0, otherwise returns 1
|
1045 |
* (either error or no more files).
|
1043 |
* (either error or no more files).
|
1046 |
*/
|
1044 |
*/
|
1047 |
static int findNextSubdir(HANDLE findnexthnd, char *subdir, char *dsubdir) {
|
1045 |
static int findNextSubdir(struct FFDTA *findnexthnd, char *subdir, char *dsubdir) {
|
1048 |
/* clear result path */
|
1046 |
/* clear result path */
|
1049 |
strcpy(subdir, "");
|
1047 |
strcpy(subdir, "");
|
1050 |
|
1048 |
|
1051 |
if (FindNextFile(findnexthnd, &findSubdir_entry) == 0) return 1; // no subdirs found
|
1049 |
if (FindNextFile(findnexthnd, &findSubdir_entry) == 0) return 1; // no subdirs found
|
1052 |
|
1050 |
|