1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #include "IrrCompileConfig.h"
\r
7 #include "CFileSystem.h"
\r
8 #include "IReadFile.h"
\r
9 #include "IWriteFile.h"
\r
10 #include "CZipReader.h"
\r
11 #include "CMountPointReader.h"
\r
12 #include "CPakReader.h"
\r
13 #include "CNPKReader.h"
\r
14 #include "CTarReader.h"
\r
15 #include "CWADReader.h"
\r
16 #include "CFileList.h"
\r
19 #include "CAttributes.h"
\r
20 #include "CReadFile.h"
\r
21 #include "CMemoryFile.h"
\r
22 #include "CLimitReadFile.h"
\r
23 #include "CWriteFile.h"
\r
24 #include "irrList.h"
\r
26 #if defined (__STRICT_ANSI__)
\r
27 #error Compiling with __STRICT_ANSI__ not supported. g++ does set this when compiling with -std=c++11 or -std=c++0x. Use instead -std=gnu++11 or -std=gnu++0x. Or use -U__STRICT_ANSI__ to disable strict ansi.
\r
30 #if defined (_IRR_WINDOWS_API_)
\r
31 #if !defined ( _WIN32_WCE )
\r
32 #include <direct.h> // for _chdir
\r
33 #include <io.h> // for _access
\r
36 #elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_))
\r
41 #include <sys/types.h>
\r
43 #include <sys/stat.h>
\r
45 #elif defined(_IRR_EMSCRIPTEN_PLATFORM_)
\r
55 CFileSystem::CFileSystem()
\r
58 setDebugName("CFileSystem");
\r
61 setFileListSystem(FILESYSTEM_NATIVE);
\r
62 //! reset current working directory
\r
63 getWorkingDirectory();
\r
65 #ifdef __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_
\r
66 ArchiveLoader.push_back(new CArchiveLoaderPAK(this));
\r
69 #ifdef __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
\r
70 ArchiveLoader.push_back(new CArchiveLoaderNPK(this));
\r
73 #ifdef __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_
\r
74 ArchiveLoader.push_back(new CArchiveLoaderTAR(this));
\r
77 #ifdef __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_
\r
78 ArchiveLoader.push_back(new CArchiveLoaderWAD(this));
\r
81 #ifdef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_
\r
82 ArchiveLoader.push_back(new CArchiveLoaderMount(this));
\r
85 #ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_
\r
86 ArchiveLoader.push_back(new CArchiveLoaderZIP(this));
\r
93 CFileSystem::~CFileSystem()
\r
97 for ( i=0; i < FileArchives.size(); ++i)
\r
99 FileArchives[i]->drop();
\r
102 for ( i=0; i < ArchiveLoader.size(); ++i)
\r
104 ArchiveLoader[i]->drop();
\r
109 //! opens a file for read access
\r
110 IReadFile* CFileSystem::createAndOpenFile(const io::path& filename)
\r
112 if ( filename.empty() )
\r
115 IReadFile* file = 0;
\r
118 for (i=0; i< FileArchives.size(); ++i)
\r
120 file = FileArchives[i]->createAndOpenFile(filename);
\r
125 // Create the file using an absolute path so that it matches
\r
126 // the scheme used by CNullDriver::getTexture().
\r
127 return CReadFile::createReadFile(getAbsolutePath(filename));
\r
131 //! Creates an IReadFile interface for treating memory like a file.
\r
132 IReadFile* CFileSystem::createMemoryReadFile(const void* memory, s32 len,
\r
133 const io::path& fileName, bool deleteMemoryWhenDropped)
\r
138 return new CMemoryReadFile(memory, len, fileName, deleteMemoryWhenDropped);
\r
142 //! Creates an IReadFile interface for reading files inside files
\r
143 IReadFile* CFileSystem::createLimitReadFile(const io::path& fileName,
\r
144 IReadFile* alreadyOpenedFile, long pos, long areaSize)
\r
146 if (!alreadyOpenedFile)
\r
149 return new CLimitReadFile(alreadyOpenedFile, pos, areaSize, fileName);
\r
153 //! Creates an IReadFile interface for treating memory like a file.
\r
154 IWriteFile* CFileSystem::createMemoryWriteFile(void* memory, s32 len,
\r
155 const io::path& fileName, bool deleteMemoryWhenDropped)
\r
160 return new CMemoryWriteFile(memory, len, fileName, deleteMemoryWhenDropped);
\r
164 //! Opens a file for write access.
\r
165 IWriteFile* CFileSystem::createAndWriteFile(const io::path& filename, bool append)
\r
167 return CWriteFile::createWriteFile(filename, append);
\r
171 //! Adds an external archive loader to the engine.
\r
172 void CFileSystem::addArchiveLoader(IArchiveLoader* loader)
\r
178 ArchiveLoader.push_back(loader);
\r
181 //! Returns the total number of archive loaders added.
\r
182 u32 CFileSystem::getArchiveLoaderCount() const
\r
184 return ArchiveLoader.size();
\r
187 //! Gets the archive loader by index.
\r
188 IArchiveLoader* CFileSystem::getArchiveLoader(u32 index) const
\r
190 if (index < ArchiveLoader.size())
\r
191 return ArchiveLoader[index];
\r
196 //! move the hirarchy of the filesystem. moves sourceIndex relative up or down
\r
197 bool CFileSystem::moveFileArchive(u32 sourceIndex, s32 relative)
\r
200 const s32 dest = (s32) sourceIndex + relative;
\r
201 const s32 dir = relative < 0 ? -1 : 1;
\r
202 const s32 sourceEnd = ((s32) FileArchives.size() ) - 1;
\r
205 for (s32 s = (s32) sourceIndex;s != dest; s += dir)
\r
207 if (s < 0 || s > sourceEnd || s + dir < 0 || s + dir > sourceEnd)
\r
210 t = FileArchives[s + dir];
\r
211 FileArchives[s + dir] = FileArchives[s];
\r
212 FileArchives[s] = t;
\r
219 //! Adds an archive to the file system.
\r
220 bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase,
\r
221 bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType,
\r
222 const core::stringc& password,
\r
223 IFileArchive** retArchive)
\r
225 IFileArchive* archive = 0;
\r
228 // see if archive is already added
\r
229 if (changeArchivePassword(filename, password, retArchive))
\r
234 // do we know what type it should be?
\r
235 if (archiveType == EFAT_UNKNOWN || archiveType == EFAT_FOLDER)
\r
237 // try to load archive based on file name
\r
238 for (i = ArchiveLoader.size()-1; i >=0 ; --i)
\r
240 if (ArchiveLoader[i]->isALoadableFileFormat(filename))
\r
242 archive = ArchiveLoader[i]->createArchive(filename, ignoreCase, ignorePaths);
\r
248 // try to load archive based on content
\r
251 io::IReadFile* file = createAndOpenFile(filename);
\r
254 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
257 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
260 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
271 // try to open archive based on archive loader type
\r
273 io::IReadFile* file = 0;
\r
275 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
277 if (ArchiveLoader[i]->isALoadableFileFormat(archiveType))
\r
279 // attempt to open file
\r
281 file = createAndOpenFile(filename);
\r
283 // is the file open?
\r
286 // attempt to open archive
\r
288 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
291 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
298 // couldn't open file
\r
304 // if open, close the file
\r
311 FileArchives.push_back(archive);
\r
312 if (password.size())
\r
313 archive->Password=password;
\r
315 *retArchive = archive;
\r
320 os::Printer::log("Could not create archive for", filename, ELL_ERROR);
\r
327 bool CFileSystem::changeArchivePassword(const path& filename,
\r
328 const core::stringc& password,
\r
329 IFileArchive** archive)
\r
331 for (s32 idx = 0; idx < (s32)FileArchives.size(); ++idx)
\r
333 // TODO: This should go into a path normalization method
\r
334 // We need to check for directory names with trailing slash and without
\r
335 const path absPath = getAbsolutePath(filename);
\r
336 const path arcPath = FileArchives[idx]->getFileList()->getPath();
\r
337 if ((absPath == arcPath) || ((absPath+_IRR_TEXT("/")) == arcPath))
\r
339 if (password.size())
\r
340 FileArchives[idx]->Password=password;
\r
342 *archive = FileArchives[idx];
\r
350 bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase,
\r
351 bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType,
\r
352 const core::stringc& password, IFileArchive** retArchive)
\r
354 if (!file || archiveType == EFAT_FOLDER)
\r
359 if (changeArchivePassword(file->getFileName(), password, retArchive))
\r
362 IFileArchive* archive = 0;
\r
365 if (archiveType == EFAT_UNKNOWN)
\r
367 // try to load archive based on file name
\r
368 for (i = ArchiveLoader.size()-1; i >=0 ; --i)
\r
370 if (ArchiveLoader[i]->isALoadableFileFormat(file->getFileName()))
\r
372 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
378 // try to load archive based on content
\r
381 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
384 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
387 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
396 // try to open archive based on archive loader type
\r
397 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
399 if (ArchiveLoader[i]->isALoadableFileFormat(archiveType))
\r
401 // attempt to open archive
\r
403 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
406 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
416 FileArchives.push_back(archive);
\r
417 if (password.size())
\r
418 archive->Password=password;
\r
420 *retArchive = archive;
\r
425 os::Printer::log("Could not create archive for", file->getFileName(), ELL_ERROR);
\r
433 //! Adds an archive to the file system.
\r
434 bool CFileSystem::addFileArchive(IFileArchive* archive)
\r
438 for (u32 i=0; i < FileArchives.size(); ++i)
\r
440 if (archive == FileArchives[i])
\r
445 FileArchives.push_back(archive);
\r
455 //! removes an archive from the file system.
\r
456 bool CFileSystem::removeFileArchive(u32 index)
\r
459 if (index < FileArchives.size())
\r
461 FileArchives[index]->drop();
\r
462 FileArchives.erase(index);
\r
469 //! removes an archive from the file system.
\r
470 bool CFileSystem::removeFileArchive(const io::path& filename)
\r
472 const path absPath = getAbsolutePath(filename);
\r
473 for (u32 i=0; i < FileArchives.size(); ++i)
\r
475 if (absPath == FileArchives[i]->getFileList()->getPath())
\r
476 return removeFileArchive(i);
\r
482 //! Removes an archive from the file system.
\r
483 bool CFileSystem::removeFileArchive(const IFileArchive* archive)
\r
485 for (u32 i=0; i < FileArchives.size(); ++i)
\r
487 if (archive == FileArchives[i])
\r
489 return removeFileArchive(i);
\r
496 //! gets an archive
\r
497 u32 CFileSystem::getFileArchiveCount() const
\r
499 return FileArchives.size();
\r
503 IFileArchive* CFileSystem::getFileArchive(u32 index)
\r
505 return index < getFileArchiveCount() ? FileArchives[index] : 0;
\r
509 //! Returns the string of the current working directory
\r
510 const io::path& CFileSystem::getWorkingDirectory()
\r
512 EFileSystemType type = FileSystemType;
\r
514 if (type != FILESYSTEM_NATIVE)
\r
516 type = FILESYSTEM_VIRTUAL;
\r
520 #if defined(_IRR_WINDOWS_API_)
\r
521 fschar_t tmp[_MAX_PATH];
\r
522 #if defined(_IRR_WCHAR_FILESYSTEM )
\r
523 _wgetcwd(tmp, _MAX_PATH);
\r
524 WorkingDirectory[FILESYSTEM_NATIVE] = tmp;
\r
525 WorkingDirectory[FILESYSTEM_NATIVE].replace(L'\\', L'/');
\r
527 _getcwd(tmp, _MAX_PATH);
\r
528 WorkingDirectory[FILESYSTEM_NATIVE] = tmp;
\r
529 WorkingDirectory[FILESYSTEM_NATIVE].replace('\\', '/');
\r
533 #if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
\r
535 // getting the CWD is rather complex as we do not know the size
\r
536 // so try it until the call was successful
\r
537 // Note that neither the first nor the second parameter may be 0 according to POSIX
\r
539 #if defined(_IRR_WCHAR_FILESYSTEM )
\r
541 wchar_t *tmpPath = new wchar_t[pathSize];
\r
542 while ((pathSize < (1<<16)) && !(wgetcwd(tmpPath,pathSize)))
\r
546 tmpPath = new char[pathSize];
\r
550 WorkingDirectory[FILESYSTEM_NATIVE] = tmpPath;
\r
555 char *tmpPath = new char[pathSize];
\r
556 while ((pathSize < (1<<16)) && !(getcwd(tmpPath,pathSize)))
\r
560 tmpPath = new char[pathSize];
\r
564 WorkingDirectory[FILESYSTEM_NATIVE] = tmpPath;
\r
570 WorkingDirectory[type].validate();
\r
573 return WorkingDirectory[type];
\r
577 //! Changes the current Working Directory to the given string.
\r
578 bool CFileSystem::changeWorkingDirectoryTo(const io::path& newDirectory)
\r
580 bool success=false;
\r
582 if (FileSystemType != FILESYSTEM_NATIVE)
\r
584 WorkingDirectory[FILESYSTEM_VIRTUAL] = newDirectory;
\r
585 // is this empty string constant really intended?
\r
586 flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], _IRR_TEXT(""));
\r
591 WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory;
\r
593 #if defined(_MSC_VER)
\r
594 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
595 success = (_wchdir(newDirectory.c_str()) == 0);
\r
597 success = (_chdir(newDirectory.c_str()) == 0);
\r
600 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
601 success = (_wchdir(newDirectory.c_str()) == 0);
\r
603 success = (chdir(newDirectory.c_str()) == 0);
\r
612 io::path CFileSystem::getAbsolutePath(const io::path& filename) const
\r
614 if ( filename.empty() )
\r
616 #if defined(_IRR_WINDOWS_API_)
\r
618 fschar_t fpath[_MAX_PATH];
\r
619 #if defined(_IRR_WCHAR_FILESYSTEM )
\r
620 p = _wfullpath(fpath, filename.c_str(), _MAX_PATH);
\r
621 core::stringw tmp(p);
\r
622 tmp.replace(L'\\', L'/');
\r
624 p = _fullpath(fpath, filename.c_str(), _MAX_PATH);
\r
625 core::stringc tmp(p);
\r
626 tmp.replace('\\', '/');
\r
629 #elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
\r
633 p = realpath(filename.c_str(), fpath);
\r
636 // content in fpath is unclear at this point
\r
637 if (!fpath[0]) // seems like fpath wasn't altered, use our best guess
\r
639 io::path tmp(filename);
\r
640 return flattenFilename(tmp);
\r
643 return io::path(fpath);
\r
645 if (filename[filename.size()-1]=='/')
\r
646 return io::path(p)+_IRR_TEXT("/");
\r
648 return io::path(p);
\r
650 return io::path(filename);
\r
655 //! returns the directory part of a filename, i.e. all until the first
\r
656 //! slash or backslash, excluding it. If no directory path is prefixed, a '.'
\r
658 io::path CFileSystem::getFileDir(const io::path& filename) const
\r
660 // find last forward or backslash
\r
661 s32 lastSlash = filename.findLast('/');
\r
662 const s32 lastBackSlash = filename.findLast('\\');
\r
663 lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
\r
665 if ((u32)lastSlash < filename.size())
\r
666 return filename.subString(0, lastSlash);
\r
668 return _IRR_TEXT(".");
\r
672 //! returns the base part of a filename, i.e. all except for the directory
\r
673 //! part. If no directory path is prefixed, the full name is returned.
\r
674 io::path CFileSystem::getFileBasename(const io::path& filename, bool keepExtension) const
\r
676 // find last forward or backslash
\r
677 s32 lastSlash = filename.findLast('/');
\r
678 const s32 lastBackSlash = filename.findLast('\\');
\r
679 lastSlash = core::max_(lastSlash, lastBackSlash);
\r
681 // get number of chars after last dot
\r
683 if (!keepExtension)
\r
685 // take care to search only after last slash to check only for
\r
686 // dots in the filename
\r
687 end = filename.findLast('.');
\r
688 if (end == -1 || end < lastSlash)
\r
691 end = filename.size()-end;
\r
694 if ((u32)lastSlash < filename.size())
\r
695 return filename.subString(lastSlash+1, filename.size()-lastSlash-1-end);
\r
697 return filename.subString(0, filename.size()-end);
\r
703 //! flatten a path and file name for example: "/you/me/../." becomes "/you"
\r
704 io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root) const
\r
706 directory.replace('\\', '/');
\r
707 if (directory.lastChar() != '/')
\r
708 directory.append('/');
\r
715 bool lastWasRealDir=false;
\r
717 while ((pos = directory.findNext('/', lastpos)) >= 0)
\r
719 subdir = directory.subString(lastpos, pos - lastpos + 1);
\r
721 if (subdir == _IRR_TEXT("../"))
\r
723 if (lastWasRealDir)
\r
725 deletePathFromPath(dir, 2);
\r
726 lastWasRealDir=(dir.size()!=0);
\r
730 dir.append(subdir);
\r
731 lastWasRealDir=false;
\r
734 else if (subdir == _IRR_TEXT("/"))
\r
738 else if (subdir != _IRR_TEXT("./"))
\r
740 dir.append(subdir);
\r
741 lastWasRealDir=true;
\r
751 //! Get the relative filename, relative to the given directory
\r
752 path CFileSystem::getRelativeFilename(const path& filename, const path& directory) const
\r
754 if ( filename.empty() || directory.empty() )
\r
757 io::path path1, file, ext;
\r
758 core::splitFilename(getAbsolutePath(filename), &path1, &file, &ext);
\r
759 io::path path2(getAbsolutePath(directory));
\r
760 core::list<io::path> list1, list2;
\r
761 path1.split(list1, _IRR_TEXT("/\\"), 2);
\r
762 path2.split(list2, _IRR_TEXT("/\\"), 2);
\r
764 core::list<io::path>::ConstIterator it1,it2;
\r
768 #if defined (_IRR_WINDOWS_API_)
\r
769 fschar_t partition1 = 0, partition2 = 0;
\r
770 io::path prefix1, prefix2;
\r
771 if ( it1 != list1.end() )
\r
773 if ( it2 != list2.end() )
\r
775 if ( prefix1.size() > 1 && prefix1[1] == _IRR_TEXT(':') )
\r
776 partition1 = core::locale_lower(prefix1[0]);
\r
777 if ( prefix2.size() > 1 && prefix2[1] == _IRR_TEXT(':') )
\r
778 partition2 = core::locale_lower(prefix2[0]);
\r
780 // must have the same prefix or we can't resolve it to a relative filename
\r
781 if ( partition1 != partition2 )
\r
788 for (; i<list1.size() && i<list2.size()
\r
789 #if defined (_IRR_WINDOWS_API_)
\r
790 && (io::path(*it1).make_lower()==io::path(*it2).make_lower())
\r
799 path1=_IRR_TEXT("");
\r
800 for (; i<list2.size(); ++i)
\r
801 path1 += _IRR_TEXT("../");
\r
802 while (it1 != list1.end())
\r
805 path1 += _IRR_TEXT('/');
\r
810 path1 += _IRR_TEXT('.');
\r
817 //! Sets the current file systen type
\r
818 EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
\r
820 EFileSystemType current = FileSystemType;
\r
821 FileSystemType = listType;
\r
826 //! Creates a list of files and directories in the current working directory
\r
827 IFileList* CFileSystem::createFileList()
\r
830 io::path Path = getWorkingDirectory();
\r
831 Path.replace('\\', '/');
\r
832 if (!Path.empty() && Path.lastChar() != '/')
\r
835 //! Construct from native filesystem
\r
836 if (FileSystemType == FILESYSTEM_NATIVE)
\r
838 // --------------------------------------------
\r
839 //! Windows version
\r
840 #ifdef _IRR_WINDOWS_API_
\r
841 #if !defined ( _WIN32_WCE )
\r
843 r = new CFileList(Path, true, false);
\r
845 // TODO: Should be unified once mingw adapts the proper types
\r
846 #if defined(__GNUC__)
\r
847 long hFile; //mingw return type declaration
\r
852 struct _tfinddata_t c_file;
\r
853 if( (hFile = _tfindfirst( _T("*"), &c_file )) != -1L )
\r
857 r->addItem(Path + c_file.name, 0, c_file.size, (_A_SUBDIR & c_file.attrib) != 0, 0);
\r
859 while( _tfindnext( hFile, &c_file ) == 0 );
\r
861 _findclose( hFile );
\r
866 //entry.Name = "E:\\";
\r
867 //entry.isDirectory = true;
\r
868 //Files.push_back(entry);
\r
871 // --------------------------------------------
\r
873 #if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
\r
876 r = new CFileList(Path, false, false);
\r
878 r->addItem(Path + _IRR_TEXT(".."), 0, 0, true, 0);
\r
880 //! We use the POSIX compliant methods instead of scandir
\r
881 DIR* dirHandle=opendir(Path.c_str());
\r
884 struct dirent *dirEntry;
\r
885 while ((dirEntry=readdir(dirHandle)))
\r
888 bool isDirectory = false;
\r
890 if((strcmp(dirEntry->d_name, ".")==0) ||
\r
891 (strcmp(dirEntry->d_name, "..")==0))
\r
896 if (stat(dirEntry->d_name, &buf)==0)
\r
898 size = buf.st_size;
\r
899 isDirectory = S_ISDIR(buf.st_mode);
\r
901 #if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__)
\r
902 // only available on some systems
\r
905 isDirectory = dirEntry->d_type == DT_DIR;
\r
909 r->addItem(Path + dirEntry->d_name, 0, size, isDirectory, 0);
\r
911 closedir(dirHandle);
\r
917 //! create file list for the virtual filesystem
\r
918 r = new CFileList(Path, false, false);
\r
920 //! add relative navigation
\r
925 r->addItem(Path + _IRR_TEXT("."), 0, 0, true, 0);
\r
928 r->addItem(Path + _IRR_TEXT(".."), 0, 0, true, 0);
\r
931 for (u32 i=0; i < FileArchives.size(); ++i)
\r
933 const IFileList *merge = FileArchives[i]->getFileList();
\r
935 for (u32 j=0; j < merge->getFileCount(); ++j)
\r
937 if (core::isInSameDirectory(Path, merge->getFullFileName(j)) == 0)
\r
939 r->addItem(merge->getFullFileName(j), merge->getFileOffset(j), merge->getFileSize(j), merge->isDirectory(j), 0);
\r
950 //! Creates an empty filelist
\r
951 IFileList* CFileSystem::createEmptyFileList(const io::path& path, bool ignoreCase, bool ignorePaths)
\r
953 return new CFileList(path, ignoreCase, ignorePaths);
\r
957 //! determines if a file exists and would be able to be opened.
\r
958 bool CFileSystem::existFile(const io::path& filename) const
\r
960 for (u32 i=0; i < FileArchives.size(); ++i)
\r
961 if (FileArchives[i]->getFileList()->findFile(filename)!=-1)
\r
964 #if defined(_MSC_VER)
\r
965 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
966 return (_waccess(filename.c_str(), 0) != -1);
\r
968 return (_access(filename.c_str(), 0) != -1);
\r
970 #elif defined(F_OK)
\r
971 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
972 return (_waccess(filename.c_str(), F_OK) != -1);
\r
974 return (access(filename.c_str(), F_OK) != -1);
\r
977 return (access(filename.c_str(), 0) != -1);
\r
982 //! creates a filesystem which is able to open files from the ordinary file system,
\r
983 //! and out of zipfiles, which are able to be added to the filesystem.
\r
984 IFileSystem* createFileSystem()
\r
986 return new CFileSystem();
\r
990 //! Creates a new empty collection of attributes, usable for serialization and more.
\r
991 IAttributes* CFileSystem::createEmptyAttributes(video::IVideoDriver* driver)
\r
993 return new CAttributes(driver);
\r
997 } // end namespace irr
\r
998 } // end namespace io
\r