BsProjectLibrary.h 2.6 KB

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