V-Gears 0
Free Final Fantasy VII engine.
File.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The V-Gears Team
3 *
4 * This file is part of V-Gears
5 *
6 * V-Gears is free software: you can redistribute it and/or modify it under
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, version 3.0 (GPLv3) of the License.
9 *
10 * V-Gears is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#pragma once
17
18#include <OgreString.h>
19#include "common/TypeDefine.h"
20
24class File{
25
26 public:
27
33 File(const Ogre::String& file);
34
40 File(const File* file);
41
49 File(const File* file, u32 offset, u32 length);
50
58 File(const u8* buffer, u32 offset, u32 length);
59
63 virtual ~File();
64
70 void WriteFile(const Ogre::String& file) const;
71
77 const Ogre::String& GetFileName() const;
78
84 u32 GetFileSize() const;
85
93 void GetFileBuffer(
94 u8* buffer, const u32 &start, const u32 &length
95 ) const;
96
102 u8 GetU8(u32 offset) const;
103
111 u16 GetU16LE(u32 offset) const;
112
120 u32 GetU32LE(u32 offset) const;
121
129 u8 readU8();
130
138 u16 readU16LE();
139
147 u32 readU32LE();
148
158
167 void SetOffset(u32 offset);
168
169 protected:
170
175
185
192
197};
Ogre::uint16 u16
Definition: TypeDefine.h:22
Ogre::uint32 u32
Definition: TypeDefine.h:23
Ogre::uint8 u8
Definition: TypeDefine.h:21
Represents a file.
Definition: File.h:24
u8 * buffer_
The file buffer.
Definition: File.h:191
u16 readU16LE()
Reads two bytes from the file (little endian).
Definition: File.cpp:94
Ogre::String file_name_
The file name.
Definition: File.h:174
u32 GetU32LE(u32 offset) const
Retrieves a pointer to a four-byte address in the file.
Definition: File.cpp:80
u16 GetU16LE(u32 offset) const
Retrieves a pointer to a two-byte address in the file.
Definition: File.cpp:76
void GetFileBuffer(u8 *buffer, const u32 &start, const u32 &length) const
Loads a buffer with the file data.
Definition: File.cpp:70
u32 readU32LE()
Reads four bytes from the file (little endian).
Definition: File.cpp:100
const Ogre::String & GetFileName() const
Retrieves the file name.
Definition: File.cpp:66
u32 offset_
Current offset of the file.
Definition: File.h:184
File(const Ogre::String &file)
Opens a file.
Definition: File.cpp:22
u32 buffer_size_
The allocated size of {.
Definition: File.h:196
u32 GetCurrentOffset()
Checks the current offset of the file.
Definition: File.cpp:106
void WriteFile(const Ogre::String &file) const
Writes the contents of the buffer to a file.
Definition: File.cpp:62
u8 GetU8(u32 offset) const
Retrieves a pointer to a byte address in the file.
Definition: File.cpp:74
u8 readU8()
Reads a byte from the file.
Definition: File.cpp:88
virtual ~File()
Destructor.
Definition: File.cpp:60
void SetOffset(u32 offset)
Sets the file offset for reading.
Definition: File.cpp:108
u32 GetFileSize() const
Retrieves the file size.
Definition: File.cpp:68
Ogre::String String
Definition: TypeDefine.h:37