IFileArchive.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. //! The type of this archive is unknown
  23. EFAT_UNKNOWN = MAKE_IRR_ID('u', 'n', 'k', 'n')
  24. };
  25. //! The FileArchive manages archives and provides access to files inside them.
  26. class IFileArchive : public virtual IReferenceCounted
  27. {
  28. public:
  29. //! Opens a file based on its name
  30. /** Creates and returns a new IReadFile for a file in the archive.
  31. \param filename The file to open
  32. \return Returns A pointer to the created file on success,
  33. or 0 on failure. */
  34. virtual IReadFile *createAndOpenFile(const path &filename) = 0;
  35. //! Opens a file based on its position in the file list.
  36. /** Creates and returns
  37. \param index The zero based index of the file.
  38. \return Returns a pointer to the created file on success, or 0 on failure. */
  39. virtual IReadFile *createAndOpenFile(u32 index) = 0;
  40. //! Returns the complete file tree
  41. /** \return Returns the complete directory tree for the archive,
  42. including all files and folders */
  43. virtual const IFileList *getFileList() const = 0;
  44. //! get the archive type
  45. virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_UNKNOWN; }
  46. //! return the name (id) of the file Archive
  47. virtual const io::path &getArchiveName() const = 0;
  48. //! Add a directory in the archive and all it's files to the FileList
  49. /** Only needed for file-archives which have no information about their own
  50. directory structure. In that case the user must add directories manually.
  51. Currently this is necessary for archives of type EFAT_ANDROID_ASSET.
  52. The root-path itself is already set by the engine.
  53. If directories are not added manually opening files might still work,
  54. but checks if file exists will fail.
  55. */
  56. virtual void addDirectoryToFileList(const io::path &filename) {}
  57. };
  58. //! Class which is able to create an archive from a file.
  59. /** If you want the Irrlicht Engine be able to load archives of
  60. currently unsupported file formats (e.g .wad), then implement
  61. this and add your new Archive loader with
  62. IFileSystem::addArchiveLoader() to the engine. */
  63. class IArchiveLoader : public virtual IReferenceCounted
  64. {
  65. public:
  66. //! Check if the file might be loaded by this class
  67. /** Check based on the file extension (e.g. ".zip")
  68. \param filename Name of file to check.
  69. \return True if file seems to be loadable. */
  70. virtual bool isALoadableFileFormat(const path &filename) const = 0;
  71. //! Check if the file might be loaded by this class
  72. /** This check may look into the file.
  73. \param file File handle to check.
  74. \return True if file seems to be loadable. */
  75. virtual bool isALoadableFileFormat(io::IReadFile *file) const = 0;
  76. //! Check to see if the loader can create archives of this type.
  77. /** Check based on the archive type.
  78. \param fileType The archive type to check.
  79. \return True if the archive loader supports this type, false if not */
  80. virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const = 0;
  81. //! Creates an archive from the filename
  82. /** \param filename File to use.
  83. \param ignoreCase Searching is performed without regarding the case
  84. \param ignorePaths Files are searched for without checking for the directories
  85. \return Pointer to newly created archive, or 0 upon error. */
  86. virtual IFileArchive *createArchive(const path &filename, bool ignoreCase, bool ignorePaths) const = 0;
  87. //! Creates an archive from the file
  88. /** \param file File handle to use.
  89. \param ignoreCase Searching is performed without regarding the case
  90. \param ignorePaths Files are searched for without checking for the directories
  91. \return Pointer to newly created archive, or 0 upon error. */
  92. virtual IFileArchive *createArchive(io::IReadFile *file, bool ignoreCase, bool ignorePaths) const = 0;
  93. };
  94. } // end namespace io
  95. } // end namespace irr