CFileList.h 4.2 KB

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