FSList WindowsFilesystemNode::listDir()

in atari_py/ale_interface/src/os_dependent/FSNodeWin32.cxx [187:236]


FSList WindowsFilesystemNode::listDir(ListMode mode) const
{
  assert(_isDirectory);

  FSList myList;

  if (_isPseudoRoot)
  {
    // Drives enumeration
    TCHAR drive_buffer[100];
    GetLogicalDriveStrings(sizeof(drive_buffer) / sizeof(TCHAR), drive_buffer);

    for (TCHAR *current_drive = drive_buffer; *current_drive; 
         current_drive += _tcslen(current_drive) + 1)
    {
      WindowsFilesystemNode entry;		
      char drive_name[2];

      drive_name[0] = toAscii(current_drive)[0];
      drive_name[1] = '\0';
      entry._displayName = drive_name;
      entry._isDirectory = true;
      entry._isValid = true;
      entry._isPseudoRoot = false;
      entry._path = toAscii(current_drive);
      myList.push_back(wrap(new WindowsFilesystemNode(&entry)));
    }
  }
  else
  {
    // Files enumeration
    WIN32_FIND_DATA desc;
    HANDLE handle;
    char searchPath[MAX_PATH + 10];

    sprintf(searchPath, "%s*", _path.c_str());

    handle = FindFirstFile(toUnicode(searchPath), &desc);
    if (handle == INVALID_HANDLE_VALUE)
      return myList;

    addFile(myList, mode, _path.c_str(), &desc);
    while (FindNextFile(handle, &desc))
      addFile(myList, mode, _path.c_str(), &desc);

    FindClose(handle);
  }

  return myList;
}