CFileSystem.h 6.0 KB

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