This commit is contained in:
2025-08-06 13:29:28 +08:00
commit 957a372209
230 changed files with 43801 additions and 0 deletions

View File

@ -0,0 +1,51 @@
//
// Created by sfd on 25-8-4.
//
#include "BinaryWriter.h"
#include <filesystem>
#include <fstream>
#include <iostream>
namespace PKG
{
BinaryWriter::BinaryWriter(const std::filesystem::path& fileName, const std::ios_base::openmode optMode)
{
m_FilePath = fileName.string();
const std::filesystem::path path(fileName.parent_path());
m_File.open(m_FilePath, optMode);
if (!m_File.is_open() && !std::filesystem::exists(path))
{
std::filesystem::create_directories(path);
m_File.open(m_FilePath, optMode);
if (!m_File.is_open())
std::cerr << "cound not create file: " << m_FilePath << std::endl;
}
}
BinaryWriter::~BinaryWriter()
{
if (!m_File.is_open())
close();
}
void BinaryWriter::WriteBytes(const std::string& data, const uint32_t size)
{
if (size == 0)
m_File.write(data.data(), data.size());
else
m_File.write(data.data(), size);
}
void BinaryWriter::WriteString(const std::string& str)
{
m_File.write(str.c_str(), str.size());
}
void BinaryWriter::close()
{
m_File.close();
}
}