2
0

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