From c736145c2fc7c56b70bc593e011d51dbcf247f21 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 6 Jul 2014 23:21:25 +0200 Subject: [PATCH] CPath can now return the file list with a path filter. --- code/nel/include/nel/misc/path.h | 8 +++ code/nel/src/misc/path.cpp | 61 +++++++++++++++++++ .../plugins/gui_editor/texture_chooser.cpp | 3 +- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index 73652a581..f3120c907 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -200,6 +200,10 @@ public: */ void getFileListByName(const std::string &extension, const std::string &name, std::vector &filenames); + /** Create a list of file having the requested string in the path and the requested extension. + */ + void getFileListByPath(const std::string &extension, const std::string &path, std::vector &filenames); + /** Make a path relative to another if possible, else doesn't change it. * \param basePath is the base path to be relative to. * \param relativePath is the path to make relative to basePath. @@ -492,6 +496,10 @@ public: */ static void getFileListByName(const std::string &extension, const std::string &name, std::vector &filenames); + /** Create a list of file having the requested string in the path and the requested extension + */ + static void getFileListByPath(const std::string &extension, const std::string &path, std::vector &filenames); + /** Make a path relative to another if possible, else doesn't change it. * \param basePath is the base path to be relative to. * \param relativePath is the path to make relative to basePath. diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index f92b0bda7..c5a80e830 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -219,6 +219,67 @@ void CFileContainer::getFileListByName(const std::string &extension, const std:: } } +void CPath::getFileListByPath(const std::string &extension, const std::string &path, std::vector &filenames) +{ + getInstance()->_FileContainer.getFileListByPath(extension, path, filenames); +} + +void CFileContainer::getFileListByPath(const std::string &extension, const std::string &path, std::vector &filenames) +{ + if (!_MemoryCompressed) + { + TFiles::iterator first(_Files.begin()), last(_Files.end()); + + if( !path.empty() ) + { + for (; first != last; ++ first) + { + string ext = SSMext.get(first->second.idExt); + string p = SSMpath.get(first->second.idPath); + if (p.find(path) != string::npos && (ext == extension || extension.empty())) + { + filenames.push_back(first->first); + } + } + } + // if extension is empty we keep all files + else + { + for (; first != last; ++ first) + { + filenames.push_back(first->first); + } + } + } + else + { + // compressed memory version + std::vector::iterator first(_MCFiles.begin()), last(_MCFiles.end()); + + if( !path.empty() ) + { + for (; first != last; ++ first) + { + string ext = SSMext.get(first->idExt); + string p = SSMpath.get(first->idPath); + + if (strstr(p.c_str(), path.c_str()) != NULL && (ext == extension || extension.empty())) + { + filenames.push_back(first->Name); + } + } + } + // if extension is empty we keep all files + else + { + for (; first != last; ++ first) + { + filenames.push_back(first->Name); + } + } + } +} + void CPath::clearMap () { getInstance()->_FileContainer.clearMap(); diff --git a/code/studio/src/plugins/gui_editor/texture_chooser.cpp b/code/studio/src/plugins/gui_editor/texture_chooser.cpp index 95a081897..7545d2803 100644 --- a/code/studio/src/plugins/gui_editor/texture_chooser.cpp +++ b/code/studio/src/plugins/gui_editor/texture_chooser.cpp @@ -24,7 +24,8 @@ void TextureChooser::load() listWidget->clear(); std::vector< std::string > textures; - NLMISC::CPath::getFileList( "tga", textures ); + //NLMISC::CPath::getFileList( "tga", textures ); + NLMISC::CPath::getFileListByPath( "tga", "interfaces", textures ); std::vector< std::string >::const_iterator itr = textures.begin(); while( itr != textures.end() )