| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #include "BsResourceManifest.h"
- #include "BsResourceManifestRTTI.h"
- #include "BsFileSerializer.h"
- #include "BsException.h"
- namespace BansheeEngine
- {
- ResourceManifest::ResourceManifest(const ConstructPrivately& dummy)
- {
- }
- ResourceManifest::ResourceManifest(const String& name)
- :mName(name)
- {
- }
- ResourceManifestPtr ResourceManifest::create(const String& name)
- {
- return bs_shared_ptr<ResourceManifest>(name);
- }
- ResourceManifestPtr ResourceManifest::createEmpty()
- {
- return bs_shared_ptr<ResourceManifest>(ConstructPrivately());
- }
- void ResourceManifest::registerResource(const String& uuid, const Path& filePath)
- {
- auto iterFind = mUUIDToFilePath.find(uuid);
- if(iterFind != mUUIDToFilePath.end())
- {
- if (iterFind->second != filePath)
- {
- mFilePathToUUID.erase(iterFind->second);
- mUUIDToFilePath[uuid] = filePath;
- mFilePathToUUID[filePath] = uuid;
- }
- }
- else
- {
- auto iterFind2 = mFilePathToUUID.find(filePath);
- if (iterFind2 != mFilePathToUUID.end())
- mUUIDToFilePath.erase(iterFind2->second);
- mUUIDToFilePath[uuid] = filePath;
- mFilePathToUUID[filePath] = uuid;
- }
- }
- void ResourceManifest::unregisterResource(const String& uuid)
- {
- auto iterFind = mUUIDToFilePath.find(uuid);
- if(iterFind != mUUIDToFilePath.end())
- {
- mFilePathToUUID.erase(iterFind->second);
- mUUIDToFilePath.erase(uuid);
- }
- }
- bool ResourceManifest::uuidToFilePath(const String& uuid, Path& filePath) const
- {
- auto iterFind = mUUIDToFilePath.find(uuid);
- if(iterFind != mUUIDToFilePath.end())
- {
- filePath = iterFind->second;
- return true;
- }
- else
- {
- filePath = Path::BLANK;
- return false;
- }
- }
- bool ResourceManifest::filePathToUUID(const Path& filePath, String& outUUID) const
- {
- auto iterFind = mFilePathToUUID.find(filePath);
- if(iterFind != mFilePathToUUID.end())
- {
- outUUID = iterFind->second;
- return true;
- }
- else
- {
- outUUID = StringUtil::BLANK;
- return false;
- }
- }
- bool ResourceManifest::uuidExists(const String& uuid) const
- {
- auto iterFind = mUUIDToFilePath.find(uuid);
- return iterFind != mUUIDToFilePath.end();
- }
- bool ResourceManifest::filePathExists(const Path& filePath) const
- {
- auto iterFind = mFilePathToUUID.find(filePath);
- return iterFind != mFilePathToUUID.end();
- }
- void ResourceManifest::save(const ResourceManifestPtr& manifest, const Path& path, const Path& relativePath)
- {
- ResourceManifestPtr copy = create(manifest->mName);
- for(auto& elem : manifest->mFilePathToUUID)
- {
- if (!relativePath.includes(elem.first))
- {
- BS_EXCEPT(InvalidStateException, "Path in resource manifest cannot be made relative to: \"" +
- relativePath.toString() + "\". Path: \"" + elem.first.toString() + "\"");
- }
- Path elementRelativePath = elem.first.getRelative(relativePath);
- copy->mFilePathToUUID[elementRelativePath] = elem.second;
- }
- for(auto& elem : manifest->mUUIDToFilePath)
- {
- if(!relativePath.includes(elem.second))
- {
- BS_EXCEPT(InvalidStateException, "Path in resource manifest cannot be made relative to: \"" +
- relativePath.toString() + "\". Path: \"" + elem.second.toString() + "\"");
- }
- Path elementRelativePath = elem.second.getRelative(relativePath);
- copy->mUUIDToFilePath[elem.first] = elementRelativePath;
- }
- FileEncoder fs(path);
- fs.encode(copy.get());
- }
- ResourceManifestPtr ResourceManifest::load(const Path& path, const Path& relativePath)
- {
- FileDecoder fs(path);
- ResourceManifestPtr manifest = std::static_pointer_cast<ResourceManifest>(fs.decode());
- ResourceManifestPtr copy = create(manifest->mName);
- for(auto& elem : manifest->mFilePathToUUID)
- {
- Path absPath = elem.first.getAbsolute(relativePath);
- copy->mFilePathToUUID[absPath] = elem.second;
- }
- for(auto& elem : manifest->mUUIDToFilePath)
- {
- Path absPath = elem.second.getAbsolute(relativePath);
- copy->mUUIDToFilePath[elem.first] = absPath;
- }
- return copy;
- }
- RTTITypeBase* ResourceManifest::getRTTIStatic()
- {
- return ResourceManifestRTTI::instance();
- }
- RTTITypeBase* ResourceManifest::getRTTI() const
- {
- return ResourceManifest::getRTTIStatic();
- }
- }
|