| 197 | } |
| 198 | |
| 199 | bool FileSystemBase::CopyFile(const StringView& dst, const StringView& src) |
| 200 | { |
| 201 | // Open and create files |
| 202 | const auto srcFile = File::Open(src, FileMode::OpenExisting, FileAccess::Read); |
| 203 | if (!srcFile) |
| 204 | { |
| 205 | return true; |
| 206 | } |
| 207 | const auto dstFile = File::Open(dst, FileMode::CreateAlways, FileAccess::Write); |
| 208 | if (!dstFile) |
| 209 | { |
| 210 | Delete(srcFile); |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | // Skip for empty file |
| 215 | uint32 size = srcFile->GetSize(); |
| 216 | if (size == 0) |
| 217 | { |
| 218 | Delete(srcFile); |
| 219 | Delete(dstFile); |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | // Copy data |
| 224 | const uint32 bufferSize = Math::Min<uint32>(1024 * 1024, size); |
| 225 | byte* buffer = (byte*)Allocator::Allocate(bufferSize); |
| 226 | while (size) |
| 227 | { |
| 228 | const uint32 readSize = Math::Min<uint32>(bufferSize, size); |
| 229 | srcFile->Read(buffer, readSize); |
| 230 | dstFile->Write(buffer, readSize); |
| 231 | size -= readSize; |
| 232 | } |
| 233 | Allocator::Free(buffer); |
| 234 | |
| 235 | // Cleanup |
| 236 | Delete(srcFile); |
| 237 | Delete(dstFile); |
| 238 | |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | bool FileSystemBase::CopyDirectory(const String& dst, const String& src, bool withSubDirectories) |
| 243 | { |