64 if (!bReadable || BytesToRead < 0 || (BytesToRead + FilePos > FileSize))
75 if (BytesToRead > BufferCacheSize)
78 int32 CacheIndex=GetCacheIndex(FilePos);
79 if (CacheIndex < CacheCount)
88 if (InnerSeek(FilePos))
90 Result = InnerRead(Destination, BytesToRead);
94 FilePos += BytesToRead;
101 while (BytesToRead && Result)
103 uint32 CacheIndex=GetCacheIndex(FilePos);
104 if (CacheIndex > CacheCount)
110 Result = InnerRead(BufferCache[CurrentCache],
SizeToRead);
116 CacheIndex = CurrentCache;
119 CurrentCache%=CacheCount;
142 return FileHandle->
ReadAt(Destination, BytesToRead,
Offset);
162 FileSize = FMath::Max<int64>(FilePos, FileSize);
190 FilePos = TellPos = FileHandle->
Tell();
191 FileSize = FileHandle->
Size();
205 static constexpr uint32 BufferCacheSize = 64 * 1024;
206 static constexpr uint64 BufferSizeMask = ~((
uint64)BufferCacheSize-1);
207 static constexpr uint32 CacheCount = 2;
209 bool InnerSeek(
uint64 Pos)
215 bool bOk=FileHandle->
Seek(Pos);
224 if (FileHandle->
Read(Dest, BytesToRead))
226 TellPos += BytesToRead;
235 if (Pos >= CacheStart[i] && Pos < CacheEnd[i])
244 for (
uint32 i=0; i<CacheCount; ++i)
246 CacheStart[i] = CacheEnd[i] = -1;
256 uint8 BufferCache[CacheCount][BufferCacheSize];
257 int64 CacheStart[CacheCount];
258 int64 CacheEnd[CacheCount];
268 return TEXT(
"CachedReadFile");
272 : LowerLevel(nullptr)
291#ifndef PLATFORM_PROVIDES_FILE_CACHE
292#define PLATFORM_PROVIDES_FILE_CACHE 0
301#if (PLATFORM_DESKTOP || PLATFORM_PROVIDES_FILE_CACHE)
335 return LowerLevel->
FileSize(Filename);
347 return LowerLevel->
MoveFile(To, From);
421 return LowerLevel->
FindFiles(FoundFiles, Directory, FileExtension);
491 FString*
OutError =
nullptr)
override
#define check(expr)
Definition AssertionMacros.h:314
#define CA_ASSUME(Expr)
Definition CoreMiscDefines.h:126
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
#define UE_ARRAY_COUNT(array)
Definition UnrealTemplate.h:212
uint32 Offset
Definition VulkanMemory.cpp:4033
Definition IPlatformFileCachedWrapper.h:23
virtual bool Write(const uint8 *Source, int64 BytesToWrite) override
Definition IPlatformFileCachedWrapper.h:145
virtual bool SeekFromEnd(int64 NewPositionRelativeToEnd=0) override
Definition IPlatformFileCachedWrapper.h:57
virtual int64 Size() override
Definition IPlatformFileCachedWrapper.h:169
virtual int64 Tell() override
Definition IPlatformFileCachedWrapper.h:42
virtual bool Flush(const bool bFullFlush=false) override
Definition IPlatformFileCachedWrapper.h:174
virtual bool ReadAt(uint8 *Destination, int64 BytesToRead, int64 Offset) override
Definition IPlatformFileCachedWrapper.h:139
virtual void ShrinkBuffers() override
Definition IPlatformFileCachedWrapper.h:198
virtual bool Seek(int64 NewPosition) override
Definition IPlatformFileCachedWrapper.h:47
virtual ~FCachedFileHandle()
Definition IPlatformFileCachedWrapper.h:37
FCachedFileHandle(IFileHandle *InFileHandle, bool bInReadable, bool bInWritable)
Definition IPlatformFileCachedWrapper.h:25
virtual bool Truncate(int64 NewSize) override
Definition IPlatformFileCachedWrapper.h:183
virtual bool Read(uint8 *Destination, int64 BytesToRead) override
Definition IPlatformFileCachedWrapper.h:62
Definition AsyncFileHandle.h:211
Definition GenericPlatformFile.h:117
virtual bool ReadAt(uint8 *Destination, int64 BytesToRead, int64 Offset)=0
virtual void ShrinkBuffers()
Definition GenericPlatformFile.h:179
virtual bool Flush(const bool bFullFlush=false)=0
virtual bool Seek(int64 NewPosition)=0
virtual bool Read(uint8 *Destination, int64 BytesToRead)=0
virtual bool Truncate(int64 NewSize)=0
virtual bool Write(const uint8 *Source, int64 BytesToWrite)=0
virtual CORE_API int64 Size()
Definition GenericPlatformFile.cpp:578
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
Definition ValueOrError.h:58
Type
Definition LogVerbosity.h:17
Definition GenericPlatformFile.h:271
Definition GenericPlatformFile.h:195
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
static CORE_API bool Param(const TCHAR *Stream, const TCHAR *Param)
Definition Parse.cpp:325