From 2f8fbdb9f52d2118108d69914207766e296d7d37 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 10 Dec 2014 02:58:12 +1000 Subject: [PATCH] Rewrite fs:GetDirListing(file) by kahrl --- src/filesys.cpp | 62 ++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 47 deletions(-) diff --git a/src/filesys.cpp b/src/filesys.cpp index 4b16d2d3a..597643887 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -34,11 +34,6 @@ namespace fs #define _WIN32_WINNT 0x0501 #include -#include -#include -#include - -#define BUFSIZE MAX_PATH std::vector GetDirListing(std::string pathstring) { @@ -47,34 +42,18 @@ std::vector GetDirListing(std::string pathstring) WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; DWORD dwError; - LPTSTR DirSpec; - INT retval; - - DirSpec = (LPTSTR) malloc (BUFSIZE); - - if(DirSpec == NULL) { - errorstream<<"GetDirListing: Insufficient memory available"< (BUFSIZE - 2)) { - errorstream<<"GetDirListing: Input directory is too large."< GetDirListing(std::string pathstring) DirListNode node; node.name = FindFileData.cFileName; node.dir = FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; - if(node.name != "." && node.name != "..") + if (node.name != "." && node.name != "..") listing.push_back(node); // List all the other files in the directory. @@ -98,23 +77,12 @@ std::vector GetDirListing(std::string pathstring) dwError = GetLastError(); FindClose(hFind); if (dwError != ERROR_NO_MORE_FILES) { - errorstream<<"GetDirListing: FindNextFile error. Error is " - < GetDirListing(std::string pathstring) // NOTE: // Be very sure to not include '..' in the results, it will // result in an epic failure when deleting stuff. - if(dirp->d_name == "." || dirp->d_name == "..") + if(strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) continue; DirListNode node;