Subversion Repositories SvarDOS

Rev

Rev 2031 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2031 Rev 2032
Line 715... Line 715...
715
 * dsubdir is subdir already modified so ready to display to user
715
 * dsubdir is subdir already modified so ready to display to user
716
 */
716
 */
717
SUBDIRINFO *newSubdirInfo(SUBDIRINFO *parent, char *subdir, char *dsubdir)
717
SUBDIRINFO *newSubdirInfo(SUBDIRINFO *parent, char *subdir, char *dsubdir)
718
{
718
{
719
  int parentLen, subdirLen;
719
  int parentLen, subdirLen;
-
 
720
  SUBDIRINFO *temp;
720
 
721
 
721
  /* Get length of parent directory */
722
  /* Get length of parent directory */
722
  if (parent == NULL)
723
  if (parent == NULL)
723
    parentLen = 0;
724
    parentLen = 0;
724
  else
725
  else
Line 727... Line 728...
727
  /* Get length of subdir, add 1 if does not end in slash */
728
  /* Get length of subdir, add 1 if does not end in slash */
728
  subdirLen = strlen(subdir);
729
  subdirLen = strlen(subdir);
729
  if ((subdirLen < 1) || ( (*(subdir+subdirLen-1) != '\\') && (*(subdir+subdirLen-1) != '/') ) )
730
  if ((subdirLen < 1) || ( (*(subdir+subdirLen-1) != '\\') && (*(subdir+subdirLen-1) != '/') ) )
730
    subdirLen++;
731
    subdirLen++;
731
 
732
 
732
  SUBDIRINFO *temp = (SUBDIRINFO *)malloc(sizeof(SUBDIRINFO));
733
  temp = (SUBDIRINFO *)malloc(sizeof(SUBDIRINFO));
733
  if (temp == NULL)
734
  if (temp == NULL)
734
  {
735
  {
735
    showOutOfMemory(subdir);
736
    showOutOfMemory(subdir);
736
    return NULL;
737
    return NULL;
737
  }
738
  }
Line 995... Line 996...
995
 * was found, and if so copies appropriate data into subdir and dsubdir.
996
 * was found, and if so copies appropriate data into subdir and dsubdir.
996
 * It will repeat until a valid subdirectory is found or no more
997
 * It will repeat until a valid subdirectory is found or no more
997
 * are found, at which point it closes the FindFile search handle and
998
 * are found, at which point it closes the FindFile search handle and
998
 * return INVALID_HANDLE_VALUE.  If successful, returns FindFile handle.
999
 * return INVALID_HANDLE_VALUE.  If successful, returns FindFile handle.
999
 */
1000
 */
1000
HANDLE cycleFindResults(HANDLE findnexthnd, WIN32_FIND_DATA_BOTH &entry, char *subdir, char *dsubdir)
1001
HANDLE cycleFindResults(HANDLE findnexthnd, WIN32_FIND_DATA_BOTH *entry, char *subdir, char *dsubdir)
1001
{
1002
{
1002
  /* cycle through directory until 1st non . or .. directory is found. */
1003
  /* cycle through directory until 1st non . or .. directory is found. */
1003
  do
1004
  do
1004
  {
1005
  {
1005
    /* skip files & hidden or system directories */
1006
    /* skip files & hidden or system directories */
1006
    if ((((entry.ad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) ||
1007
    if ((((entry->ad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) ||
1007
         ((entry.ad.dwFileAttributes &
1008
         ((entry->ad.dwFileAttributes &
1008
          (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0  && !dspAll) ) ||
1009
          (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0  && !dspAll) ) ||
1009
        ((strcmp(entry.ad.cFileName, ".") == 0) ||
1010
        ((strcmp(entry->ad.cFileName, ".") == 0) ||
1010
         (strcmp(entry.ad.cFileName, "..") == 0)) )
1011
         (strcmp(entry->ad.cFileName, "..") == 0)) )
1011
    {
1012
    {
1012
      if (FindNextFile(findnexthnd, &entry.ad) == 0)
1013
      if (FindNextFile(findnexthnd, &(entry->ad)) == 0)
1013
      {
1014
      {
1014
        FindClose(findnexthnd);      // prevent resource leaks
1015
        FindClose(findnexthnd);      // prevent resource leaks
1015
        return INVALID_HANDLE_VALUE; // no subdirs found
1016
        return INVALID_HANDLE_VALUE; // no subdirs found
1016
      }
1017
      }
1017
    }
1018
    }
1018
    else
1019
    else
1019
    {
1020
    {
1020
      /* set display name */
1021
      /* set display name */
1021
      strcpy(dsubdir, entry.ad.cFileName);
1022
      strcpy(dsubdir, entry->ad.cFileName);
1022
 
1023
 
1023
      /* set canical name to use for further FindFile calls */
1024
      /* set canical name to use for further FindFile calls */
1024
      /* use short file name if exists as lfn may contain unicode values converted
1025
      /* use short file name if exists as lfn may contain unicode values converted
1025
       * to default character (eg. ?) and so not a valid path.
1026
       * to default character (eg. ?) and so not a valid path.
1026
       */
1027
       */
1027
      strcpy(subdir, entry.ad.cFileName);
1028
      strcpy(subdir, entry->ad.cFileName);
1028
      strcat(subdir, "\\");
1029
      strcat(subdir, "\\");
1029
    }
1030
    }
1030
  } while (!*subdir); // while (subdir is still blank)
1031
  } while (!*subdir); // while (subdir is still blank)
1031
 
1032
 
1032
  return findnexthnd;
1033
  return findnexthnd;
Line 1063... Line 1064...
1063
  }
1064
  }
1064
 
1065
 
1065
  /* clear result path */
1066
  /* clear result path */
1066
  strcpy(subdir, "");
1067
  strcpy(subdir, "");
1067
 
1068
 
1068
  return cycleFindResults(dir, findSubdir_entry, subdir, dsubdir);
1069
  return cycleFindResults(dir, &findSubdir_entry, subdir, dsubdir);
1069
}
1070
}
1070
 
1071
 
1071
/**
1072
/**
1072
 * Given a search HANDLE, will find the next subdirectory,
1073
 * Given a search HANDLE, will find the next subdirectory,
1073
 * setting subdir to the found directory name.
1074
 * setting subdir to the found directory name.
Line 1081... Line 1082...
1081
  /* clear result path */
1082
  /* clear result path */
1082
  strcpy(subdir, "");
1083
  strcpy(subdir, "");
1083
 
1084
 
1084
  if (FindNextFile(findnexthnd, &findSubdir_entry.ad) == 0) return 1; // no subdirs found
1085
  if (FindNextFile(findnexthnd, &findSubdir_entry.ad) == 0) return 1; // no subdirs found
1085
 
1086
 
1086
  if (cycleFindResults(findnexthnd, findSubdir_entry, subdir, dsubdir) == INVALID_HANDLE_VALUE)
1087
  if (cycleFindResults(findnexthnd, &findSubdir_entry, subdir, dsubdir) == INVALID_HANDLE_VALUE)
1087
    return 1;
1088
    return 1;
1088
  else
1089
  else
1089
    return 0;
1090
    return 0;
1090
}
1091
}
1091
 
1092