MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / RenameAsset

Method RenameAsset

Source/Engine/Content/Content.cpp:916–975  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

914#if USE_EDITOR
915
916bool Content::RenameAsset(const StringView& oldPath, const StringView& newPath)
917{
918 ASSERT(IsInMainThread());
919
920 // Cache data
921 Asset* oldAsset = GetAsset(oldPath);
922 Asset* newAsset = GetAsset(newPath);
923
924 // Validate name
925 if (newAsset != nullptr && newAsset != oldAsset)
926 {
927 LOG(Error, "Invalid name '{0}' when trying to rename '{1}'.", newPath, oldPath);
928 return true;
929 }
930
931 // Ensure asset is ready for renaming
932 if (oldAsset)
933 {
934 // Wait for data loaded
935 if (oldAsset->WaitForLoaded())
936 {
937 LOG(Error, "Failed to load asset '{0}'.", oldAsset->ToString());
938 return true;
939 }
940
941 // Unload
942 // Don't unload asset fully, only release ref to file, don't call OnUnload so managed asset and all refs will remain alive
943 oldAsset->releaseStorage();
944 //oldAsset->onUnload_MainThread();
945 //ScopeLock lock(oldAsset->Locker);
946 //oldAsset->unload(true);
947 }
948
949 // Ensure to unlock file
950 ContentStorageManager::EnsureAccess(oldPath);
951
952 // Move file
953 if (FileSystem::MoveFile(newPath, oldPath))
954 {
955 LOG(Error, "Cannot move file '{0}' to '{1}'", oldPath, newPath);
956 return true;
957 }
958
959 // Update cache
960 Cache.RenameAsset(oldPath, newPath);
961 ContentStorageManager::OnRenamed(oldPath, newPath);
962
963 // Check if is loaded
964 if (oldAsset)
965 {
966 // Rename internal call
967 oldAsset->onRename(newPath);
968
969 // Load
970 //ScopeLock lock(oldAsset->Locker);
971 //oldAsset->startLoading();
972 }
973

Callers

nothing calls this directly

Calls 6

IsInMainThreadFunction · 0.85
GetAssetFunction · 0.85
WaitForLoadedMethod · 0.80
ToStringMethod · 0.45
releaseStorageMethod · 0.45
onRenameMethod · 0.45

Tested by

no test coverage detected