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

Method CopyFile

Source/Engine/Platform/Base/FileSystemBase.cpp:199–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199bool 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
242bool FileSystemBase::CopyDirectory(const String& dst, const String& src, bool withSubDirectories)
243{

Callers

nothing calls this directly

Calls 5

DeleteFunction · 0.85
FreeFunction · 0.50
GetSizeMethod · 0.45
ReadMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected