BsProjectLibrary.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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() {}
  20. LibraryEntry(const CM::WString& path, const CM::WString& name, DirectoryEntry* parent, LibraryEntryType type);
  21. LibraryEntryType type;
  22. CM::WString path;
  23. CM::WString elementName;
  24. DirectoryEntry* parent;
  25. };
  26. struct ResourceEntry : public LibraryEntry
  27. {
  28. ResourceEntry() {}
  29. ResourceEntry(const CM::WString& path, const CM::WString& name, DirectoryEntry* parent);
  30. ResourceMetaPtr meta;
  31. std::time_t lastUpdateTime;
  32. };
  33. struct DirectoryEntry : public LibraryEntry
  34. {
  35. DirectoryEntry() {}
  36. DirectoryEntry(const CM::WString& path, const CM::WString& name, DirectoryEntry* parent);
  37. CM::Vector<LibraryEntry*>::type mChildren;
  38. };
  39. public:
  40. ProjectLibrary();
  41. ~ProjectLibrary();
  42. void update();
  43. void checkForModifications(const CM::WString& fullPath);
  44. const LibraryEntry* getRootEntry() const { return mRootEntry; }
  45. LibraryEntry* findEntry(const CM::WString& fullPath) const;
  46. void moveEntry(const CM::WString& oldPath, const CM::WString& newPath);
  47. void deleteEntry(const CM::WString& path);
  48. boost::signal<void(const CM::WString&)> onEntryRemoved;
  49. boost::signal<void(const CM::WString&)> onEntryAdded;
  50. private:
  51. static const CM::WString INTERNAL_RESOURCES_DIR;
  52. static const CM::WString LIBRARY_ENTRIES_FILENAME;
  53. static const CM::WString RESOURCE_MANIFEST_FILENAME;
  54. DirectoryEntry* mRootEntry;
  55. CM::FolderMonitor* mMonitor;
  56. void save();
  57. void load();
  58. ResourceEntry* addResourceInternal(DirectoryEntry* parent, const CM::WString& filePath);
  59. DirectoryEntry* addDirectoryInternal(DirectoryEntry* parent, const CM::WString& dirPath);
  60. void deleteResourceInternal(ResourceEntry* resource);
  61. void deleteDirectoryInternal(DirectoryEntry* directory);
  62. void reimportResourceInternal(ResourceEntry* resource);
  63. void createInternalParentHierarchy(const CM::WString& fullPath, DirectoryEntry** newHierarchyRoot, DirectoryEntry** newHierarchyLeaf);
  64. bool isUpToDate(ResourceEntry* resource) const;
  65. CM::WString getMetaPath(const CM::WString& path) const;
  66. bool isMeta(const CM::WString& fullPath) const;
  67. void onMonitorFileModified(const CM::WString& path);
  68. };
  69. }