CFileList.h 4.0 KB

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