IFileArchive.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #ifndef IRR_I_FILE_ARCHIVE_H_INCLUDED
  5. #define IRR_I_FILE_ARCHIVE_H_INCLUDED
  6. #include "IReadFile.h"
  7. #include "IFileList.h"
  8. namespace irr
  9. {
  10. namespace io
  11. {
  12. //! FileSystemType: which filesystem should be used for e.g. browsing
  13. enum EFileSystemType
  14. {
  15. FILESYSTEM_NATIVE = 0, // Native OS FileSystem
  16. FILESYSTEM_VIRTUAL // Virtual FileSystem
  17. };
  18. //! Contains the different types of archives
  19. enum E_FILE_ARCHIVE_TYPE
  20. {
  21. //! A PKZIP archive
  22. EFAT_ZIP = MAKE_IRR_ID('Z','I','P', 0),
  23. //! A gzip archive
  24. EFAT_GZIP = MAKE_IRR_ID('g','z','i','p'),
  25. //! A virtual directory
  26. EFAT_FOLDER = MAKE_IRR_ID('f','l','d','r'),
  27. //! An ID Software PAK archive
  28. EFAT_PAK = MAKE_IRR_ID('P','A','K', 0),
  29. //! A Nebula Device archive
  30. EFAT_NPK = MAKE_IRR_ID('N','P','K', 0),
  31. //! A Tape ARchive
  32. EFAT_TAR = MAKE_IRR_ID('T','A','R', 0),
  33. //! A wad Archive, Quake2, Halflife
  34. EFAT_WAD = MAKE_IRR_ID('W','A','D', 0),
  35. //! The type of this archive is unknown
  36. EFAT_UNKNOWN = MAKE_IRR_ID('u','n','k','n')
  37. };
  38. //! The FileArchive manages archives and provides access to files inside them.
  39. class IFileArchive : public virtual IReferenceCounted
  40. {
  41. public:
  42. //! Opens a file based on its name
  43. /** Creates and returns a new IReadFile for a file in the archive.
  44. \param filename The file to open
  45. \return Returns A pointer to the created file on success,
  46. or 0 on failure. */
  47. virtual IReadFile* createAndOpenFile(const path& filename) =0;
  48. //! Opens a file based on its position in the file list.
  49. /** Creates and returns
  50. \param index The zero based index of the file.
  51. \return Returns a pointer to the created file on success, or 0 on failure. */
  52. virtual IReadFile* createAndOpenFile(u32 index) =0;
  53. //! Returns the complete file tree
  54. /** \return Returns the complete directory tree for the archive,
  55. including all files and folders */
  56. virtual const IFileList* getFileList() const =0;
  57. //! get the archive type
  58. virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_UNKNOWN; }
  59. //! return the name (id) of the file Archive
  60. virtual const io::path& getArchiveName() const =0;
  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
  106. #endif