CFileList.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef __C_FILE_LIST_H_INCLUDED__
  5. #define __C_FILE_LIST_H_INCLUDED__
  6. #include "IFileList.h"
  7. #include "irrString.h"
  8. #include "irrArray.h"
  9. namespace irr
  10. {
  11. namespace io
  12. {
  13. //! An entry in a list of files, can be a folder or a file.
  14. struct SFileListEntry
  15. {
  16. //! The name of the file
  17. /** If this is a file or folder in the virtual filesystem and the archive
  18. was created with the ignoreCase flag then the file name will be lower case. */
  19. io::path Name;
  20. //! The name of the file including the path
  21. /** If this is a file or folder in the virtual filesystem and the archive was
  22. created with the ignoreDirs flag then it will be the same as Name. */
  23. io::path FullName;
  24. //! The size of the file in bytes
  25. u32 Size;
  26. //! The ID of the file in an archive
  27. /** This is used to link the FileList entry to extra info held about this
  28. file in an archive, which can hold things like data offset and CRC. */
  29. u32 ID;
  30. //! FileOffset inside an archive
  31. u32 Offset;
  32. //! True if this is a folder, false if not.
  33. bool IsDirectory;
  34. //! The == operator is provided so that CFileList can slowly search the list!
  35. bool operator ==(const struct SFileListEntry& other) const
  36. {
  37. if (IsDirectory != other.IsDirectory)
  38. return false;
  39. return FullName.equals_ignore_case(other.FullName);
  40. }
  41. //! The < operator is provided so that CFileList can sort and quickly search the list.
  42. bool operator <(const struct SFileListEntry& other) const
  43. {
  44. if (IsDirectory != other.IsDirectory)
  45. return IsDirectory;
  46. return FullName.lower_ignore_case(other.FullName);
  47. }
  48. };
  49. //! Implementation of a file list
  50. class CFileList : public IFileList
  51. {
  52. public:
  53. // CFileList methods
  54. //! Constructor
  55. /** \param path The path of this file archive */
  56. CFileList(const io::path& path, bool ignoreCase, bool ignorePaths);
  57. //! Destructor
  58. virtual ~CFileList();
  59. //! Add as a file or folder to the list
  60. /** \param fullPath The file name including path, up to the root of the file list.
  61. \param isDirectory True if this is a directory rather than a file.
  62. \param offset The offset where the file is stored in an archive
  63. \param size The size of the file in bytes.
  64. \param id The ID of the file in the archive which owns it */
  65. virtual u32 addItem(const io::path& fullPath, u32 offset, u32 size, bool isDirectory, u32 id=0);
  66. //! Sorts the file list. You should call this after adding any items to the file list
  67. virtual void sort();
  68. //! Returns the amount of files in the filelist.
  69. virtual u32 getFileCount() const;
  70. //! Gets the name of a file in the list, based on an index.
  71. virtual const io::path& getFileName(u32 index) const;
  72. //! Gets the full name of a file in the list, path included, based on an index.
  73. virtual const io::path& getFullFileName(u32 index) const;
  74. //! Returns the ID of a file in the file list, based on an index.
  75. virtual u32 getID(u32 index) const;
  76. //! Returns true if the file is a directory
  77. virtual bool isDirectory(u32 index) const;
  78. //! Returns the size of a file
  79. virtual u32 getFileSize(u32 index) const;
  80. //! Returns the offest of a file
  81. virtual u32 getFileOffset(u32 index) const;
  82. //! Searches for a file or folder within the list, returns the index
  83. virtual s32 findFile(const io::path& filename, bool isFolder) const;
  84. //! Returns the base path of the file list
  85. virtual const io::path& getPath() const;
  86. protected:
  87. //! Ignore paths when adding or searching for files
  88. bool IgnorePaths;
  89. //! Ignore case when adding or searching for files
  90. bool IgnoreCase;
  91. //! Path to the file list
  92. io::path Path;
  93. //! List of files
  94. core::array<SFileListEntry> Files;
  95. };
  96. } // end namespace irr
  97. } // end namespace io
  98. #endif