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

Method deleteFileSafety

Source/Engine/Content/Content.cpp:861–895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

859}
860
861void Content::deleteFileSafety(const StringView& path, const Guid* id)
862{
863 if (id && !id->IsValid())
864 {
865 LOG(Warning, "Cannot remove file \'{0}\'. Given ID is invalid.", path);
866 return;
867 }
868 PROFILE_CPU();
869
870 // Ensure that file has the same ID (prevent from deleting different assets)
871 auto storage = ContentStorageManager::TryGetStorage(path);
872 if (storage && id)
873 {
874 storage->CloseFileHandles(); // Close file handle to allow removing it
875 if (!storage->HasAsset(*id))
876 {
877 LOG(Warning, "Cannot remove file \'{0}\'. It doesn\'t contain asset {1}.", path, *id);
878 return;
879 }
880 }
881
882#if PLATFORM_WINDOWS || PLATFORM_LINUX
883 // Safety way - move file to the recycle bin
884 if (FileSystem::MoveFileToRecycleBin(path))
885 {
886 LOG(Warning, "Failed to move file to Recycle Bin. Path: \'{0}\'", path);
887 }
888#else
889 // Remove file
890 if (FileSystem::DeleteFile(path))
891 {
892 LOG(Warning, "Failed to delete file Path: \'{0}\'", path);
893 }
894#endif
895}
896
897#if !COMPILE_WITHOUT_CSHARP
898

Callers

nothing calls this directly

Calls 3

CloseFileHandlesMethod · 0.80
IsValidMethod · 0.45
HasAssetMethod · 0.45

Tested by

no test coverage detected