diff --git a/src/os/windows/FSNodeWINDOWS.cxx b/src/os/windows/FSNodeWINDOWS.cxx index 0eddc1c48..e4b92fa12 100644 --- a/src/os/windows/FSNodeWINDOWS.cxx +++ b/src/os/windows/FSNodeWINDOWS.cxx @@ -141,10 +141,34 @@ bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const if (handle == INVALID_HANDLE_VALUE) return false; - addFile(myList, mode, _path, desc); + do { + const char* const asciiName = desc.cFileName; - while (FindNextFile(handle, &desc)) - addFile(myList, mode, _path, desc); + // Skip files starting with '.' (we assume empty filenames never occur) + if (asciiName[0] == '.') + continue; + + const bool isDirectory = static_cast(desc.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + const bool isFile = !isDirectory; + + if ((isFile && mode == FSNode::ListMode::DirectoriesOnly) || + (isDirectory && mode == FSNode::ListMode::FilesOnly)) + continue; + + FSNodeWINDOWS entry; + entry._isDirectory = isDirectory; + entry._isFile = isFile; + entry._displayName = asciiName; + entry._path = _path; + entry._path += asciiName; + if (entry._isDirectory) + entry._path += FSNode::PATH_SEPARATOR; + entry._isPseudoRoot = false; + entry._size = desc.nFileSizeHigh * (static_cast(MAXDWORD) + 1) + desc.nFileSizeLow; + + myList.emplace_back(make_unique(entry)); + } + while (FindNextFile(handle, &desc)); FindClose(handle); } @@ -152,37 +176,6 @@ bool FSNodeWINDOWS::getChildren(AbstractFSList& myList, ListMode mode) const return true; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FSNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode, - const string& base, const WIN32_FIND_DATA& find_data) -{ - const char* const asciiName = find_data.cFileName; - - // Skip files starting with '.' (we assume empty filenames never occur) - if (asciiName[0] == '.') - return; - - const bool isDirectory = static_cast(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - const bool isFile = !isDirectory;//(find_data->dwFileAttributes & FILE_ATTRIBUTE_NORMAL ? true : false); - - if ((isFile && mode == FSNode::ListMode::DirectoriesOnly) || - (isDirectory && mode == FSNode::ListMode::FilesOnly)) - return; - - FSNodeWINDOWS entry; - entry._isDirectory = isDirectory; - entry._isFile = isFile; - entry._displayName = asciiName; - entry._path = base; - entry._path += asciiName; - if (entry._isDirectory) - entry._path += FSNode::PATH_SEPARATOR; - entry._isPseudoRoot = false; - entry._size = find_data.nFileSizeHigh * (static_cast(MAXDWORD) + 1) + find_data.nFileSizeLow; - - list.emplace_back(make_unique(entry)); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool FSNodeWINDOWS::exists() const { diff --git a/src/os/windows/FSNodeWINDOWS.hxx b/src/os/windows/FSNodeWINDOWS.hxx index 7f297cb9d..5959a4b60 100644 --- a/src/os/windows/FSNodeWINDOWS.hxx +++ b/src/os/windows/FSNodeWINDOWS.hxx @@ -77,18 +77,6 @@ class FSNodeWINDOWS : public AbstractFSNode */ bool setFlags(); - /** - * Adds a single FSNodeWINDOWS to a given list. - * This method is used by getChildren() to populate the directory entries list. - * - * @param list List to put the file entry node in. - * @param mode Mode to use while adding the file entry to the list. - * @param base String with the directory being listed. - * @param find_data Describes a file that the FindFirstFile, FindFirstFileEx, or FindNextFile functions find. - */ - static void addFile(AbstractFSList& list, ListMode mode, - const string& base, const WIN32_FIND_DATA& find_data); - private: string _displayName, _path; bool _isPseudoRoot{false}, _isDirectory{false}, _isFile{false};