settings file and save/restore ui state

This commit is contained in:
2019-04-14 18:03:41 +02:00
parent ada1afbac2
commit a8d475fbfb
15 changed files with 596 additions and 38 deletions

View File

@@ -1,7 +1,6 @@
#include "pch.h"
#include "binary_stream.h"
#include "asset.h"
BinaryStreamReader::~BinaryStreamReader()
{
@@ -17,6 +16,17 @@ void BinaryStreamReader::init(uint8_t* data_ptr, size_t size, ByteOrder byte_ord
m_swap = byte_order == ByteOrder::Host ? false : byte_order != sys_order();
}
bool BinaryStreamReader::load(const std::string& path, ByteOrder byte_order /*= ByteOrder::Host*/)
{
if (m_asset.open(path.c_str()))
{
m_asset.read_all();
init(m_asset.m_data, m_asset.m_len, byte_order);
return true;
}
return false;
}
size_t BinaryStreamReader::pos()
{
return std::distance(m_ptr, m_cur);
@@ -198,6 +208,17 @@ void BinaryStreamWriter::init(ByteOrder byte_order /*= ByteOrder::Host*/)
m_swap = byte_order == ByteOrder::Host ? false : byte_order != sys_order();
}
bool BinaryStreamWriter::save(const std::string& path) const
{
std::ofstream f(path, std::ios::binary);
if (f.good())
{
f.write((char*)m_data.data(), m_data.size());
return true;
}
return false;
}
void BinaryStreamWriter::skip(size_t bytes, uint8_t fill /*= 0*/)
{
m_data.resize(m_data.size() + bytes);
@@ -334,5 +355,6 @@ void BinaryStreamWriter::wrle(std::vector<uint8_t> data)
void BinaryStreamWriter::wkey_or_string(std::string s)
{
assert(s.size() > 0);
wstring(s);
}