| 859 | } |
| 860 | |
| 861 | void 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 |
nothing calls this directly
no test coverage detected