IFileSystem.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #pragma once
  5. #include "IReferenceCounted.h"
  6. #include "IFileArchive.h"
  7. namespace irr
  8. {
  9. namespace video
  10. {
  11. class IVideoDriver;
  12. } // end namespace video
  13. namespace io
  14. {
  15. class IReadFile;
  16. class IWriteFile;
  17. class IFileList;
  18. //! The FileSystem manages files and archives and provides access to them.
  19. /** It manages where files are, so that modules which use the the IO do not
  20. need to know where every file is located. A file could be in a .zip-Archive or
  21. as file on disk, using the IFileSystem makes no difference to this. */
  22. class IFileSystem : public virtual IReferenceCounted
  23. {
  24. public:
  25. //! Opens a file for read access.
  26. /** \param filename: Name of file to open.
  27. \return Pointer to the created file interface.
  28. The returned pointer should be dropped when no longer needed.
  29. See IReferenceCounted::drop() for more information. */
  30. virtual IReadFile *createAndOpenFile(const path &filename) = 0;
  31. //! Creates an IReadFile interface for accessing memory like a file.
  32. /** This allows you to use a pointer to memory where an IReadFile is requested.
  33. \param memory: A pointer to the start of the file in memory
  34. \param len: The length of the memory in bytes
  35. \param fileName: The name given to this file
  36. \param deleteMemoryWhenDropped: True if the memory should be deleted
  37. along with the IReadFile when it is dropped.
  38. \return Pointer to the created file interface.
  39. The returned pointer should be dropped when no longer needed.
  40. See IReferenceCounted::drop() for more information.
  41. */
  42. virtual IReadFile *createMemoryReadFile(const void *memory, s32 len, const path &fileName, bool deleteMemoryWhenDropped = false) = 0;
  43. //! Creates an IReadFile interface for accessing files inside files.
  44. /** This is useful e.g. for archives.
  45. \param fileName: The name given to this file
  46. \param alreadyOpenedFile: Pointer to the enclosing file
  47. \param pos: Start of the file inside alreadyOpenedFile
  48. \param areaSize: The length of the file
  49. \return A pointer to the created file interface.
  50. The returned pointer should be dropped when no longer needed.
  51. See IReferenceCounted::drop() for more information.
  52. */
  53. virtual IReadFile *createLimitReadFile(const path &fileName,
  54. IReadFile *alreadyOpenedFile, long pos, long areaSize) = 0;
  55. //! Creates an IWriteFile interface for accessing memory like a file.
  56. /** This allows you to use a pointer to memory where an IWriteFile is requested.
  57. You are responsible for allocating enough memory.
  58. \param memory: A pointer to the start of the file in memory (allocated by you)
  59. \param len: The length of the memory in bytes
  60. \param fileName: The name given to this file
  61. \param deleteMemoryWhenDropped: True if the memory should be deleted
  62. along with the IWriteFile when it is dropped.
  63. \return Pointer to the created file interface.
  64. The returned pointer should be dropped when no longer needed.
  65. See IReferenceCounted::drop() for more information.
  66. */
  67. virtual IWriteFile *createMemoryWriteFile(void *memory, s32 len, const path &fileName, bool deleteMemoryWhenDropped = false) = 0;
  68. //! Opens a file for write access.
  69. /** \param filename: Name of file to open.
  70. \param append: If the file already exist, all write operations are
  71. appended to the file.
  72. \return Pointer to the created file interface. 0 is returned, if the
  73. file could not created or opened for writing.
  74. The returned pointer should be dropped when no longer needed.
  75. See IReferenceCounted::drop() for more information. */
  76. virtual IWriteFile *createAndWriteFile(const path &filename, bool append = false) = 0;
  77. //! Adds an external archive loader to the engine.
  78. /** Use this function to add support for new archive types to the
  79. engine, for example proprietary or encrypted file storage. */
  80. virtual void addArchiveLoader(IArchiveLoader *loader) = 0;
  81. //! Gets the number of archive loaders currently added
  82. virtual u32 getArchiveLoaderCount() const = 0;
  83. //! Retrieve the given archive loader
  84. /** \param index The index of the loader to retrieve. This parameter is an 0-based
  85. array index.
  86. \return A pointer to the specified loader, 0 if the index is incorrect. */
  87. virtual IArchiveLoader *getArchiveLoader(u32 index) const = 0;
  88. //! Get the current working directory.
  89. /** \return Current working directory as a string. */
  90. virtual const path &getWorkingDirectory() = 0;
  91. //! Changes the current working directory.
  92. /** \param newDirectory: A string specifying the new working directory.
  93. The string is operating system dependent. Under Windows it has
  94. the form "<drive>:\<directory>\<sudirectory>\<..>". An example would be: "C:\Windows\"
  95. \return True if successful, otherwise false. */
  96. virtual bool changeWorkingDirectoryTo(const path &newDirectory) = 0;
  97. //! Converts a relative path to an absolute (unique) path, resolving symbolic links if required
  98. /** \param filename Possibly relative file or directory name to query.
  99. \result Absolute filename which points to the same file. */
  100. virtual path getAbsolutePath(const path &filename) const = 0;
  101. //! Get the directory a file is located in.
  102. /** \param filename: The file to get the directory from.
  103. \return String containing the directory of the file. */
  104. virtual path getFileDir(const path &filename) const = 0;
  105. //! Get the base part of a filename, i.e. the name without the directory part.
  106. /** If no directory is prefixed, the full name is returned.
  107. \param filename: The file to get the basename from
  108. \param keepExtension True if filename with extension is returned otherwise everything
  109. after the final '.' is removed as well. */
  110. virtual path getFileBasename(const path &filename, bool keepExtension = true) const = 0;
  111. //! flatten a path and file name for example: "/you/me/../." becomes "/you"
  112. virtual path &flattenFilename(path &directory, const path &root = "/") const = 0;
  113. //! Get the relative filename, relative to the given directory
  114. virtual path getRelativeFilename(const path &filename, const path &directory) const = 0;
  115. //! Creates a list of files and directories in the current working directory and returns it.
  116. /** \return a Pointer to the created IFileList is returned. After the list has been used
  117. it has to be deleted using its IFileList::drop() method.
  118. See IReferenceCounted::drop() for more information. */
  119. virtual IFileList *createFileList() = 0;
  120. //! Creates an empty filelist
  121. /** \return a Pointer to the created IFileList is returned. After the list has been used
  122. it has to be deleted using its IFileList::drop() method.
  123. See IReferenceCounted::drop() for more information. */
  124. virtual IFileList *createEmptyFileList(const io::path &path, bool ignoreCase, bool ignorePaths) = 0;
  125. //! Set the active type of file system.
  126. virtual EFileSystemType setFileListSystem(EFileSystemType listType) = 0;
  127. //! Determines if a file exists and could be opened.
  128. /** \param filename is the string identifying the file which should be tested for existence.
  129. \return True if file exists, and false if it does not exist or an error occurred. */
  130. virtual bool existFile(const path &filename) const = 0;
  131. };
  132. } // end namespace io
  133. } // end namespace irr