X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Ffileutils.cpp;h=6c98ba30071893a3a201639f78a15a176caa489a;hb=4cc992f6c20354eef88b7652f268591daccb1b20;hp=8a726ba699621f74d4089e4ef7853eca4700529c;hpb=429a4ddf6ac9fd0f16667ff38a40dc437d9af2d2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/fileutils.cpp b/src/fileutils.cpp index 8a726ba69..6c98ba300 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -21,6 +21,10 @@ #include +#ifndef _WIN32 +# include +#endif + FileReader::FileReader(const std::string& filename) { Load(filename); @@ -86,12 +90,46 @@ bool FileSystem::FileExists(const std::string& file) return !access(file.c_str(), F_OK); } +bool FileSystem::GetFileList(const std::string& directory, std::vector& entries, const std::string& match) +{ +#ifdef _WIN32 + const std::string search_path = directory + "\\" + match; + + WIN32_FIND_DATAA wfd; + HANDLE fh = FindFirstFileA(search_path.c_str(), &wfd); + if (fh == INVALID_HANDLE_VALUE) + return false; + + do + { + entries.push_back(wfd.cFileName); + } while (FindNextFile(fh, &wfd) != 0); + + FindClose(fh); + return true; +#else + DIR* library = opendir(directory.c_str()); + if (!library) + return false; + + dirent* entry = NULL; + while ((entry = readdir(library))) + { + if (InspIRCd::Match(entry->d_name, match, ascii_case_insensitive_map)) + entries.push_back(entry->d_name); + } + closedir(library); + return true; +#endif +} + + std::string FileSystem::GetFileName(const std::string& name) { #ifdef _WIN32 size_t pos = name.find_last_of("\\/"); #else - size_t pos = name.rfind('/'); + size_t pos = name.rfind('/'); #endif return pos == std::string::npos ? name : name.substr(++pos); }