BsProjectLibrary.h 2.3 KB

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