Subversion Repositories SvarDOS

Rev

Rev 2037 | Rev 2039 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2037 Rev 2038
Line 669... Line 669...
669
    sprintf(serial, "%04X:%04X",
669
    sprintf(serial, "%04X:%04X",
670
      serialNum.serialParts.b, serialNum.serialParts.a);
670
      serialNum.serialParts.b, serialNum.serialParts.a);
671
}
671
}
672
 
672
 
673
 
673
 
674
/* FindFile stuff to support optional NT API variant */
-
 
675
typedef union WIN32_FIND_DATA_BOTH
-
 
676
{
-
 
677
 WIN32_FIND_DATAW ud;
-
 
678
 WIN32_FIND_DATAA ad;
-
 
679
} WIN32_FIND_DATA_BOTH;
-
 
680
 
-
 
681
#ifndef STDCALL
674
#ifndef STDCALL
682
#define STDCALL __stdcall
675
#define STDCALL __stdcall
683
#endif
676
#endif
684
 
677
 
685
 
678
 
Line 1057... Line 1050...
1057
 * was found, and if so copies appropriate data into subdir and dsubdir.
1050
 * was found, and if so copies appropriate data into subdir and dsubdir.
1058
 * It will repeat until a valid subdirectory is found or no more
1051
 * It will repeat until a valid subdirectory is found or no more
1059
 * are found, at which point it closes the FindFile search handle and
1052
 * are found, at which point it closes the FindFile search handle and
1060
 * return INVALID_HANDLE_VALUE.  If successful, returns FindFile handle.
1053
 * return INVALID_HANDLE_VALUE.  If successful, returns FindFile handle.
1061
 */
1054
 */
1062
static HANDLE cycleFindResults(HANDLE findnexthnd, WIN32_FIND_DATA_BOTH *entry, char *subdir, char *dsubdir) {
1055
static HANDLE cycleFindResults(HANDLE findnexthnd, WIN32_FIND_DATAA *entry, char *subdir, char *dsubdir) {
1063
  /* cycle through directory until 1st non . or .. directory is found. */
1056
  /* cycle through directory until 1st non . or .. directory is found. */
1064
  do
1057
  do
1065
  {
1058
  {
1066
    /* skip files & hidden or system directories */
1059
    /* skip files & hidden or system directories */
1067
    if ((((entry->ad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) ||
1060
    if ((((entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) ||
1068
         ((entry->ad.dwFileAttributes &
1061
         ((entry->dwFileAttributes &
1069
          (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0  && !dspAll) ) ||
1062
          (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0  && !dspAll) ) ||
1070
        ((strcmp(entry->ad.cFileName, ".") == 0) ||
1063
        ((strcmp(entry->cFileName, ".") == 0) ||
1071
         (strcmp(entry->ad.cFileName, "..") == 0)) )
1064
         (strcmp(entry->cFileName, "..") == 0)) )
1072
    {
1065
    {
1073
      if (FindNextFile(findnexthnd, &(entry->ad)) == 0)
1066
      if (FindNextFile(findnexthnd, entry) == 0)
1074
      {
1067
      {
1075
        FindClose(findnexthnd);      // prevent resource leaks
1068
        FindClose(findnexthnd);      // prevent resource leaks
1076
        return INVALID_HANDLE_VALUE; // no subdirs found
1069
        return INVALID_HANDLE_VALUE; // no subdirs found
1077
      }
1070
      }
1078
    }
1071
    }
1079
    else
1072
    else
1080
    {
1073
    {
1081
      /* set display name */
1074
      /* set display name */
1082
      strcpy(dsubdir, entry->ad.cFileName);
1075
      strcpy(dsubdir, entry->cFileName);
1083
 
1076
 
1084
      /* set canical name to use for further FindFile calls */
1077
      /* set canical name to use for further FindFile calls */
1085
      /* use short file name if exists as lfn may contain unicode values converted
1078
      /* use short file name if exists as lfn may contain unicode values converted
1086
       * to default character (eg. ?) and so not a valid path.
1079
       * to default character (eg. ?) and so not a valid path.
1087
       */
1080
       */
1088
      strcpy(subdir, entry->ad.cFileName);
1081
      strcpy(subdir, entry->cFileName);
1089
      strcat(subdir, "\\");
1082
      strcat(subdir, "\\");
1090
    }
1083
    }
1091
  } while (!*subdir); // while (subdir is still blank)
1084
  } while (!*subdir); // while (subdir is still blank)
1092
 
1085
 
1093
  return findnexthnd;
1086
  return findnexthnd;
1094
}
1087
}
1095
 
1088
 
1096
 
1089
 
1097
/* FindFile buffer used by findFirstSubdir and findNextSubdir only */
1090
/* FindFile buffer used by findFirstSubdir and findNextSubdir only */
1098
static WIN32_FIND_DATA_BOTH findSubdir_entry; /* current directory entry info    */
1091
static WIN32_FIND_DATAA findSubdir_entry; /* current directory entry info    */
1099
 
1092
 
1100
/**
1093
/**
1101
 * Given the current path, find the 1st subdirectory.
1094
 * Given the current path, find the 1st subdirectory.
1102
 * The subdirectory found is stored in subdir.
1095
 * The subdirectory found is stored in subdir.
1103
 * subdir is cleared on error or no subdirectories.
1096
 * subdir is cleared on error or no subdirectories.
Line 1113... Line 1106...
1113
 
1106
 
1114
  /* get handle for files in current directory (using wildcard spec) */
1107
  /* get handle for files in current directory (using wildcard spec) */
1115
  strcpy(buffer, currentpath);
1108
  strcpy(buffer, currentpath);
1116
  strcat(buffer, "*");
1109
  strcat(buffer, "*");
1117
 
1110
 
1118
  dir = FindFirstFileA(buffer, &findSubdir_entry.ad);
1111
  dir = FindFirstFileA(buffer, &findSubdir_entry);
1119
  if (dir == INVALID_HANDLE_VALUE)
1112
  if (dir == INVALID_HANDLE_VALUE)
1120
  {
1113
  {
1121
    showInvalidPath(currentpath);
1114
    showInvalidPath(currentpath);
1122
    return INVALID_HANDLE_VALUE;
1115
    return INVALID_HANDLE_VALUE;
1123
  }
1116
  }
Line 1138... Line 1131...
1138
 */
1131
 */
1139
static int findNextSubdir(HANDLE findnexthnd, char *subdir, char *dsubdir) {
1132
static int findNextSubdir(HANDLE findnexthnd, char *subdir, char *dsubdir) {
1140
  /* clear result path */
1133
  /* clear result path */
1141
  strcpy(subdir, "");
1134
  strcpy(subdir, "");
1142
 
1135
 
1143
  if (FindNextFile(findnexthnd, &findSubdir_entry.ad) == 0) return 1; // no subdirs found
1136
  if (FindNextFile(findnexthnd, &findSubdir_entry) == 0) return 1; // no subdirs found
1144
 
1137
 
1145
  if (cycleFindResults(findnexthnd, &findSubdir_entry, subdir, dsubdir) == INVALID_HANDLE_VALUE)
1138
  if (cycleFindResults(findnexthnd, &findSubdir_entry, subdir, dsubdir) == INVALID_HANDLE_VALUE)
1146
    return 1;
1139
    return 1;
1147
  else
1140
  else
1148
    return 0;
1141
    return 0;