Don't change current working directory.
It causes issues with multithreading. Fixes #3498
This commit is contained in:
parent
b4cb7321d6
commit
ba1da58f0b
@ -304,6 +304,10 @@ public:
|
|||||||
See IReferenceCounted::drop() for more information. */
|
See IReferenceCounted::drop() for more information. */
|
||||||
virtual IFileList* createFileList() =0;
|
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
|
//! Creates an empty filelist
|
||||||
/** \return a Pointer to the created IFileList is returned. After the list has been used
|
/** \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.
|
it has to be deleted using its IFileList::drop() method.
|
||||||
|
@ -803,12 +803,18 @@ EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Creates a list of files and directories in specified directory
|
||||||
//! Creates a list of files and directories in the current working directory
|
|
||||||
IFileList* CFileSystem::createFileList()
|
IFileList* CFileSystem::createFileList()
|
||||||
{
|
{
|
||||||
CFileList* r = 0;
|
|
||||||
io::path Path = getWorkingDirectory();
|
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('\\', '/');
|
Path.replace('\\', '/');
|
||||||
if (Path.lastChar() != '/')
|
if (Path.lastChar() != '/')
|
||||||
Path.append('/');
|
Path.append('/');
|
||||||
@ -830,8 +836,10 @@ IFileList* CFileSystem::createFileList()
|
|||||||
intptr_t hFile;
|
intptr_t hFile;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
io::path searchPath = Path;
|
||||||
|
searchPath.append('*');
|
||||||
struct _tfinddata_t c_file;
|
struct _tfinddata_t c_file;
|
||||||
if( (hFile = _tfindfirst( _T("*"), &c_file )) != -1L )
|
if( (hFile = _tfindfirst( _T(searchPath.c_str()), &c_file )) != -1L )
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -121,6 +121,10 @@ public:
|
|||||||
//! and returns it.
|
//! and returns it.
|
||||||
virtual IFileList* createFileList();
|
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
|
//! Creates an empty filelist
|
||||||
virtual IFileList* createEmptyFileList(const io::path& path, bool ignoreCase, bool ignorePaths);
|
virtual IFileList* createEmptyFileList(const io::path& path, bool ignoreCase, bool ignorePaths);
|
||||||
|
|
||||||
|
@ -1324,25 +1324,17 @@ void FileManager::listFiles(std::set<std::string>& result,
|
|||||||
{
|
{
|
||||||
result.clear();
|
result.clear();
|
||||||
|
|
||||||
if(!isDirectory(dir))
|
if (!isDirectory(dir))
|
||||||
return;
|
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");
|
result.insert(make_full_path ? dir + "/" + files->getFileName(n).c_str()
|
||||||
return;
|
: files->getFileName(n).c_str());
|
||||||
}
|
|
||||||
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() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_file_system->changeWorkingDirectoryTo( previous_cwd );
|
|
||||||
files->drop();
|
files->drop();
|
||||||
} // listFiles
|
} // listFiles
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user