IFileArchive.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt/ Thomas Alten
  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 "IReadFile.h"
  6. #include "IFileList.h"
  7. namespace irr
  8. {
  9. namespace io
  10. {
  11. //! FileSystemType: which filesystem should be used for e.g. browsing
  12. enum EFileSystemType
  13. {
  14. FILESYSTEM_NATIVE = 0, // Native OS FileSystem
  15. FILESYSTEM_VIRTUAL // Virtual FileSystem
  16. };
  17. //! Contains the different types of archives
  18. enum E_FILE_ARCHIVE_TYPE
  19. {
  20. //! A PKZIP archive
  21. EFAT_ZIP = MAKE_IRR_ID('Z', 'I', 'P', 0),
  22. //! A gzip archive
  23. EFAT_GZIP = MAKE_IRR_ID('g', 'z', 'i', 'p'),
  24. //! An Android asset file archive
  25. EFAT_ANDROID_ASSET = MAKE_IRR_ID('A', 'S', 'S', 'E'),
  26. //! The type of this archive is unknown
  27. EFAT_UNKNOWN = MAKE_IRR_ID('u', 'n', 'k', 'n')
  28. };
  29. //! The FileArchive manages archives and provides access to files inside them.
  30. class IFileArchive : public virtual IReferenceCounted
  31. {
  32. public:
  33. //! Opens a file based on its name
  34. /** Creates and returns a new IReadFile for a file in the archive.
  35. \param filename The file to open
  36. \return Returns A pointer to the created file on success,
  37. or 0 on failure. */
  38. virtual IReadFile *createAndOpenFile(const path &filename) = 0;
  39. //! Opens a file based on its position in the file list.
  40. /** Creates and returns
  41. \param index The zero based index of the file.
  42. \return Returns a pointer to the created file on success, or 0 on failure. */
  43. virtual IReadFile *createAndOpenFile(u32 index) = 0;
  44. //! Returns the complete file tree
  45. /** \return Returns the complete directory tree for the archive,
  46. including all files and folders */
  47. virtual const IFileList *getFileList() const = 0;
  48. //! get the archive type
  49. virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_UNKNOWN; }
  50. //! return the name (id) of the file Archive
  51. virtual const io::path &getArchiveName() const = 0;
  52. //! Add a directory in the archive and all it's files to the FileList
  53. /** Only needed for file-archives which have no information about their own
  54. directory structure. In that case the user must add directories manually.
  55. Currently this is necessary for archives of type EFAT_ANDROID_ASSET.
  56. The root-path itself is already set by the engine.
  57. If directories are not added manually opening files might still work,
  58. but checks if file exists will fail.
  59. */
  60. virtual void addDirectoryToFileList(const io::path &filename) {}
  61. //! An optionally used password string
  62. /** This variable is publicly accessible from the interface in order to
  63. avoid single access patterns to this place, and hence allow some more
  64. obscurity.
  65. */
  66. core::stringc Password;
  67. };
  68. //! Class which is able to create an archive from a file.
  69. /** If you want the Irrlicht Engine be able to load archives of
  70. currently unsupported file formats (e.g .wad), then implement
  71. this and add your new Archive loader with
  72. IFileSystem::addArchiveLoader() to the engine. */
  73. class IArchiveLoader : public virtual IReferenceCounted
  74. {
  75. public:
  76. //! Check if the file might be loaded by this class
  77. /** Check based on the file extension (e.g. ".zip")
  78. \param filename Name of file to check.
  79. \return True if file seems to be loadable. */
  80. virtual bool isALoadableFileFormat(const path &filename) const = 0;
  81. //! Check if the file might be loaded by this class
  82. /** This check may look into the file.
  83. \param file File handle to check.
  84. \return True if file seems to be loadable. */
  85. virtual bool isALoadableFileFormat(io::IReadFile *file) const = 0;
  86. //! Check to see if the loader can create archives of this type.
  87. /** Check based on the archive type.
  88. \param fileType The archive type to check.
  89. \return True if the archive loader supports this type, false if not */
  90. virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const = 0;
  91. //! Creates an archive from the filename
  92. /** \param filename File to use.
  93. \param ignoreCase Searching is performed without regarding the case
  94. \param ignorePaths Files are searched for without checking for the directories
  95. \return Pointer to newly created archive, or 0 upon error. */
  96. virtual IFileArchive *createArchive(const path &filename, bool ignoreCase, bool ignorePaths) const = 0;
  97. //! Creates an archive from the file
  98. /** \param file File handle to use.
  99. \param ignoreCase Searching is performed without regarding the case
  100. \param ignorePaths Files are searched for without checking for the directories
  101. \return Pointer to newly created archive, or 0 upon error. */
  102. virtual IFileArchive *createArchive(io::IReadFile *file, bool ignoreCase, bool ignorePaths) const = 0;
  103. };
  104. } // end namespace io
  105. } // end namespace irr