Files
ExPkg/expkg/src/BinaryOPT/BinaryReader.h
2025-12-03 17:55:50 +08:00

51 lines
1.2 KiB
C++

//
// Created by sfd on 25-8-4.
//
#ifndef BINARYREADER_H
#define BINARYREADER_H
#include <filesystem>
#include <fstream>
#include <vector>
#include "Core.h"
namespace PKG
{
using pos_type = long long;
class PKG_API BinaryReader
{
public:
BinaryReader() = delete;
explicit BinaryReader(const std::filesystem::path& fileName);
~BinaryReader();
int32_t ReadInt32();
uint32_t ReadUInt32();
float ReadSingle();
char ReadChar();
std::string ReadString(uint32_t length);
std::string ReadNString(int32_t maxLength = -1);
std::string ReadStringFileData(uint32_t length);
void ReadData(std::string& data, uint32_t length);
void ReadData(std::vector<uint8_t>& data, uint32_t length);
void seekg(const pos_type pos) { m_File.seekg(pos); }
pos_type tellg() { return m_File.tellg(); }
std::string GetFilePath() const { return m_FilePath; }
std::string GetFileName() const { return m_FilePath.substr(m_FilePath.find_last_of("\\/") + 1); }
private:
std::ifstream m_File;
std::string m_FilePath;
};
}
#endif //BINARYREADER_H