6#include "Misc/AssertionMacros.h"
7#include "HAL/UnrealMemory.h"
8#include "Templates/UnrealTemplate.h"
9#include "Math/UnrealMathUtility.h"
10#include "Serialization/Archive.h"
11#include "Containers/UnrealString.h"
12#include "Misc/Parse.h"
13#include "Logging/LogMacros.h"
14#include "Misc/DateTime.h"
15#include "GenericPlatform/GenericPlatformFile.h"
16#include "HAL/IPlatformFileLogWrapper.h"
17#include "Templates/UniquePtr.h"
19class IAsyncReadFileHandle;
41 virtual int64
Tell()
override
46 virtual bool Seek(int64 NewPosition)
override
48 if (NewPosition < 0 || NewPosition >
FileSize)
56 virtual bool SeekFromEnd(int64 NewPositionRelativeToEnd = 0)
override
61 virtual bool Read(uint8* Destination, int64 BytesToRead)
override
83 BytesToRead -= CopyBytes;
84 Destination += CopyBytes;
100 while (BytesToRead && Result)
107 uint64 SizeToRead=FMath::Min<uint64>(BufferCacheSize, FileSize-AlignedFilePos);
127 uint64 CorrectedBytesToRead=FMath::Min<uint64>(BytesToRead, CacheEnd[CacheIndex]-FilePos);
129 FilePos += CorrectedBytesToRead;
130 Destination += CorrectedBytesToRead;
131 BytesToRead -= CorrectedBytesToRead;
138 virtual bool Write(
const uint8* Source, int64 BytesToWrite)
override
145 if (BytesToWrite == 0)
151 bool Result = FileHandle->Write(Source, BytesToWrite);
155 FileSize = FMath::Max<int64>(FilePos, FileSize);
167 virtual bool Flush(
const bool bFullFlush =
false)
override
171 return FileHandle->Flush(bFullFlush);
180 if (FileHandle->Truncate(NewSize))
183 FilePos = TellPos = FileHandle->Tell();
184 FileSize = FileHandle->Size();
193 FileHandle->ShrinkBuffers();
208 bool bOk=FileHandle->Seek(Pos);
217 if (FileHandle->Read(Dest, BytesToRead))
261 return TEXT(
"CachedReadFile");
278 check(Inner !=
nullptr);
284#ifndef PLATFORM_PROVIDES_FILE_CACHE
285#define PLATFORM_PROVIDES_FILE_CACHE 0
294 if (
FParse::Param(CmdLine,
TEXT(
"NoCachedReadFile")))
298 else if (
FParse::Param(CmdLine,
TEXT(
"CachedReadFile")))
303 UE_LOG(LogPlatformFile, Verbose,
TEXT(
"%s cached read wrapper"), bResult ?
TEXT(
"Using") :
TEXT(
"Not using"));
324 virtual int64
FileSize(
const TCHAR* Filename)
override
328 virtual bool DeleteFile(
const TCHAR* Filename)
override
336 virtual bool MoveFile(
const TCHAR* To,
const TCHAR* From)
override
340 virtual bool SetReadOnly(
const TCHAR* Filename,
bool bNewReadOnlyValue)
override
367 return new FCachedFileHandle(InnerHandle,
true,
false);
376 return new FCachedFileHandle(InnerHandle, bAllowRead,
true);
382 virtual bool CreateDirectory(
const TCHAR* Directory)
override
384 return LowerLevel->CreateDirectory(Directory);
410 virtual void FindFiles(TArray<FString>& FoundFiles,
const TCHAR* Directory,
const TCHAR* FileExtension)
412 return LowerLevel->FindFiles(FoundFiles, Directory, FileExtension);
414 virtual void FindFilesRecursively(TArray<FString>& FoundFiles,
const TCHAR* Directory,
const TCHAR* FileExtension)
416 return LowerLevel->FindFilesRecursively(FoundFiles, Directory, FileExtension);
424 return LowerLevel->CopyFile(To, From, ReadFlags, WriteFlags);
430 virtual bool CopyDirectoryTree(
const TCHAR* DestinationDirectory,
const TCHAR* Source,
bool bOverwriteAllExisting)
override
450 virtual IMappedFileHandle*
OpenMapped(
const TCHAR* Filename)
override
#define UE_ARRAY_COUNT(array)
virtual bool Write(const uint8 *Source, int64 BytesToWrite) override
bool InnerRead(uint8 *Dest, uint64 BytesToRead)
uint8 BufferCache[CacheCount][BufferCacheSize]
static constexpr uint64 BufferSizeMask
virtual bool SeekFromEnd(int64 NewPositionRelativeToEnd=0) override
virtual int64 Size() override
static constexpr uint32 CacheCount
virtual int64 Tell() override
virtual bool Flush(const bool bFullFlush=false) override
virtual void ShrinkBuffers() override
static constexpr uint32 BufferCacheSize
int64 CacheStart[CacheCount]
int32 GetCacheIndex(int64 Pos) const
virtual bool Seek(int64 NewPosition) override
virtual ~FCachedFileHandle()
FCachedFileHandle(IFileHandle *InFileHandle, bool bInReadable, bool bInWritable)
TUniquePtr< IFileHandle > FileHandle
bool InnerSeek(uint64 Pos)
virtual bool Truncate(int64 NewSize) override
virtual bool Read(uint8 *Destination, int64 BytesToRead) override
int64 CacheEnd[CacheCount]
static FORCEINLINE void * Memcpy(void *Dest, const void *Src, SIZE_T Count)