V-Gears 0
Free Final Fantasy VII engine.
File Class Reference

Represents a file. More...

#include <File.h>

Inheritance diagram for File:
Collaboration diagram for File:

Public Member Functions

 File (const Ogre::String &file)
 Opens a file. More...
 
 File (const File *file)
 Opens a file. More...
 
 File (const File *file, u32 offset, u32 length)
 Loads a file fragment. More...
 
 File (const u8 *buffer, u32 offset, u32 length)
 Loads a file fragment from a buffer. More...
 
virtual ~File ()
 Destructor. More...
 
void WriteFile (const Ogre::String &file) const
 Writes the contents of the buffer to a file. More...
 
const Ogre::String & GetFileName () const
 Retrieves the file name. More...
 
u32 GetFileSize () const
 Retrieves the file size. More...
 
void GetFileBuffer (u8 *buffer, const u32 &start, const u32 &length) const
 Loads a buffer with the file data. More...
 
u8 GetU8 (u32 offset) const
 Retrieves a pointer to a byte address in the file. More...
 
u16 GetU16LE (u32 offset) const
 Retrieves a pointer to a two-byte address in the file. More...
 
u32 GetU32LE (u32 offset) const
 Retrieves a pointer to a four-byte address in the file. More...
 
u8 readU8 ()
 Reads a byte from the file. More...
 
u16 readU16LE ()
 Reads two bytes from the file (little endian). More...
 
u32 readU32LE ()
 Reads four bytes from the file (little endian). More...
 
u32 GetCurrentOffset ()
 Checks the current offset of the file. More...
 
void SetOffset (u32 offset)
 Sets the file offset for reading. More...
 

Protected Attributes

Ogre::String file_name_
 The file name. More...
 
u32 offset_ = 0
 Current offset of the file. More...
 
u8buffer_
 The file buffer. More...
 
u32 buffer_size_
 The allocated size of {. More...
 

Detailed Description

Represents a file.

Constructor & Destructor Documentation

◆ File() [1/4]

File::File ( const Ogre::String &  file)

Opens a file.

Parameters
[in]filePath to the file.

◆ File() [2/4]

File::File ( const File file)

Opens a file.

Parameters
[in]filePointer to the file.

◆ File() [3/4]

File::File ( const File file,
u32  offset,
u32  length 
)

Loads a file fragment.

Parameters
[in]filePointer to the file.
[in]offsetOffset to the data to load.
[in]lengthLength of the data to load.

◆ File() [4/4]

File::File ( const u8 buffer,
u32  offset,
u32  length 
)

Loads a file fragment from a buffer.

Parameters
[in]bufferPointer to the buffer to load from.
[in]offsetOffset to the data to load.
[in]lengthLength of the data to load.

◆ ~File()

File::~File ( )
virtual

Destructor.

Member Function Documentation

◆ GetCurrentOffset()

u32 File::GetCurrentOffset ( )

Checks the current offset of the file.

Default is 0. Can be set on instantiation with {

See also
File(const File* file, u32 offset, u32 length)} or {
File(const u8* buffer, u32 offset, u32 length)} and advanced with {
readU8}, {
readU16LE} or {
readU32LE}

◆ GetFileBuffer()

void File::GetFileBuffer ( u8 buffer,
const u32 start,
const u32 length 
) const

Loads a buffer with the file data.

Parameters
[out]bufferPointer to the buffer to load.
[in]startOffset to the data to load.
[in]lengthLength of the data to load.

◆ GetFileName()

const Ogre::String & File::GetFileName ( ) const

Retrieves the file name.

Returns
The file name, without path.

◆ GetFileSize()

u32 File::GetFileSize ( ) const

Retrieves the file size.

Returns
File size, in bytes.

◆ GetU16LE()

u16 File::GetU16LE ( u32  offset) const

Retrieves a pointer to a two-byte address in the file.

The data must b considered to be in little endian.

Parameters
[in]offsetThe offset to the requested address.

◆ GetU32LE()

u32 File::GetU32LE ( u32  offset) const

Retrieves a pointer to a four-byte address in the file.

The data must b considered to be in little endian.

Parameters
[in]offsetThe offset to the requested address.

◆ GetU8()

u8 File::GetU8 ( u32  offset) const

Retrieves a pointer to a byte address in the file.

Parameters
[in]offsetThe offset to the requested address.

◆ readU16LE()

u16 File::readU16LE ( )

Reads two bytes from the file (little endian).

Advances the current offset by two bytes.

Returns
Two bytes of data from the current offset of the file.

◆ readU32LE()

u32 File::readU32LE ( )

Reads four bytes from the file (little endian).

Advances the current offset by four byte.

Returns
Four bytes of data from the current offset of the file.

◆ readU8()

u8 File::readU8 ( )

Reads a byte from the file.

Advances the current offset by one byte.

Returns
The data in the byte in the current offset of the file.

◆ SetOffset()

void File::SetOffset ( u32  offset)

Sets the file offset for reading.

If the offset is larger than the file size, the offset will be set to the end of the file

Parameters
[in]offsetThe new offset.

◆ WriteFile()

void File::WriteFile ( const Ogre::String &  file) const

Writes the contents of the buffer to a file.

Parameters
[in]filePath of the file to save

Member Data Documentation

◆ buffer_

u8* File::buffer_
protected

The file buffer.

It contains the file data.

◆ buffer_size_

u32 File::buffer_size_
protected

The allocated size of {.

See also
buffer_}.

◆ file_name_

Ogre::String File::file_name_
protected

The file name.

◆ offset_

u32 File::offset_ = 0
protected

Current offset of the file.

Default is 0. Can be set on instantiation with {

See also
File(const File* file, u32 offset, u32 length)} or {
File(const u8* buffer, u32 offset, u32 length)} and advanced with {
readU8}, {
readU16LE} or {
readU32LE}

The documentation for this class was generated from the following files: