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

Method CloneAssetFile

Source/Engine/Content/Content.cpp:1006–1129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1004};
1005
1006bool Content::CloneAssetFile(const StringView& dstPath, const StringView& srcPath, const Guid& dstId)
1007{
1008 // Best to run this on the main thread to avoid clone conflicts.
1009 if (IsInMainThread())
1010 {
1011 PROFILE_CPU();
1012 ASSERT(FileSystem::AreFilePathsEqual(srcPath, dstPath) == false && dstId.IsValid());
1013
1014 LOG(Info, "Cloning asset \'{0}\' to \'{1}\'({2}).", srcPath, dstPath, dstId);
1015
1016 // Check source file
1017 if (!FileSystem::FileExists(srcPath))
1018 {
1019 LOG(Warning, "Missing source file.");
1020 return true;
1021 }
1022
1023 // Special case for json resources
1024 if (JsonStorageProxy::IsValidExtension(FileSystem::GetExtension(srcPath).ToLower()))
1025 {
1026 if (FileSystem::CopyFile(dstPath, srcPath))
1027 {
1028 LOG(Warning, "Cannot copy file to destination.");
1029 return true;
1030 }
1031 if (JsonStorageProxy::ChangeId(dstPath, dstId))
1032 {
1033 LOG(Warning, "Cannot change asset ID.");
1034 return true;
1035 }
1036 return false;
1037 }
1038
1039 // Check if destination file is missing
1040 if (!FileSystem::FileExists(dstPath))
1041 {
1042 // Use quick file copy
1043 if (FileSystem::CopyFile(dstPath, srcPath))
1044 {
1045 LOG(Warning, "Cannot copy file to destination.");
1046 return true;
1047 }
1048
1049 // Change ID
1050 auto storage = ContentStorageManager::GetStorage(dstPath);
1051 FlaxStorage::Entry e;
1052 storage->GetEntry(0, e);
1053 if (storage == nullptr || storage->ChangeAssetID(e, dstId))
1054 {
1055 LOG(Warning, "Cannot change asset ID.");
1056 return true;
1057 }
1058 }
1059 else
1060 {
1061 // Use temporary file
1062 String tmpPath = Globals::TemporaryFolder / Guid::New().ToString(Guid::FormatType::D);
1063 if (FileSystem::CopyFile(tmpPath, srcPath))

Callers

nothing calls this directly

Calls 14

IsInMainThreadFunction · 0.85
AreFilePathsEqualFunction · 0.85
ChangeAssetIDMethod · 0.80
NewFunction · 0.50
IsValidMethod · 0.45
ToLowerMethod · 0.45
GetEntryMethod · 0.45
ToStringMethod · 0.45
IsLoadedMethod · 0.45
ReloadMethod · 0.45
TryGetMethod · 0.45
OnDependencyModifiedMethod · 0.45

Tested by

no test coverage detected