1 // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 // This file is part of the "Irrlicht Engine". 3 // For conditions of distribution and use, see copyright notice in irrlicht.h 4 5 #ifndef __C_FILE_SYSTEM_H_INCLUDED__ 6 #define __C_FILE_SYSTEM_H_INCLUDED__ 7 8 #include "IFileSystem.h" 9 #include "irrArray.h" 10 11 namespace irr 12 { 13 namespace io 14 { 15 16 class CZipReader; 17 class CPakReader; 18 class CMountPointReader; 19 20 /*! 21 FileSystem which uses normal files and one zipfile 22 */ 23 class CFileSystem : public IFileSystem 24 { 25 public: 26 27 //! constructor 28 CFileSystem(); 29 30 //! destructor 31 virtual ~CFileSystem(); 32 33 //! opens a file for read access 34 virtual IReadFile* createAndOpenFile(const io::path& filename); 35 36 //! Creates an IReadFile interface for accessing memory like a file. 37 virtual IReadFile* createMemoryReadFile(void* memory, s32 len, const io::path& fileName, bool deleteMemoryWhenDropped = false); 38 39 //! Creates an IReadFile interface for accessing files inside files 40 virtual IReadFile* createLimitReadFile(const io::path& fileName, IReadFile* alreadyOpenedFile, long pos, long areaSize); 41 42 //! Creates an IWriteFile interface for accessing memory like a file. 43 virtual IWriteFile* createMemoryWriteFile(void* memory, s32 len, const io::path& fileName, bool deleteMemoryWhenDropped=false); 44 45 //! Opens a file for write access. 46 virtual IWriteFile* createAndWriteFile(const io::path& filename, bool append=false); 47 48 //! Adds an archive to the file system. 49 virtual bool addFileArchive(const io::path& filename, 50 bool ignoreCase = true, bool ignorePaths = true, 51 E_FILE_ARCHIVE_TYPE archiveType = EFAT_UNKNOWN, 52 const core::stringc& password="", 53 IFileArchive** retArchive = 0); 54 55 //! Adds an archive to the file system. 56 virtual bool addFileArchive(IReadFile* file, bool ignoreCase=true, 57 bool ignorePaths=true, 58 E_FILE_ARCHIVE_TYPE archiveType=EFAT_UNKNOWN, 59 const core::stringc& password="", 60 IFileArchive** retArchive = 0); 61 62 //! Adds an archive to the file system. 63 virtual bool addFileArchive(IFileArchive* archive); 64 65 //! move the hirarchy of the filesystem. moves sourceIndex relative up or down 66 virtual bool moveFileArchive(u32 sourceIndex, s32 relative); 67 68 //! Adds an external archive loader to the engine. 69 virtual void addArchiveLoader(IArchiveLoader* loader); 70 71 //! Returns the total number of archive loaders added. 72 virtual u32 getArchiveLoaderCount() const; 73 74 //! Gets the archive loader by index. 75 virtual IArchiveLoader* getArchiveLoader(u32 index) const; 76 77 //! gets the file archive count 78 virtual u32 getFileArchiveCount() const; 79 80 //! gets an archive 81 virtual IFileArchive* getFileArchive(u32 index); 82 83 virtual void removeAllFileArchives(); 84 85 //! removes an archive from the file system. 86 virtual bool removeFileArchive(u32 index); 87 88 //! removes an archive from the file system. 89 virtual bool removeFileArchive(const io::path& filename); 90 91 //! Removes an archive from the file system. 92 virtual bool removeFileArchive(const IFileArchive* archive); 93 94 //! Returns the string of the current working directory 95 virtual const io::path& getWorkingDirectory(); 96 97 //! Changes the current Working Directory to the string given. 98 //! The string is operating system dependent. Under Windows it will look 99 //! like this: "drive:\directory\sudirectory\" 100 virtual bool changeWorkingDirectoryTo(const io::path& newDirectory); 101 102 //! Converts a relative path to an absolute (unique) path, resolving symbolic links 103 virtual io::path getAbsolutePath(const io::path& filename) const; 104 105 //! Returns the directory a file is located in. 106 /** \param filename: The file to get the directory from */ 107 virtual io::path getFileDir(const io::path& filename) const; 108 109 //! Returns the base part of a filename, i.e. the name without the directory 110 //! part. If no directory is prefixed, the full name is returned. 111 /** \param filename: The file to get the basename from */ 112 virtual io::path getFileBasename(const io::path& filename, bool keepExtension=true) const; 113 114 //! flatten a path and file name for example: "/you/me/../." becomes "/you" 115 virtual io::path& flattenFilename( io::path& directory, const io::path& root = "/" ) const; 116 117 //! Get the relative filename, relative to the given directory 118 virtual path getRelativeFilename(const path& filename, const path& directory) const; 119 120 virtual EFileSystemType setFileListSystem(EFileSystemType listType); 121 122 //! Creates a list of files and directories in the current working directory 123 //! and returns it. 124 virtual IFileList* createFileList(); 125 126 //! Creates a list of files and directories in specified directory 127 //! and returns it. 128 virtual IFileList* createFileList(const io::path& directory); 129 130 //! Creates an empty filelist 131 virtual IFileList* createEmptyFileList(const io::path& path, bool ignoreCase, bool ignorePaths); 132 133 //! determines if a file exists and would be able to be opened. 134 virtual bool existFile(const io::path& filename) const; 135 136 //! Creates a XML Reader from a file. 137 virtual IXMLReader* createXMLReader(const io::path& filename); 138 139 //! Creates a XML Reader from a file. 140 virtual IXMLReader* createXMLReader(IReadFile* file); 141 142 //! Creates a XML Reader from a file. 143 virtual IXMLReaderUTF8* createXMLReaderUTF8(const io::path& filename); 144 145 //! Creates a XML Reader from a file. 146 virtual IXMLReaderUTF8* createXMLReaderUTF8(IReadFile* file); 147 148 //! Creates a XML Writer from a file. 149 virtual IXMLWriter* createXMLWriter(const io::path& filename); 150 151 //! Creates a XML Writer from a file. 152 virtual IXMLWriter* createXMLWriter(IWriteFile* file); 153 154 //! Creates a new empty collection of attributes, usable for serialization and more. 155 virtual IAttributes* createEmptyAttributes(video::IVideoDriver* driver); 156 157 private: 158 159 // don't expose, needs refactoring 160 bool changeArchivePassword(const path& filename, 161 const core::stringc& password, 162 IFileArchive** archive = 0); 163 164 //! Currently used FileSystemType 165 EFileSystemType FileSystemType; 166 //! WorkingDirectory for Native and Virtual filesystems 167 io::path WorkingDirectory [2]; 168 //! currently attached ArchiveLoaders 169 core::array<IArchiveLoader*> ArchiveLoader; 170 //! currently attached Archives 171 core::array<IFileArchive*> FileArchives; 172 }; 173 174 175 } // end namespace irr 176 } // end namespace io 177 178 #endif 179 180