42 m_ReadPos +=
m_pFile->Read( &m_Magic, 4 );
46 m_Header.FileSize = PARSEDWORD_BIG( m_Header.FileSize );
47 m_Magic = PARSEDWORD_BIG( m_Magic );
50 m_CurrentHunk.Name = m_Header.Magic;
51 m_CurrentHunk.Size = m_Header.FileSize;
61 auto uiResult =
Open( pFile );
69 if ( m_CurrentHunk.Name !=
TFourCC(
"FORM" ) &&
70 m_CurrentHunk.Name !=
TFourCC(
"TSFL" ) &&
71 m_CurrentHunk.Name !=
TFourCC(
"TSFB" ) )
76 m_FileInfo[ m_FileInfoCount ].FileStartOffset =
m_pFile->Tell() - 4;
77 m_FileInfo[ m_FileInfoCount ].FileSize = m_CurrentHunk.Size;
89 auto& fileInfo = m_FileInfo[ m_FileInfoCount ];
91 m_CurrentHunk.Size = fileInfo.FileSize;
92 m_ReadPos =
m_pFile->Tell() - fileInfo.FileStartOffset;
96 m_ReadPos = alignedPos;
108 m_CurrentHunk.Name = PARSEDWORD_BIG( m_CurrentHunk.Name );
109 m_CurrentHunk.Size = PARSEDWORD_BIG( m_CurrentHunk.Size );
122 m_ReadPos = alignedSize;
130 if ( m_CurrentHunk.Name !=
TFourCC(
"FORM" ) )
143 if ( m_CurrentHunk.Name ==
TFourCC(
"FORM" ) )
148 TASSERT( m_ReadPos == 0,
"m_ReadPos should be zero" );
149 m_ReadPos +=
m_pFile->Read( dst, m_CurrentHunk.Size );
194 m_CurrentHunk.Name = 0;
195 m_CurrentHunk.Size = 0;
210 hunk.Size = PARSEDWORD_BIG( hunk.Size );
217 m_Positions[ m_PositionCount ] = 0;
218 m_PositionCount += 1;
243 auto nameValue =
TFourCC( name );
247 hunk.Name = PARSEDWORD_BIG( hunk.Name );
248 nameValue = PARSEDWORD_BIG( nameValue );
251 m_Positions[ m_PositionCount++ ] =
m_pFile->Tell();
253 auto written1 =
Write( hunk );
254 auto written2 =
Write( nameValue );
256 return written1 + written2;
263 if ( m_PositionCount > 0 )
265 auto formPosition = m_Positions[ --m_PositionCount ];
268 auto formSize = ( oldPos - formPosition ) - 8;
272 formSize = PARSEDWORD_BIG( formSize );
315 hunk.Name = PARSEDWORD_BIG( hunk.Name );
316 hunk.Size = PARSEDWORD_BIG( hunk.Size );
323 if ( buffer !=
TNULL && bufferSize > 0 )
325 writtenSize +=
m_pFile->Write( buffer, bufferSize );
336 static TCHAR s_AlignBuffer[ 4 ];
339 if ( alignValue != 4 )
341 return m_pFile->Read( s_AlignBuffer, alignValue );
349 m_ReadPos +=
m_pFile->Read( dst, size );
#define TOSHI_NAMESPACE_START
#define TOSHI_NAMESPACE_END
TFORCEINLINE TUINT32 TFourCCLE(const TCHAR str[4])
TFORCEINLINE constexpr T TAlignNumUp(T a_iValue, TSIZE a_uiAlignment=4)
TFORCEINLINE constexpr TUINT32 TFourCC(const TCHAR str[4])
static uintptr_t Decompress(TFile *file, TCompress::Header *header, TBYTE *buffer, TUINT32 bufferSize)
static int8_t GetHeader(TFile *file, TCompress::Header &btecHeader)
static TFile * Create(const TString8 &a_rcFilename, TFILEMODE a_eMode=TFILEMODE_READ)
static constexpr TUINT32 IDMAGICL
static constexpr TUINT32 IDMAGICB
TUINT32 Open(TFile *a_pFile)
void ReadCompressed(void *buffer, TUINT32 size)
void Close(TBOOL free=true)
void ReadRaw(void *dst, TUINT32 size)
TUINT32 ReadAlignmentPad()
TUINT8 ReadHunkData(void *dest)
TUINT8 ReadFORM(TFORM *section)
void Close()
Closes the file.
TSIZE BeginForm(const TCHAR *name)
Begin a new form and saves it's info.
TUINT32 WriteAlignmentPad()
Aligns current position to 4.
TTSFO::ERROR Create(const TCHAR *filepath, const TCHAR *magic="TRBF", Endianess endianess=Endianess_Little)
Creates file for writing.
TBOOL CloseHunk(HunkMark *hunkMark)
Closes the hunk.
TSIZE EndForm()
Ends the current form if it exists.
TBOOL OpenHunk(HunkMark *hunkMark, const TCHAR *hunkName)
Opens new hunk.
TUINT32 Write(const T &value)
TUINT32 WriteHunk(TUINT32 hunkName, void *buffer=nullptr, TSIZE bufferSize=0)
Writes a hunk of data.
@ ERROR_NO_FILEINFO_ON_STACK
static void MemClear(void *ptr, TSIZE size)