20 bool File::Open(
const std::string& filename,
const std::string& mode) {
24 std::ios_base::openmode streamMode = std::ios_base::in;
25 if (mode.find(
'w') != std::string::npos) {
26 streamMode = std::ios_base::out;
28 if (mode.find(
'b') != std::string::npos) {
29 streamMode |= std::ios_base::binary;
33 m_fileStream.open(filename, streamMode);
34 if (!m_fileStream.is_open()) {
35 std::cerr <<
"Failed to open file: " << filename << std::endl;
44 if (m_fileStream.is_open()) {
50 if (!m_fileStream.is_open()) {
51 std::cerr <<
"File is not open for reading." << std::endl;
55 std::stringstream buffer;
56 buffer << m_fileStream.rdbuf();
61 if (!m_fileStream.is_open()) {
62 std::cerr <<
"File is not open for reading." << std::endl;
67 m_fileStream.seekg(0, std::ios::end);
68 std::streampos fileSize = m_fileStream.tellg();
69 m_fileStream.seekg(0, std::ios::beg);
72 std::vector<unsigned char> data(fileSize);
73 m_fileStream.read(
reinterpret_cast<char*
>(data.data()), fileSize);
78 if (!m_fileStream.is_open()) {
79 std::cerr <<
"File is not open for writing." << std::endl;
83 m_fileStream << content;
84 return m_fileStream.good();
88 if (!m_fileStream.is_open()) {
89 std::cerr <<
"File is not open for writing." << std::endl;
93 m_fileStream.write(
reinterpret_cast<const char*
>(data.data()), data.size());
94 return m_fileStream.good();
98 return ExistsImpl(filename);
102 bool File::ExistsImpl(
const std::string& filename) {
104 DWORD attribs = GetFileAttributesA(filename.c_str());
105 return (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY));
108 return (stat(filename.c_str(), &buffer) == 0);
static bool Exists(const std::string &filename)
std::vector< unsigned char > ReadAllBytes()
bool WriteAllText(const std::string &content)
bool Open(const std::string &filename, const std::string &mode)
std::string ReadAllText()
bool WriteAllBytes(const std::vector< unsigned char > &data)
Root namespace for everything the engine exposes.