5#include "Containers/Map.h"
6#include "Containers/UnrealString.h"
8#include "GenericPlatform/GenericPlatformFile.h"
9#include "HAL/CriticalSection.h"
10#include "HAL/PlatformMisc.h"
11#include "HAL/PlatformTime.h"
12#include "Logging/LogCategory.h"
13#include "Logging/LogMacros.h"
14#include "Math/Color.h"
15#include "Misc/DateTime.h"
16#include "Misc/ScopeLock.h"
17#include "Templates/UniquePtr.h"
18#include "Trace/Detail/Channel.h"
22class IAsyncReadFileHandle;
23class IMappedFileHandle;
26
27
32#define FILE_LOG(CategoryName, Verbosity, Format, ...)
33 if (!bSuppressFileLog)
35 bSuppressFileLog = true;
36 UE_LOG(CategoryName, Verbosity, Format, ##__VA_ARGS__);
37 bSuppressFileLog = false;
54 virtual int64
Tell()
override
56 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Tell %s"), *Filename);
58 int64 Result = FileHandle->Tell();
60 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Tell return %lld [%fms]"), Result, ThisTime);
63 virtual bool Seek(int64 NewPosition)
override
65 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Seek %s %lld"), *Filename, NewPosition);
67 bool Result = FileHandle->Seek(NewPosition);
69 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Seek return %d [%fms]"), int32(Result), ThisTime);
72 virtual bool SeekFromEnd(int64 NewPositionRelativeToEnd)
override
74 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"SeekFromEnd %s %lld"), *Filename, NewPositionRelativeToEnd);
76 bool Result = FileHandle->SeekFromEnd(NewPositionRelativeToEnd);
78 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"SeekFromEnd return %d [%fms]"), int32(Result), ThisTime);
81 virtual bool Read(uint8* Destination, int64 BytesToRead)
override
83 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Read %s %lld"), *Filename, BytesToRead);
85 bool Result = FileHandle->Read(Destination, BytesToRead);
87 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Read return %d [%fms]"), int32(Result), ThisTime);
90 virtual bool Write(
const uint8* Source, int64 BytesToWrite)
override
92 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Write %s %lld"), *Filename, BytesToWrite);
94 bool Result = FileHandle->Write(Source, BytesToWrite);
96 FILE_LOG(LogPlatformFile, VeryVerbose,
TEXT(
"Write return %d [%fms]"), int32(Result), ThisTime);
99 virtual int64
Size()
override
101 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Size %s"), *Filename);
103 int64 Result = FileHandle->Size();
105 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Size return %lld [%fms]"), Result, ThisTime);
108 virtual bool Flush(
const bool bFullFlush =
false)
override
110 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Flush %s %s"), *Filename, (bFullFlush ? TEXT(
"full") : TEXT(
"partial")));
112 bool bResult = FileHandle->Flush(bFullFlush);
114 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Flush return %d [%fms]"), int32(bResult), ThisTime);
119 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Truncate %s %lld"), *Filename, NewSize);
121 bool bResult = FileHandle->Truncate(NewSize);
123 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Truncate return %d [%fms]"), int32(bResult), ThisTime);
128 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"ShrinkBuffers %s"), *Filename);
130 FileHandle->ShrinkBuffers();
132 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"ShrinkBuffers return [%fms]"), ThisTime);
148 return TEXT(
"LogFile");
187 FILE_LOG(LogPlatformFile, Log,
TEXT(
"FileExists return %d [%fms]"), int32(Result), ThisTime);
190 virtual int64
FileSize(
const TCHAR* Filename)
override
198 FILE_LOG(LogPlatformFile, Log,
TEXT(
"FileSize return %lld [%fms]"), Result, ThisTime);
201 virtual bool DeleteFile(
const TCHAR* Filename)
override
207 bool Result =
LowerLevel->DeleteFile(Filename);
209 FILE_LOG(LogPlatformFile, Log,
TEXT(
"DeleteFile return %d [%fms]"), int32(Result), ThisTime);
220 FILE_LOG(LogPlatformFile, Log,
TEXT(
"IsReadOnly return %d [%fms]"), int32(Result), ThisTime);
223 virtual bool MoveFile(
const TCHAR* To,
const TCHAR* From)
override
231 FILE_LOG(LogPlatformFile, Log,
TEXT(
"MoveFile return %d [%fms]"), int32(Result), ThisTime);
234 virtual bool SetReadOnly(
const TCHAR* Filename,
bool bNewReadOnlyValue)
override
236 FString DataStr =
FString::Printf(
TEXT(
"SetReadOnly %s %d"), Filename, int32(bNewReadOnlyValue));
242 FILE_LOG(LogPlatformFile, Log,
TEXT(
"SetReadOnly return %d [%fms]"), int32(Result), ThisTime);
253 FILE_LOG(LogPlatformFile, Log,
TEXT(
"GetTimeStamp return %llx [%fms]"), Result.GetTicks(), ThisTime);
264 FILE_LOG(LogPlatformFile, Log,
TEXT(
"SetTimeStamp [%fms]"), ThisTime);
274 FILE_LOG(LogPlatformFile, Log,
TEXT(
"GetAccessTimeStamp return %llx [%fms]"), Result.GetTicks(), ThisTime);
285 FILE_LOG(LogPlatformFile, Log,
TEXT(
"GetFilenameOnDisk return %s [%fms]"), *Result, ThisTime);
296 FILE_LOG(LogPlatformFile, Log,
TEXT(
"OpenRead return %llx [%fms]"), uint64(Result), ThisTime);
301 FString DataStr =
FString::Printf(
TEXT(
"OpenWrite %s %d %d"), Filename, int32(bAppend), int32(bAllowRead));
307 FILE_LOG(LogPlatformFile, Log,
TEXT(
"OpenWrite return %llx [%fms]"), uint64(Result), ThisTime);
319 FILE_LOG(LogPlatformFile, Log,
TEXT(
"DirectoryExists return %d [%fms]"), int32(Result), ThisTime);
322 virtual bool CreateDirectory(
const TCHAR* Directory)
override
328 bool Result =
LowerLevel->CreateDirectory(Directory);
330 FILE_LOG(LogPlatformFile, Log,
TEXT(
"CreateDirectory return %d [%fms]"), int32(Result), ThisTime);
341 FILE_LOG(LogPlatformFile, Log,
TEXT(
"DeleteDirectory return %d [%fms]"), int32(Result), ThisTime);
352 FILE_LOG(LogPlatformFile, Log,
TEXT(
"GetStatData return %d [%fms]"), int32(Result.bIsValid), ThisTime);
364 virtual bool Visit(
const TCHAR* FilenameOrDirectory,
bool bIsDirectory)
override
366 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Visit %s %d"), FilenameOrDirectory, int32(bIsDirectory));
370 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Visit return %d [%fms]"), int32(Result), ThisTime);
384 FILE_LOG(LogPlatformFile, Log,
TEXT(
"IterateDirectory return %d [%fms]"), int32(Result), ThisTime);
396 FILE_LOG(LogPlatformFile, Log,
TEXT(
"IterateDirectoryRecursively return %d [%fms]"), int32(Result), ThisTime);
410 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Visit %s %d"), FilenameOrDirectory, int32(StatData.bIsDirectory));
414 FILE_LOG(LogPlatformFile, Verbose,
TEXT(
"Visit return %d [%fms]"), int32(Result), ThisTime);
428 FILE_LOG(LogPlatformFile, Log,
TEXT(
"IterateDirectoryStat return %d [%fms]"), int32(Result), ThisTime);
433 FString DataStr =
FString::Printf(
TEXT(
"IterateDirectoryStatRecursively %s"), Directory);
440 FILE_LOG(LogPlatformFile, Log,
TEXT(
"IterateDirectoryStatRecursively return %d [%fms]"), int32(Result), ThisTime);
452 FILE_LOG(LogPlatformFile, Log,
TEXT(
"DeleteDirectoryRecursively return %d [%fms]"), int32(Result), ThisTime);
461 bool Result =
LowerLevel->CopyFile(To, From, ReadFlags, WriteFlags);
463 FILE_LOG(LogPlatformFile, Log,
TEXT(
"CopyFile return %d [%fms]"), int32(Result), ThisTime);
493 FILE_LOG(LogPlatformFile, Log,
TEXT(
"OpenAsyncRead return %llx [%fms]"), uint64(Result), ThisTime);
497 virtual IMappedFileHandle*
OpenMapped(
const TCHAR* Filename)
override
#define UE_BUILD_SHIPPING
virtual bool Read(uint8 *Destination, int64 BytesToRead) override
virtual int64 Tell() override
virtual ~FLoggedFileHandle()
virtual bool SeekFromEnd(int64 NewPositionRelativeToEnd) override
virtual bool Flush(const bool bFullFlush=false) override
FLoggedFileHandle(IFileHandle *InFileHandle, const TCHAR *InFilename, FLoggedPlatformFile &InOwner)
virtual bool Write(const uint8 *Source, int64 BytesToWrite) override
virtual void ShrinkBuffers() override
virtual bool Truncate(int64 NewSize) override
virtual int64 Size() override
TUniquePtr< IFileHandle > FileHandle
virtual bool Seek(int64 NewPosition) override