|
| 1 | +/***************************************************************************** |
| 2 | + * |
| 3 | + * PROJECT: Multi Theft Auto |
| 4 | + * LICENSE: See LICENSE in the top level directory |
| 5 | + * FILE: Client/mods/deathmatch/logic/CFileReader.cpp |
| 6 | + * |
| 7 | + * Multi Theft Auto is available from http://www.multitheftauto.com/ |
| 8 | + * |
| 9 | + *****************************************************************************/ |
| 10 | + |
1 | 11 | #include <StdInc.h>
|
2 | 12 | #include <fstream>
|
3 | 13 |
|
4 | 14 | CFileReader::CFileReader(void)
|
5 | 15 | {
|
6 |
| - u32BytesReadFromBuffer = 0; |
| 16 | + m_u32BytesReadFromBuffer = 0; |
7 | 17 | }
|
8 | 18 |
|
9 | 19 | void CFileReader::FreeFileReaderMemory(void)
|
10 | 20 | {
|
11 |
| - std::vector<char>().swap(vecFileDataBuffer); |
12 |
| - u32BytesReadFromBuffer = 0; |
| 21 | + std::vector<char>().swap(m_vecFileDataBuffer); |
| 22 | + m_u32BytesReadFromBuffer = 0; |
13 | 23 | }
|
14 | 24 |
|
15 | 25 | void CFileReader::ReadBytes(void* pDestination, const std::uint32_t u32BytesToRead)
|
16 | 26 | {
|
17 |
| - const std::uint32_t u32ReadOffset = u32BytesReadFromBuffer; |
18 |
| - u32BytesReadFromBuffer += u32BytesToRead; |
19 |
| - memcpy(pDestination, &vecFileDataBuffer[u32ReadOffset], u32BytesToRead); |
| 27 | + const std::uint32_t u32ReadOffset = m_u32BytesReadFromBuffer; |
| 28 | + m_u32BytesReadFromBuffer += u32BytesToRead; |
| 29 | + memcpy(pDestination, &m_vecFileDataBuffer[u32ReadOffset], u32BytesToRead); |
20 | 30 | }
|
21 | 31 |
|
22 | 32 | void CFileReader::ReadStringNullTerminated(char* pDestination, const std::uint32_t u32BytesToRead)
|
23 | 33 | {
|
24 |
| - const std::uint32_t u32ReadOffset = u32BytesReadFromBuffer; |
25 |
| - u32BytesReadFromBuffer += u32BytesToRead; |
26 |
| - memcpy(pDestination, &vecFileDataBuffer[u32ReadOffset], u32BytesToRead); |
| 34 | + const std::uint32_t u32ReadOffset = m_u32BytesReadFromBuffer; |
| 35 | + m_u32BytesReadFromBuffer += u32BytesToRead; |
| 36 | + memcpy(pDestination, &m_vecFileDataBuffer[u32ReadOffset], u32BytesToRead); |
27 | 37 | *(pDestination + (u32BytesToRead - 1)) = '\0';
|
28 | 38 | }
|
29 | 39 |
|
30 | 40 | void CFileReader::SkipBytes(const std::uint32_t u32BytesToSkip)
|
31 | 41 | {
|
32 |
| - u32BytesReadFromBuffer += u32BytesToSkip; |
| 42 | + m_u32BytesReadFromBuffer += u32BytesToSkip; |
33 | 43 | }
|
34 | 44 |
|
35 | 45 | bool CFileReader::LoadFileToMemory(const SString& strFilePath)
|
36 | 46 | {
|
37 | 47 | std::ifstream fileStream(strFilePath, std::ios::binary | std::ios::ate);
|
38 |
| - std::streamsize iFileSize = fileStream.tellg(); |
39 |
| - if (iFileSize == eIFSTREAM::SIZE_ERROR) |
| 48 | + std::streamsize m_iFileSize = fileStream.tellg(); |
| 49 | + if (m_iFileSize == eIFSTREAM::SIZE_ERROR) |
40 | 50 | {
|
41 | 51 | return false;
|
42 | 52 | }
|
43 | 53 |
|
44 | 54 | fileStream.seekg(0, std::ios::beg);
|
45 |
| - vecFileDataBuffer.reserve(static_cast<size_t>(iFileSize)); |
46 |
| - if (fileStream.read(vecFileDataBuffer.data(), iFileSize)) |
| 55 | + m_vecFileDataBuffer.reserve(static_cast<size_t>(m_iFileSize)); |
| 56 | + if (fileStream.read(m_vecFileDataBuffer.data(), m_iFileSize)) |
47 | 57 | {
|
48 | 58 | return true;
|
49 | 59 | }
|
|
0 commit comments