|
@@ -9,7 +9,6 @@
|
|
|
#include "BsImporter.h"
|
|
#include "BsImporter.h"
|
|
|
#include "BsImportOptions.h"
|
|
#include "BsImportOptions.h"
|
|
|
#include "BsFileSerializer.h"
|
|
#include "BsFileSerializer.h"
|
|
|
-#include "BsFolderMonitor.h"
|
|
|
|
|
#include "BsDebug.h"
|
|
#include "BsDebug.h"
|
|
|
#include "BsProjectLibraryEntries.h"
|
|
#include "BsProjectLibraryEntries.h"
|
|
|
#include "BsResource.h"
|
|
#include "BsResource.h"
|
|
@@ -35,11 +34,11 @@ namespace BansheeEngine
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
ProjectLibrary::ResourceEntry::ResourceEntry()
|
|
ProjectLibrary::ResourceEntry::ResourceEntry()
|
|
|
- :lastUpdateTime(0)
|
|
|
|
|
|
|
+ : lastUpdateTime(0)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
ProjectLibrary::ResourceEntry::ResourceEntry(const Path& path, const WString& name, DirectoryEntry* parent)
|
|
ProjectLibrary::ResourceEntry::ResourceEntry(const Path& path, const WString& name, DirectoryEntry* parent)
|
|
|
- :LibraryEntry(path, name, parent, LibraryEntryType::File), lastUpdateTime(0)
|
|
|
|
|
|
|
+ : LibraryEntry(path, name, parent, LibraryEntryType::File), lastUpdateTime(0)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
ProjectLibrary::DirectoryEntry::DirectoryEntry()
|
|
ProjectLibrary::DirectoryEntry::DirectoryEntry()
|
|
@@ -54,15 +53,6 @@ namespace BansheeEngine
|
|
|
{
|
|
{
|
|
|
mResourcesFolder = mProjectFolder;
|
|
mResourcesFolder = mProjectFolder;
|
|
|
mResourcesFolder.append(RESOURCES_DIR);
|
|
mResourcesFolder.append(RESOURCES_DIR);
|
|
|
- mMonitor = bs_new<FolderMonitor>();
|
|
|
|
|
-
|
|
|
|
|
- FolderChange folderChanges = (FolderChange)((UINT32)FolderChange::FileName | (UINT32)FolderChange::DirName |
|
|
|
|
|
- (UINT32)FolderChange::Creation | (UINT32)FolderChange::LastWrite);
|
|
|
|
|
- mMonitor->startMonitor(mResourcesFolder, true, folderChanges);
|
|
|
|
|
-
|
|
|
|
|
- mMonitor->onAdded.connect(std::bind(&ProjectLibrary::onMonitorFileModified, this, _1));
|
|
|
|
|
- mMonitor->onRemoved.connect(std::bind(&ProjectLibrary::onMonitorFileModified, this, _1));
|
|
|
|
|
- mMonitor->onModified.connect(std::bind(&ProjectLibrary::onMonitorFileModified, this, _1));
|
|
|
|
|
|
|
|
|
|
load();
|
|
load();
|
|
|
|
|
|
|
@@ -70,25 +60,18 @@ namespace BansheeEngine
|
|
|
mResourceManifest = ResourceManifest::create("ProjectLibrary");
|
|
mResourceManifest = ResourceManifest::create("ProjectLibrary");
|
|
|
|
|
|
|
|
gResources().registerResourceManifest(mResourceManifest);
|
|
gResources().registerResourceManifest(mResourceManifest);
|
|
|
-
|
|
|
|
|
- checkForModifications(mResourcesFolder);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ProjectLibrary::~ProjectLibrary()
|
|
ProjectLibrary::~ProjectLibrary()
|
|
|
{
|
|
{
|
|
|
save();
|
|
save();
|
|
|
|
|
|
|
|
- mMonitor->stopMonitorAll();
|
|
|
|
|
- bs_delete(mMonitor);
|
|
|
|
|
-
|
|
|
|
|
if(mRootEntry != nullptr)
|
|
if(mRootEntry != nullptr)
|
|
|
deleteDirectoryInternal(mRootEntry);
|
|
deleteDirectoryInternal(mRootEntry);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ProjectLibrary::update()
|
|
void ProjectLibrary::update()
|
|
|
{
|
|
{
|
|
|
- mMonitor->_update();
|
|
|
|
|
-
|
|
|
|
|
while (!mReimportQueue.empty())
|
|
while (!mReimportQueue.empty())
|
|
|
{
|
|
{
|
|
|
Path toReimport = *mReimportQueue.begin();
|
|
Path toReimport = *mReimportQueue.begin();
|
|
@@ -105,6 +88,12 @@ namespace BansheeEngine
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ProjectLibrary::checkForModifications(const Path& fullPath)
|
|
void ProjectLibrary::checkForModifications(const Path& fullPath)
|
|
|
|
|
+ {
|
|
|
|
|
+ Vector<Path> dirtyResources;
|
|
|
|
|
+ checkForModifications(fullPath, true, dirtyResources);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void ProjectLibrary::checkForModifications(const Path& fullPath, bool import, Vector<Path>& dirtyResources)
|
|
|
{
|
|
{
|
|
|
if (!mResourcesFolder.includes(fullPath))
|
|
if (!mResourcesFolder.includes(fullPath))
|
|
|
return; // Folder not part of our resources path, so no modifications
|
|
return; // Folder not part of our resources path, so no modifications
|
|
@@ -131,26 +120,32 @@ namespace BansheeEngine
|
|
|
|
|
|
|
|
if(FileSystem::isFile(pathToSearch))
|
|
if(FileSystem::isFile(pathToSearch))
|
|
|
{
|
|
{
|
|
|
- addResourceInternal(entryParent, pathToSearch);
|
|
|
|
|
|
|
+ if (import)
|
|
|
|
|
+ addResourceInternal(entryParent, pathToSearch);
|
|
|
|
|
+
|
|
|
|
|
+ dirtyResources.push_back(pathToSearch);
|
|
|
}
|
|
}
|
|
|
else if(FileSystem::isDirectory(pathToSearch))
|
|
else if(FileSystem::isDirectory(pathToSearch))
|
|
|
{
|
|
{
|
|
|
addDirectoryInternal(entryParent, pathToSearch);
|
|
addDirectoryInternal(entryParent, pathToSearch);
|
|
|
|
|
|
|
|
- if(newHierarchyParent == nullptr)
|
|
|
|
|
- checkForModifications(pathToSearch);
|
|
|
|
|
|
|
+ checkForModifications(pathToSearch);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if(newHierarchyParent != nullptr)
|
|
|
|
|
- checkForModifications(newHierarchyParent->path);
|
|
|
|
|
}
|
|
}
|
|
|
else if(entry->type == LibraryEntryType::File)
|
|
else if(entry->type == LibraryEntryType::File)
|
|
|
{
|
|
{
|
|
|
if(FileSystem::isFile(entry->path))
|
|
if(FileSystem::isFile(entry->path))
|
|
|
{
|
|
{
|
|
|
ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
|
|
ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
|
|
|
- reimportResourceInternal(resEntry);
|
|
|
|
|
- queueDependantForReimport(resEntry);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (import)
|
|
|
|
|
+ {
|
|
|
|
|
+ reimportResourceInternal(resEntry);
|
|
|
|
|
+ queueDependantForReimport(resEntry);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!isUpToDate(resEntry))
|
|
|
|
|
+ dirtyResources.push_back(entry->path);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -220,8 +215,14 @@ namespace BansheeEngine
|
|
|
|
|
|
|
|
if(existingEntry != nullptr)
|
|
if(existingEntry != nullptr)
|
|
|
{
|
|
{
|
|
|
- reimportResourceInternal(existingEntry);
|
|
|
|
|
- queueDependantForReimport(existingEntry);
|
|
|
|
|
|
|
+ if (import)
|
|
|
|
|
+ {
|
|
|
|
|
+ reimportResourceInternal(existingEntry);
|
|
|
|
|
+ queueDependantForReimport(existingEntry);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!isUpToDate(existingEntry))
|
|
|
|
|
+ dirtyResources.push_back(existingEntry->path);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -733,9 +734,6 @@ namespace BansheeEngine
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
doOnEntryAdded(oldEntry);
|
|
doOnEntryAdded(oldEntry);
|
|
|
-
|
|
|
|
|
- if(newHierarchyParent != nullptr)
|
|
|
|
|
- checkForModifications(newHierarchyParent->path);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else // Moving from outside of the Resources folder (likely adding a new resource)
|
|
else // Moving from outside of the Resources folder (likely adding a new resource)
|
|
@@ -871,6 +869,19 @@ namespace BansheeEngine
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ HResource ProjectLibrary::load(const Path& path)
|
|
|
|
|
+ {
|
|
|
|
|
+ LibraryEntry* entry = findEntry(path);
|
|
|
|
|
+
|
|
|
|
|
+ if (entry == nullptr || entry->type == LibraryEntryType::Directory)
|
|
|
|
|
+ return HResource();
|
|
|
|
|
+
|
|
|
|
|
+ ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
|
|
|
|
|
+ String resUUID = resEntry->meta->getUUID();
|
|
|
|
|
+
|
|
|
|
|
+ return Resources::instance().loadFromUUID(resUUID);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void ProjectLibrary::createInternalParentHierarchy(const Path& fullPath, DirectoryEntry** newHierarchyRoot, DirectoryEntry** newHierarchyLeaf)
|
|
void ProjectLibrary::createInternalParentHierarchy(const Path& fullPath, DirectoryEntry** newHierarchyRoot, DirectoryEntry** newHierarchyLeaf)
|
|
|
{
|
|
{
|
|
|
Path parentPath = fullPath;
|
|
Path parentPath = fullPath;
|
|
@@ -928,19 +939,6 @@ namespace BansheeEngine
|
|
|
return fullPath.getWExtension() == L".meta";
|
|
return fullPath.getWExtension() == L".meta";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void ProjectLibrary::onMonitorFileModified(const Path& path)
|
|
|
|
|
- {
|
|
|
|
|
- if(!isMeta(path))
|
|
|
|
|
- checkForModifications(path);
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- Path resourcePath = path;
|
|
|
|
|
- resourcePath.setExtension(L"");
|
|
|
|
|
-
|
|
|
|
|
- checkForModifications(resourcePath);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
void ProjectLibrary::save()
|
|
void ProjectLibrary::save()
|
|
|
{
|
|
{
|
|
|
std::shared_ptr<ProjectLibraryEntries> libEntries = ProjectLibraryEntries::create(*mRootEntry);
|
|
std::shared_ptr<ProjectLibraryEntries> libEntries = ProjectLibraryEntries::create(*mRootEntry);
|
|
@@ -999,26 +997,37 @@ namespace BansheeEngine
|
|
|
if(child->type == LibraryEntryType::File)
|
|
if(child->type == LibraryEntryType::File)
|
|
|
{
|
|
{
|
|
|
ResourceEntry* resEntry = static_cast<ResourceEntry*>(child);
|
|
ResourceEntry* resEntry = static_cast<ResourceEntry*>(child);
|
|
|
|
|
+ bool doAddDependencies = true;
|
|
|
|
|
|
|
|
- if(resEntry->meta == nullptr)
|
|
|
|
|
|
|
+ if (FileSystem::isFile(resEntry->path))
|
|
|
{
|
|
{
|
|
|
- Path metaPath = resEntry->path;
|
|
|
|
|
- metaPath.setFilename(metaPath.getWFilename() + L".meta");
|
|
|
|
|
-
|
|
|
|
|
- if(FileSystem::isFile(metaPath))
|
|
|
|
|
|
|
+ if (resEntry->meta == nullptr)
|
|
|
{
|
|
{
|
|
|
- FileDecoder fs(metaPath);
|
|
|
|
|
- std::shared_ptr<IReflectable> loadedMeta = fs.decode();
|
|
|
|
|
|
|
+ Path metaPath = resEntry->path;
|
|
|
|
|
+ metaPath.setFilename(metaPath.getWFilename() + L".meta");
|
|
|
|
|
+
|
|
|
|
|
+ if (FileSystem::isFile(metaPath))
|
|
|
|
|
+ {
|
|
|
|
|
+ FileDecoder fs(metaPath);
|
|
|
|
|
+ std::shared_ptr<IReflectable> loadedMeta = fs.decode();
|
|
|
|
|
|
|
|
- if(loadedMeta != nullptr && loadedMeta->isDerivedFrom(ProjectResourceMeta::getRTTIStatic()))
|
|
|
|
|
|
|
+ if (loadedMeta != nullptr && loadedMeta->isDerivedFrom(ProjectResourceMeta::getRTTIStatic()))
|
|
|
|
|
+ {
|
|
|
|
|
+ ProjectResourceMetaPtr resourceMeta = std::static_pointer_cast<ProjectResourceMeta>(loadedMeta);
|
|
|
|
|
+ resEntry->meta = resourceMeta;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
{
|
|
{
|
|
|
- ProjectResourceMetaPtr resourceMeta = std::static_pointer_cast<ProjectResourceMeta>(loadedMeta);
|
|
|
|
|
- resEntry->meta = resourceMeta;
|
|
|
|
|
|
|
+ LOGWRN("Missing meta file: " + metaPath.toString() + ". Triggering reimport.");
|
|
|
|
|
+ reimportResourceInternal(resEntry);
|
|
|
|
|
+ doAddDependencies = false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- addDependencies(resEntry);
|
|
|
|
|
|
|
+ if (doAddDependencies)
|
|
|
|
|
+ addDependencies(resEntry);
|
|
|
}
|
|
}
|
|
|
else if(child->type == LibraryEntryType::Directory)
|
|
else if(child->type == LibraryEntryType::Directory)
|
|
|
{
|
|
{
|
|
@@ -1103,7 +1112,7 @@ namespace BansheeEngine
|
|
|
curDependencies.erase(iterRemove, curDependencies.end());
|
|
curDependencies.erase(iterRemove, curDependencies.end());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
void ProjectLibrary::queueDependantForReimport(const ResourceEntry* entry)
|
|
void ProjectLibrary::queueDependantForReimport(const ResourceEntry* entry)
|
|
|
{
|
|
{
|
|
|
auto iterFind = mDependencies.find(entry->path);
|
|
auto iterFind = mDependencies.find(entry->path);
|