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 "CFileList.h"
\r
15 #include "CAttributes.h"
\r
16 #include "CReadFile.h"
\r
17 #include "CMemoryFile.h"
\r
18 #include "CLimitReadFile.h"
\r
19 #include "CWriteFile.h"
\r
20 #include "irrList.h"
\r
22 #if defined (__STRICT_ANSI__)
\r
23 #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
26 #if defined (_IRR_WINDOWS_API_)
\r
27 #if !defined ( _WIN32_WCE )
\r
28 #include <direct.h> // for _chdir
\r
29 #include <io.h> // for _access
\r
32 #elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_))
\r
37 #include <sys/types.h>
\r
39 #include <sys/stat.h>
\r
41 #elif defined(_IRR_EMSCRIPTEN_PLATFORM_)
\r
51 CFileSystem::CFileSystem()
\r
54 setDebugName("CFileSystem");
\r
57 setFileListSystem(FILESYSTEM_NATIVE);
\r
58 //! reset current working directory
\r
59 getWorkingDirectory();
\r
61 #ifdef __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_
\r
62 ArchiveLoader.push_back(new CArchiveLoaderPAK(this));
\r
65 #ifdef __IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_
\r
66 ArchiveLoader.push_back(new CArchiveLoaderNPK(this));
\r
69 #ifdef __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_
\r
70 ArchiveLoader.push_back(new CArchiveLoaderTAR(this));
\r
73 #ifdef __IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_
\r
74 ArchiveLoader.push_back(new CArchiveLoaderWAD(this));
\r
77 #ifdef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_
\r
78 ArchiveLoader.push_back(new CArchiveLoaderMount(this));
\r
81 #ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_
\r
82 ArchiveLoader.push_back(new CArchiveLoaderZIP(this));
\r
89 CFileSystem::~CFileSystem()
\r
93 for ( i=0; i < FileArchives.size(); ++i)
\r
95 FileArchives[i]->drop();
\r
98 for ( i=0; i < ArchiveLoader.size(); ++i)
\r
100 ArchiveLoader[i]->drop();
\r
105 //! opens a file for read access
\r
106 IReadFile* CFileSystem::createAndOpenFile(const io::path& filename)
\r
108 if ( filename.empty() )
\r
111 IReadFile* file = 0;
\r
114 for (i=0; i< FileArchives.size(); ++i)
\r
116 file = FileArchives[i]->createAndOpenFile(filename);
\r
121 // Create the file using an absolute path so that it matches
\r
122 // the scheme used by CNullDriver::getTexture().
\r
123 return CReadFile::createReadFile(getAbsolutePath(filename));
\r
127 //! Creates an IReadFile interface for treating memory like a file.
\r
128 IReadFile* CFileSystem::createMemoryReadFile(const void* memory, s32 len,
\r
129 const io::path& fileName, bool deleteMemoryWhenDropped)
\r
134 return new CMemoryReadFile(memory, len, fileName, deleteMemoryWhenDropped);
\r
138 //! Creates an IReadFile interface for reading files inside files
\r
139 IReadFile* CFileSystem::createLimitReadFile(const io::path& fileName,
\r
140 IReadFile* alreadyOpenedFile, long pos, long areaSize)
\r
142 if (!alreadyOpenedFile)
\r
145 return new CLimitReadFile(alreadyOpenedFile, pos, areaSize, fileName);
\r
149 //! Creates an IReadFile interface for treating memory like a file.
\r
150 IWriteFile* CFileSystem::createMemoryWriteFile(void* memory, s32 len,
\r
151 const io::path& fileName, bool deleteMemoryWhenDropped)
\r
156 return new CMemoryWriteFile(memory, len, fileName, deleteMemoryWhenDropped);
\r
160 //! Opens a file for write access.
\r
161 IWriteFile* CFileSystem::createAndWriteFile(const io::path& filename, bool append)
\r
163 return CWriteFile::createWriteFile(filename, append);
\r
167 //! Adds an external archive loader to the engine.
\r
168 void CFileSystem::addArchiveLoader(IArchiveLoader* loader)
\r
174 ArchiveLoader.push_back(loader);
\r
177 //! Returns the total number of archive loaders added.
\r
178 u32 CFileSystem::getArchiveLoaderCount() const
\r
180 return ArchiveLoader.size();
\r
183 //! Gets the archive loader by index.
\r
184 IArchiveLoader* CFileSystem::getArchiveLoader(u32 index) const
\r
186 if (index < ArchiveLoader.size())
\r
187 return ArchiveLoader[index];
\r
192 //! move the hirarchy of the filesystem. moves sourceIndex relative up or down
\r
193 bool CFileSystem::moveFileArchive(u32 sourceIndex, s32 relative)
\r
196 const s32 dest = (s32) sourceIndex + relative;
\r
197 const s32 dir = relative < 0 ? -1 : 1;
\r
198 const s32 sourceEnd = ((s32) FileArchives.size() ) - 1;
\r
201 for (s32 s = (s32) sourceIndex;s != dest; s += dir)
\r
203 if (s < 0 || s > sourceEnd || s + dir < 0 || s + dir > sourceEnd)
\r
206 t = FileArchives[s + dir];
\r
207 FileArchives[s + dir] = FileArchives[s];
\r
208 FileArchives[s] = t;
\r
215 //! Adds an archive to the file system.
\r
216 bool CFileSystem::addFileArchive(const io::path& filename, bool ignoreCase,
\r
217 bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType,
\r
218 const core::stringc& password,
\r
219 IFileArchive** retArchive)
\r
221 IFileArchive* archive = 0;
\r
224 // see if archive is already added
\r
225 if (changeArchivePassword(filename, password, retArchive))
\r
230 // do we know what type it should be?
\r
231 if (archiveType == EFAT_UNKNOWN || archiveType == EFAT_FOLDER)
\r
233 // try to load archive based on file name
\r
234 for (i = ArchiveLoader.size()-1; i >=0 ; --i)
\r
236 if (ArchiveLoader[i]->isALoadableFileFormat(filename))
\r
238 archive = ArchiveLoader[i]->createArchive(filename, ignoreCase, ignorePaths);
\r
244 // try to load archive based on content
\r
247 io::IReadFile* file = createAndOpenFile(filename);
\r
250 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
253 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
256 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
267 // try to open archive based on archive loader type
\r
269 io::IReadFile* file = 0;
\r
271 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
273 if (ArchiveLoader[i]->isALoadableFileFormat(archiveType))
\r
275 // attempt to open file
\r
277 file = createAndOpenFile(filename);
\r
279 // is the file open?
\r
282 // attempt to open archive
\r
284 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
287 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
294 // couldn't open file
\r
300 // if open, close the file
\r
307 FileArchives.push_back(archive);
\r
308 if (password.size())
\r
309 archive->Password=password;
\r
311 *retArchive = archive;
\r
316 os::Printer::log("Could not create archive for", filename, ELL_ERROR);
\r
323 bool CFileSystem::changeArchivePassword(const path& filename,
\r
324 const core::stringc& password,
\r
325 IFileArchive** archive)
\r
327 for (s32 idx = 0; idx < (s32)FileArchives.size(); ++idx)
\r
329 // TODO: This should go into a path normalization method
\r
330 // We need to check for directory names with trailing slash and without
\r
331 const path absPath = getAbsolutePath(filename);
\r
332 const path arcPath = FileArchives[idx]->getFileList()->getPath();
\r
333 if ((absPath == arcPath) || ((absPath+_IRR_TEXT("/")) == arcPath))
\r
335 if (password.size())
\r
336 FileArchives[idx]->Password=password;
\r
338 *archive = FileArchives[idx];
\r
346 bool CFileSystem::addFileArchive(IReadFile* file, bool ignoreCase,
\r
347 bool ignorePaths, E_FILE_ARCHIVE_TYPE archiveType,
\r
348 const core::stringc& password, IFileArchive** retArchive)
\r
350 if (!file || archiveType == EFAT_FOLDER)
\r
355 if (changeArchivePassword(file->getFileName(), password, retArchive))
\r
358 IFileArchive* archive = 0;
\r
361 if (archiveType == EFAT_UNKNOWN)
\r
363 // try to load archive based on file name
\r
364 for (i = ArchiveLoader.size()-1; i >=0 ; --i)
\r
366 if (ArchiveLoader[i]->isALoadableFileFormat(file->getFileName()))
\r
368 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
374 // try to load archive based on content
\r
377 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
380 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
383 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
392 // try to open archive based on archive loader type
\r
393 for (i = ArchiveLoader.size()-1; i >= 0; --i)
\r
395 if (ArchiveLoader[i]->isALoadableFileFormat(archiveType))
\r
397 // attempt to open archive
\r
399 if (ArchiveLoader[i]->isALoadableFileFormat(file))
\r
402 archive = ArchiveLoader[i]->createArchive(file, ignoreCase, ignorePaths);
\r
412 FileArchives.push_back(archive);
\r
413 if (password.size())
\r
414 archive->Password=password;
\r
416 *retArchive = archive;
\r
421 os::Printer::log("Could not create archive for", file->getFileName(), ELL_ERROR);
\r
429 //! Adds an archive to the file system.
\r
430 bool CFileSystem::addFileArchive(IFileArchive* archive)
\r
434 for (u32 i=0; i < FileArchives.size(); ++i)
\r
436 if (archive == FileArchives[i])
\r
441 FileArchives.push_back(archive);
\r
451 //! removes an archive from the file system.
\r
452 bool CFileSystem::removeFileArchive(u32 index)
\r
455 if (index < FileArchives.size())
\r
457 FileArchives[index]->drop();
\r
458 FileArchives.erase(index);
\r
465 //! removes an archive from the file system.
\r
466 bool CFileSystem::removeFileArchive(const io::path& filename)
\r
468 const path absPath = getAbsolutePath(filename);
\r
469 for (u32 i=0; i < FileArchives.size(); ++i)
\r
471 if (absPath == FileArchives[i]->getFileList()->getPath())
\r
472 return removeFileArchive(i);
\r
478 //! Removes an archive from the file system.
\r
479 bool CFileSystem::removeFileArchive(const IFileArchive* archive)
\r
481 for (u32 i=0; i < FileArchives.size(); ++i)
\r
483 if (archive == FileArchives[i])
\r
485 return removeFileArchive(i);
\r
492 //! gets an archive
\r
493 u32 CFileSystem::getFileArchiveCount() const
\r
495 return FileArchives.size();
\r
499 IFileArchive* CFileSystem::getFileArchive(u32 index)
\r
501 return index < getFileArchiveCount() ? FileArchives[index] : 0;
\r
505 //! Returns the string of the current working directory
\r
506 const io::path& CFileSystem::getWorkingDirectory()
\r
508 EFileSystemType type = FileSystemType;
\r
510 if (type != FILESYSTEM_NATIVE)
\r
512 type = FILESYSTEM_VIRTUAL;
\r
516 #if defined(_IRR_WINDOWS_API_)
\r
517 fschar_t tmp[_MAX_PATH];
\r
518 #if defined(_IRR_WCHAR_FILESYSTEM )
\r
519 _wgetcwd(tmp, _MAX_PATH);
\r
520 WorkingDirectory[FILESYSTEM_NATIVE] = tmp;
\r
521 WorkingDirectory[FILESYSTEM_NATIVE].replace(L'\\', L'/');
\r
523 _getcwd(tmp, _MAX_PATH);
\r
524 WorkingDirectory[FILESYSTEM_NATIVE] = tmp;
\r
525 WorkingDirectory[FILESYSTEM_NATIVE].replace('\\', '/');
\r
529 #if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
\r
531 // getting the CWD is rather complex as we do not know the size
\r
532 // so try it until the call was successful
\r
533 // Note that neither the first nor the second parameter may be 0 according to POSIX
\r
535 #if defined(_IRR_WCHAR_FILESYSTEM )
\r
537 wchar_t *tmpPath = new wchar_t[pathSize];
\r
538 while ((pathSize < (1<<16)) && !(wgetcwd(tmpPath,pathSize)))
\r
542 tmpPath = new char[pathSize];
\r
546 WorkingDirectory[FILESYSTEM_NATIVE] = tmpPath;
\r
551 char *tmpPath = new char[pathSize];
\r
552 while ((pathSize < (1<<16)) && !(getcwd(tmpPath,pathSize)))
\r
556 tmpPath = new char[pathSize];
\r
560 WorkingDirectory[FILESYSTEM_NATIVE] = tmpPath;
\r
566 WorkingDirectory[type].validate();
\r
569 return WorkingDirectory[type];
\r
573 //! Changes the current Working Directory to the given string.
\r
574 bool CFileSystem::changeWorkingDirectoryTo(const io::path& newDirectory)
\r
576 bool success=false;
\r
578 if (FileSystemType != FILESYSTEM_NATIVE)
\r
580 WorkingDirectory[FILESYSTEM_VIRTUAL] = newDirectory;
\r
581 // is this empty string constant really intended?
\r
582 flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], _IRR_TEXT(""));
\r
587 WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory;
\r
589 #if defined(_MSC_VER)
\r
590 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
591 success = (_wchdir(newDirectory.c_str()) == 0);
\r
593 success = (_chdir(newDirectory.c_str()) == 0);
\r
596 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
597 success = (_wchdir(newDirectory.c_str()) == 0);
\r
599 success = (chdir(newDirectory.c_str()) == 0);
\r
608 io::path CFileSystem::getAbsolutePath(const io::path& filename) const
\r
610 if ( filename.empty() )
\r
612 #if defined(_IRR_WINDOWS_API_)
\r
614 fschar_t fpath[_MAX_PATH];
\r
615 #if defined(_IRR_WCHAR_FILESYSTEM )
\r
616 p = _wfullpath(fpath, filename.c_str(), _MAX_PATH);
\r
617 core::stringw tmp(p);
\r
618 tmp.replace(L'\\', L'/');
\r
620 p = _fullpath(fpath, filename.c_str(), _MAX_PATH);
\r
621 core::stringc tmp(p);
\r
622 tmp.replace('\\', '/');
\r
625 #elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
\r
629 p = realpath(filename.c_str(), fpath);
\r
632 // content in fpath is unclear at this point
\r
633 if (!fpath[0]) // seems like fpath wasn't altered, use our best guess
\r
635 io::path tmp(filename);
\r
636 return flattenFilename(tmp);
\r
639 return io::path(fpath);
\r
641 if (filename[filename.size()-1]=='/')
\r
642 return io::path(p)+_IRR_TEXT("/");
\r
644 return io::path(p);
\r
646 return io::path(filename);
\r
651 //! returns the directory part of a filename, i.e. all until the first
\r
652 //! slash or backslash, excluding it. If no directory path is prefixed, a '.'
\r
654 io::path CFileSystem::getFileDir(const io::path& filename) const
\r
656 // find last forward or backslash
\r
657 s32 lastSlash = filename.findLast('/');
\r
658 const s32 lastBackSlash = filename.findLast('\\');
\r
659 lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash;
\r
661 if ((u32)lastSlash < filename.size())
\r
662 return filename.subString(0, lastSlash);
\r
664 return _IRR_TEXT(".");
\r
668 //! returns the base part of a filename, i.e. all except for the directory
\r
669 //! part. If no directory path is prefixed, the full name is returned.
\r
670 io::path CFileSystem::getFileBasename(const io::path& filename, bool keepExtension) const
\r
672 // find last forward or backslash
\r
673 s32 lastSlash = filename.findLast('/');
\r
674 const s32 lastBackSlash = filename.findLast('\\');
\r
675 lastSlash = core::max_(lastSlash, lastBackSlash);
\r
677 // get number of chars after last dot
\r
679 if (!keepExtension)
\r
681 // take care to search only after last slash to check only for
\r
682 // dots in the filename
\r
683 end = filename.findLast('.');
\r
684 if (end == -1 || end < lastSlash)
\r
687 end = filename.size()-end;
\r
690 if ((u32)lastSlash < filename.size())
\r
691 return filename.subString(lastSlash+1, filename.size()-lastSlash-1-end);
\r
693 return filename.subString(0, filename.size()-end);
\r
699 //! flatten a path and file name for example: "/you/me/../." becomes "/you"
\r
700 io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root) const
\r
702 directory.replace('\\', '/');
\r
703 if (directory.lastChar() != '/')
\r
704 directory.append('/');
\r
711 bool lastWasRealDir=false;
\r
713 while ((pos = directory.findNext('/', lastpos)) >= 0)
\r
715 subdir = directory.subString(lastpos, pos - lastpos + 1);
\r
717 if (subdir == _IRR_TEXT("../"))
\r
719 if (lastWasRealDir)
\r
721 deletePathFromPath(dir, 2);
\r
722 lastWasRealDir=(dir.size()!=0);
\r
726 dir.append(subdir);
\r
727 lastWasRealDir=false;
\r
730 else if (subdir == _IRR_TEXT("/"))
\r
734 else if (subdir != _IRR_TEXT("./"))
\r
736 dir.append(subdir);
\r
737 lastWasRealDir=true;
\r
747 //! Get the relative filename, relative to the given directory
\r
748 path CFileSystem::getRelativeFilename(const path& filename, const path& directory) const
\r
750 if ( filename.empty() || directory.empty() )
\r
753 io::path path1, file, ext;
\r
754 core::splitFilename(getAbsolutePath(filename), &path1, &file, &ext);
\r
755 io::path path2(getAbsolutePath(directory));
\r
756 core::list<io::path> list1, list2;
\r
757 path1.split(list1, _IRR_TEXT("/\\"), 2);
\r
758 path2.split(list2, _IRR_TEXT("/\\"), 2);
\r
760 core::list<io::path>::ConstIterator it1,it2;
\r
764 #if defined (_IRR_WINDOWS_API_)
\r
765 fschar_t partition1 = 0, partition2 = 0;
\r
766 io::path prefix1, prefix2;
\r
767 if ( it1 != list1.end() )
\r
769 if ( it2 != list2.end() )
\r
771 if ( prefix1.size() > 1 && prefix1[1] == _IRR_TEXT(':') )
\r
772 partition1 = core::locale_lower(prefix1[0]);
\r
773 if ( prefix2.size() > 1 && prefix2[1] == _IRR_TEXT(':') )
\r
774 partition2 = core::locale_lower(prefix2[0]);
\r
776 // must have the same prefix or we can't resolve it to a relative filename
\r
777 if ( partition1 != partition2 )
\r
784 for (; i<list1.size() && i<list2.size()
\r
785 #if defined (_IRR_WINDOWS_API_)
\r
786 && (io::path(*it1).make_lower()==io::path(*it2).make_lower())
\r
795 path1=_IRR_TEXT("");
\r
796 for (; i<list2.size(); ++i)
\r
797 path1 += _IRR_TEXT("../");
\r
798 while (it1 != list1.end())
\r
801 path1 += _IRR_TEXT('/');
\r
806 path1 += _IRR_TEXT('.');
\r
813 //! Sets the current file systen type
\r
814 EFileSystemType CFileSystem::setFileListSystem(EFileSystemType listType)
\r
816 EFileSystemType current = FileSystemType;
\r
817 FileSystemType = listType;
\r
822 //! Creates a list of files and directories in the current working directory
\r
823 IFileList* CFileSystem::createFileList()
\r
826 io::path Path = getWorkingDirectory();
\r
827 Path.replace('\\', '/');
\r
828 if (!Path.empty() && Path.lastChar() != '/')
\r
831 //! Construct from native filesystem
\r
832 if (FileSystemType == FILESYSTEM_NATIVE)
\r
834 // --------------------------------------------
\r
835 //! Windows version
\r
836 #ifdef _IRR_WINDOWS_API_
\r
837 #if !defined ( _WIN32_WCE )
\r
839 r = new CFileList(Path, true, false);
\r
841 // TODO: Should be unified once mingw adapts the proper types
\r
842 #if defined(__GNUC__)
\r
843 long hFile; //mingw return type declaration
\r
848 struct _tfinddata_t c_file;
\r
849 if( (hFile = _tfindfirst( _T("*"), &c_file )) != -1L )
\r
853 r->addItem(Path + c_file.name, 0, c_file.size, (_A_SUBDIR & c_file.attrib) != 0, 0);
\r
855 while( _tfindnext( hFile, &c_file ) == 0 );
\r
857 _findclose( hFile );
\r
862 //entry.Name = "E:\\";
\r
863 //entry.isDirectory = true;
\r
864 //Files.push_back(entry);
\r
867 // --------------------------------------------
\r
869 #if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))
\r
872 r = new CFileList(Path, false, false);
\r
874 r->addItem(Path + _IRR_TEXT(".."), 0, 0, true, 0);
\r
876 //! We use the POSIX compliant methods instead of scandir
\r
877 DIR* dirHandle=opendir(Path.c_str());
\r
880 struct dirent *dirEntry;
\r
881 while ((dirEntry=readdir(dirHandle)))
\r
884 bool isDirectory = false;
\r
886 if((strcmp(dirEntry->d_name, ".")==0) ||
\r
887 (strcmp(dirEntry->d_name, "..")==0))
\r
892 if (stat(dirEntry->d_name, &buf)==0)
\r
894 size = buf.st_size;
\r
895 isDirectory = S_ISDIR(buf.st_mode);
\r
897 #if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__)
\r
898 // only available on some systems
\r
901 isDirectory = dirEntry->d_type == DT_DIR;
\r
905 r->addItem(Path + dirEntry->d_name, 0, size, isDirectory, 0);
\r
907 closedir(dirHandle);
\r
913 //! create file list for the virtual filesystem
\r
914 r = new CFileList(Path, false, false);
\r
916 //! add relative navigation
\r
921 r->addItem(Path + _IRR_TEXT("."), 0, 0, true, 0);
\r
924 r->addItem(Path + _IRR_TEXT(".."), 0, 0, true, 0);
\r
927 for (u32 i=0; i < FileArchives.size(); ++i)
\r
929 const IFileList *merge = FileArchives[i]->getFileList();
\r
931 for (u32 j=0; j < merge->getFileCount(); ++j)
\r
933 if (core::isInSameDirectory(Path, merge->getFullFileName(j)) == 0)
\r
935 r->addItem(merge->getFullFileName(j), merge->getFileOffset(j), merge->getFileSize(j), merge->isDirectory(j), 0);
\r
946 //! Creates an empty filelist
\r
947 IFileList* CFileSystem::createEmptyFileList(const io::path& path, bool ignoreCase, bool ignorePaths)
\r
949 return new CFileList(path, ignoreCase, ignorePaths);
\r
953 //! determines if a file exists and would be able to be opened.
\r
954 bool CFileSystem::existFile(const io::path& filename) const
\r
956 for (u32 i=0; i < FileArchives.size(); ++i)
\r
957 if (FileArchives[i]->getFileList()->findFile(filename)!=-1)
\r
960 #if defined(_MSC_VER)
\r
961 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
962 return (_waccess(filename.c_str(), 0) != -1);
\r
964 return (_access(filename.c_str(), 0) != -1);
\r
966 #elif defined(F_OK)
\r
967 #if defined(_IRR_WCHAR_FILESYSTEM)
\r
968 return (_waccess(filename.c_str(), F_OK) != -1);
\r
970 return (access(filename.c_str(), F_OK) != -1);
\r
973 return (access(filename.c_str(), 0) != -1);
\r
978 //! creates a filesystem which is able to open files from the ordinary file system,
\r
979 //! and out of zipfiles, which are able to be added to the filesystem.
\r
980 IFileSystem* createFileSystem()
\r
982 return new CFileSystem();
\r
986 //! Creates a new empty collection of attributes, usable for serialization and more.
\r
987 IAttributes* CFileSystem::createEmptyAttributes(video::IVideoDriver* driver)
\r
989 return new CAttributes(driver);
\r
993 } // end namespace irr
\r
994 } // end namespace io
\r