BsProjectLibrary.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "CmModule.h"
  4. namespace BansheeEditor
  5. {
  6. class ProjectLibrary : public CM::Module<ProjectLibrary>
  7. {
  8. public:
  9. struct LibraryEntry;
  10. struct ResourceEntry;
  11. struct DirectoryEntry;
  12. enum class LibraryEntryType
  13. {
  14. File,
  15. Directory
  16. };
  17. struct LibraryEntry
  18. {
  19. LibraryEntry(const CM::WString& path, const CM::WString& name, DirectoryEntry* parent, LibraryEntryType type);
  20. LibraryEntryType type;
  21. CM::WString path;
  22. CM::WString elementName;
  23. DirectoryEntry* parent;
  24. };
  25. struct ResourceEntry : public LibraryEntry
  26. {
  27. ResourceEntry(const CM::WString& path, const CM::WString& name, DirectoryEntry* parent);
  28. ResourceMetaPtr meta;
  29. std::time_t lastUpdateTime;
  30. };
  31. struct DirectoryEntry : public LibraryEntry
  32. {
  33. DirectoryEntry(const CM::WString& path, const CM::WString& name, DirectoryEntry* parent);
  34. CM::Vector<LibraryEntry*>::type mChildren;
  35. };
  36. public:
  37. ProjectLibrary();
  38. ~ProjectLibrary();
  39. void update();
  40. void checkForModifications(const CM::WString& fullPath);
  41. const LibraryEntry* getRootEntry() const { return mRootEntry; }
  42. LibraryEntry* findEntry(const CM::WString& fullPath) const;
  43. void moveEntry(const CM::WString& oldPath, const CM::WString& newPath);
  44. void deleteEntry(const CM::WString& path);
  45. boost::signal<void(const CM::WString&)> onEntryRemoved;
  46. boost::signal<void(const CM::WString&)> onEntryAdded;
  47. private:
  48. static const CM::WString INTERNAL_RESOURCES_DIR;
  49. DirectoryEntry* mRootEntry;
  50. CM::FolderMonitor* mMonitor;
  51. ResourceEntry* addResourceInternal(DirectoryEntry* parent, const CM::WString& filePath);
  52. DirectoryEntry* addDirectoryInternal(DirectoryEntry* parent, const CM::WString& dirPath);
  53. void deleteResourceInternal(ResourceEntry* resource);
  54. void deleteDirectoryInternal(DirectoryEntry* directory);
  55. void reimportResourceInternal(ResourceEntry* resource);
  56. void createInternalParentHierarchy(const CM::WString& fullPath, DirectoryEntry** newHierarchyRoot, DirectoryEntry** newHierarchyLeaf);
  57. bool isUpToDate(ResourceEntry* resource) const;
  58. CM::WString getMetaPath(const CM::WString& path) const;
  59. bool isMeta(const CM::WString& fullPath) const;
  60. void onMonitorFileModified(const CM::WString& path);
  61. };
  62. }