17#pragma region TNativeFileSystem
35 if ( !nativeFile->
Open( a_rcFileName, a_eFileMode ) )
55 return DeleteFileA( a_rcFileName ) != 0;
61 if ( a_rcPath.
Compare(
"//", 2 ) == 0 ||
62 a_rcPath.
Compare(
"\\\\", 2 ) == 0 ||
63 ( a_rcPath.
Length() >= 2 && a_rcPath[ 1 ] ==
':' ) )
69 return strInternalPath;
76 if ( strInternalPath.
Length() > 0 )
78 TCHAR cLastChar = strInternalPath[ strInternalPath.
Length() - 1 ];
80 if ( cLastChar ==
'/' || cLastChar ==
'\\' )
87 return strInternalPath;
95 const char* pchFilter =
101 strPath += pchFilter;
103 WIN32_FIND_DATAA oFindData;
104 HANDLE hFirstFile = FindFirstFileA( strPath, &oFindData );
107 if ( hFirstFile != INVALID_HANDLE_VALUE )
111 if ( oFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
116 if ( ui8MaskedFlags != 0 )
118 a_rOutFileName = oFindData.cFileName;
128 return CreateDirectoryA(
string,
TNULL );
133 WIN32_FIND_DATAA findFileData;
142 else if ( findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
146 a_rOutFileName = findFileData.cFileName;
152 a_rOutFileName = findFileData.cFileName;
199 DWORD lpNumberOfBytesRead;
224TINT TNativeFile::FlushWriteBuffer()
227#ifdef BARNYARD_COMMUNITY_PATCH
241 if (
m_RBufferPosition == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR )
249 DWORD lpNumberOfBytesWritten;
256 return lpNumberOfBytesWritten;
260TINT TNativeFile::ReadUnbuffered( LPVOID dst,
TUINT size )
262 DWORD lpNumberOfBytesRead;
269 if (
m_RBufferPosition == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR )
277 if ( ReadFile(
m_Handle, dst, size, &lpNumberOfBytesRead,
TNULL ) == 0 )
285 return lpNumberOfBytesRead;
293 if ( a_uiSize < 1 )
return 0;
297 TSIZE readedCount = 0;
301 LPVOID curPosBuffer = a_pDst;
303 if ( curBufferPos != newBufferPos )
313 curPosBuffer = (
TCHAR*)a_pDst + readCount;
315 readedCount = readCount;
319 DWORD toReadCount = newBufferPos -
m_Position;
320 curBufferPos = newBufferPos;
322 if ( toReadCount > 0 )
324 TUINT32 readed = ReadUnbuffered( curPosBuffer, toReadCount );
325 curPosBuffer = (
TCHAR*)curPosBuffer + readed;
326 readedCount += readed;
328 if ( readed != toReadCount )
336 if ( readedCount != a_uiSize && LoadBuffer( curBufferPos ) )
338 a_uiSize -= readedCount;
339 DWORD bufferLeftSize =
m_Position - curBufferPos;
347 readedCount += readCount;
354 return ReadUnbuffered( a_pDst, a_uiSize );
365 if (
m_RBufferPosition == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR )
376 BOOL bRes = WriteFile(
m_Handle, buffer, size, &written, NULL );
405 BOOL bRes = WriteFile(
m_Handle, buffer, size, &written, NULL );
442 if (
m_RBufferPosition == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR )
472 if (
Read( &result,
sizeof( result ) ) !=
sizeof( result ) )
495 if (
Read( &result,
sizeof( result ) ) !=
sizeof( result ) )
504 if (
Write( &a_cCharacter, 1 ) != 1 )
509 return a_cCharacter & 0xFF;
515 if (
Write( &a_wcCharacter, 2 ) != 2 )
520 return a_wcCharacter & 0xFFFF;
527 va_start( args, a_szFormat );
535 Write( str, iResult );
544 va_start( args, a_wszFormat );
562 if (
m_RBufferPosition == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR )
577 GetFileTime(
m_Handle, NULL, NULL, (LPFILETIME)&uiLastWriteTime );
580 return uiLastWriteTime;
588 DWORD dwCreationDisposition = OPEN_EXISTING;
589 DWORD dwDesiredAccess = 0;
590 DWORD dwShareMode = 0;
592 dwDesiredAccess |= ( a_Mode &
TFILEMODE_READ ) ? GENERIC_READ : dwDesiredAccess;
593 dwDesiredAccess |= ( a_Mode &
TFILEMODE_WRITE ) ? GENERIC_WRITE : dwDesiredAccess;
594 dwDesiredAccess |= ( a_Mode &
TFILEMODE_READWRITE ) ? ( GENERIC_READ | GENERIC_WRITE ) : dwDesiredAccess;
598 dwShareMode = FILE_SHARE_READ;
599 dwCreationDisposition = CREATE_ALWAYS;
600 dwDesiredAccess |= GENERIC_WRITE;
603 if ( dwDesiredAccess == 0 )
605 TWARN(
"WARNING: File created with no access mode, assuming WRITEONLY\n" );
606 dwDesiredAccess = GENERIC_WRITE;
609 m_Handle = CreateFileA( a_FileName.
GetString(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, NULL, NULL );
611 if (
m_Handle != INVALID_HANDLE_VALUE )
void * TMalloc(TSIZE a_uiSize, Toshi::TMemory::MemBlock *a_pMemBlock, const TCHAR *a_szFileName, TINT a_iLineNum)
Allocates memory from a specific memory block.
void TFree(void *a_pMem)
Frees previously allocated memory.
#define TSTATICCAST(POINTERTYPE, VALUE)
#define TREINTERPRETCAST(TYPE, VALUE)
#define TOSHI_NAMESPACE_START
#define TARRAYSIZE(ARRAY)
#define TOSHI_NAMESPACE_END
void FixPathSlashes(TString8 &a_rPath)
TFORCEINLINE const T & Min(const T &a, const T &b)
TFileSystem(const TCHAR *a_szName)
TFileLookupHandle m_NextFileHandle
void UnmountFileSystem()
Unmounts this file system from the TFileManager.
TFile(TFileSystem *a_pFS)
TString8 MakeAbsolutePath(const TString8 &a_rcRelativePath) const
void MountFileSystem(TFileSystem *a_pFileSystem)
virtual ~TNativeFileSystem()
TNativeFileSystem(const TCHAR *name)
virtual TBOOL GetFirstFile(const TString8 &a_rcPath, TString8 &a_rOutFileName, TFINDFILE a_ui8Flags) OVERRIDE
Finds out what's the first file at the specified path.
virtual TString8 MakeInternalPath(const TString8 &a_rcPath) OVERRIDE
Not documented.
virtual TBOOL MakeDirectory(const TString8 &a_rcDirectory)
virtual TBOOL GetNextFile(TString8 &a_rOutFileName, TFINDFILE a_ui8Flags) OVERRIDE
Not documented.
virtual TBOOL RemoveFile(const TString8 &a_rcFileName) OVERRIDE
Removes specified file.
virtual void DestroyFile(TFile *a_pFile) OVERRIDE
Destroys specified file.
virtual TFile * CreateFile(const TString8 &a_rcFileName, TFILEMODE a_eFileMode) OVERRIDE
Creates file.
TUINT32 m_WriteBufferUsed
TNativeFile(TNativeFileSystem *a_pFileSystem)
virtual TSIZE Write(const void *a_pSrc, TSIZE a_uiSize) OVERRIDE
Writes specified number of bytes to the file from the buffer.
TBOOL Open(const TString8 &a_FileName, TFILEMODE a_Mode)
virtual TINT PutWChar(TWCHAR a_wcCharacter) OVERRIDE
Writes one character of type wchar to the file.
virtual TINT PutCChar(TCHAR a_cCharacter) OVERRIDE
Writes one character of type TCHAR to the file.
static constexpr TUINT32 BUFFER_SIZE
virtual TSIZE Read(void *a_pDst, TSIZE a_uiSize) OVERRIDE
Reads specified number of bytes from the file into the buffer.
virtual TBOOL Seek(TINT a_iOffset, TSEEK a_eOrigin=TSEEK_CUR) OVERRIDE
Shifts current file cursor based on the specified offset and origin.
virtual TSIZE GetSize() OVERRIDE
virtual void FlushBuffers() OVERRIDE
Flushes write buffers.
virtual TINT WPrintf(const TWCHAR *a_wszFormat,...) OVERRIDE
Analogue of wprintf but writes result to the file.
virtual TWCHAR GetWChar() OVERRIDE
Reads one character of type wchar from the file.
virtual TCHAR GetCChar() OVERRIDE
Reads one character of type TCHAR from the file.
virtual TUINT64 GetDate() OVERRIDE
virtual TINT CPrintf(const TCHAR *a_szFormat,...) OVERRIDE
Analogue of printf but writes result to the file.
virtual TSIZE Tell() OVERRIDE
TUINT32 m_RBufferPosition
static TINT FormatV(TWCHAR *a_pcString, TINT size, const TWCHAR *a_pcFormat, va_list args)
static TINT FormatV(TCHAR *a_pcString, TINT size, const TCHAR *a_pcFormat, va_list args)
static TFORCEINLINE TFileManager * GetSingleton()
static TFORCEINLINE TFileManager * GetSingletonSafe()
TString8 Mid(TINT a_iFirst, TINT a_iCount) const
TINT Compare(const TCHAR *a_szString, TINT a_iLength=-1) const
TBOOL IsIndexValid(TINT a_iIndex) const
void Truncate(TINT length)
const TCHAR * GetString(TINT a_iIndex=0) const
static void * MemCopy(void *dst, const void *src, TSIZE size)