Don't change current working directory.

It causes issues with multithreading.
Fixes #3498
This commit is contained in:
Deve 2018-10-09 21:42:16 +02:00
parent b4cb7321d6
commit ba1da58f0b
4 changed files with 25 additions and 17 deletions

View File

@ -304,6 +304,10 @@ public:
See IReferenceCounted::drop() for more information. */
virtual IFileList* createFileList() =0;
//! Creates a list of files and directories in specified directory
//! and returns it.
virtual IFileList* createFileList(const io::path& directory) =0;
//! Creates an empty filelist
/** \return a Pointer to the created IFileList is returned. After the list has been used
it has to be deleted using its IFileList::drop() method.

View File

@ -803,12 +803,18 @@ EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
return current;
}
//! Creates a list of files and directories in the current working directory
//! Creates a list of files and directories in specified directory
IFileList* CFileSystem::createFileList()
{
CFileList* r = 0;
io::path Path = getWorkingDirectory();
return createFileList(Path);
}
//! Creates a list of files and directories in the current working directory
IFileList* CFileSystem::createFileList(const io::path& directory)
{
CFileList* r = 0;
io::path Path = directory;
Path.replace('\\', '/');
if (Path.lastChar() != '/')
Path.append('/');
@ -830,8 +836,10 @@ IFileList* CFileSystem::createFileList()
intptr_t hFile;
#endif
io::path searchPath = Path;
searchPath.append('*');
struct _tfinddata_t c_file;
if( (hFile = _tfindfirst( _T("*"), &c_file )) != -1L )
if( (hFile = _tfindfirst( _T(searchPath.c_str()), &c_file )) != -1L )
{
do
{

View File

@ -121,6 +121,10 @@ public:
//! and returns it.
virtual IFileList* createFileList();
//! Creates a list of files and directories in specified directory
//! and returns it.
virtual IFileList* createFileList(const io::path& directory);
//! Creates an empty filelist
virtual IFileList* createEmptyFileList(const io::path& path, bool ignoreCase, bool ignorePaths);

View File

@ -1324,25 +1324,17 @@ void FileManager::listFiles(std::set<std::string>& result,
{
result.clear();
if(!isDirectory(dir))
if (!isDirectory(dir))
return;
io::path previous_cwd = m_file_system->getWorkingDirectory();
irr::io::IFileList* files = m_file_system->createFileList(dir.c_str());
if(!m_file_system->changeWorkingDirectoryTo( dir.c_str() ))
for (int n = 0; n < (int)files->getFileCount(); n++)
{
Log::error("FileManager", "listFiles : Could not change CWD!\n");
return;
}
irr::io::IFileList* files = m_file_system->createFileList();
for(int n=0; n<(int)files->getFileCount(); n++)
{
result.insert(make_full_path ? dir+"/"+ files->getFileName(n).c_str()
: files->getFileName(n).c_str() );
result.insert(make_full_path ? dir + "/" + files->getFileName(n).c_str()
: files->getFileName(n).c_str());
}
m_file_system->changeWorkingDirectoryTo( previous_cwd );
files->drop();
} // listFiles