mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use IStream for IniReader and IniWriter
This commit is contained in:
parent
6e9d22e99d
commit
4dc792bc1d
|
@ -17,6 +17,7 @@
|
|||
#include <memory>
|
||||
#include "../core/Console.hpp"
|
||||
#include "../core/Exception.hpp"
|
||||
#include "../core/FileStream.hpp"
|
||||
#include "../core/Memory.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
|
@ -505,7 +506,8 @@ namespace Config
|
|||
{
|
||||
try
|
||||
{
|
||||
auto reader = std::unique_ptr<IIniReader>(CreateIniReader(path));
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
auto reader = std::unique_ptr<IIniReader>(CreateIniReader(&fs));
|
||||
ReadGeneral(reader.get());
|
||||
ReadInterface(reader.get());
|
||||
ReadSound(reader.get());
|
||||
|
@ -525,7 +527,8 @@ namespace Config
|
|||
{
|
||||
try
|
||||
{
|
||||
auto writer = std::unique_ptr<IIniWriter>(CreateIniWriter(path));
|
||||
auto fs = FileStream(path, FILE_MODE_WRITE);
|
||||
auto writer = std::unique_ptr<IIniWriter>(CreateIniWriter(&fs));
|
||||
WriteGeneral(writer.get());
|
||||
WriteInterface(writer.get());
|
||||
WriteSound(writer.get());
|
||||
|
|
|
@ -60,12 +60,11 @@ private:
|
|||
std::unordered_map<std::string, std::string> _values;
|
||||
|
||||
public:
|
||||
IniReader(const std::string &path)
|
||||
IniReader(IStream * stream)
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
uint64 length = fs.GetLength();
|
||||
uint64 length = stream->GetLength() - stream->GetPosition();
|
||||
_buffer.resize(length);
|
||||
fs.Read(_buffer.data(), length);
|
||||
stream->Read(_buffer.data(), length);
|
||||
|
||||
RemoveBOM();
|
||||
|
||||
|
@ -368,9 +367,9 @@ utf8 * IIniReader::GetCString(const std::string &name, const utf8 * defaultValue
|
|||
return String::Duplicate(szValue.c_str());
|
||||
}
|
||||
|
||||
IIniReader * CreateIniReader(const std::string &path)
|
||||
IIniReader * CreateIniReader(IStream * stream)
|
||||
{
|
||||
return new IniReader(path);
|
||||
return new IniReader(stream);
|
||||
}
|
||||
|
||||
IIniReader * CreateDefaultIniReader()
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "../common.h"
|
||||
#include "ConfigEnum.hpp"
|
||||
|
||||
interface IStream;
|
||||
|
||||
interface IIniReader
|
||||
{
|
||||
virtual ~IIniReader() = default;
|
||||
|
@ -45,5 +47,5 @@ interface IIniReader
|
|||
utf8 * GetCString(const std::string &name, const utf8 * defaultValue) const;
|
||||
};
|
||||
|
||||
IIniReader * CreateIniReader(const std::string &path);
|
||||
IIniReader * CreateIniReader(IStream * stream);
|
||||
IIniReader * CreateDefaultIniReader();
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
class IniWriter final : public IIniWriter
|
||||
{
|
||||
private:
|
||||
FileStream _fs;
|
||||
IStream * _stream;
|
||||
bool _firstSection = false;
|
||||
|
||||
public:
|
||||
IniWriter(const std::string &path)
|
||||
: _fs(path, FILE_MODE_WRITE)
|
||||
IniWriter(IStream * stream)
|
||||
: _stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -87,12 +87,12 @@ private:
|
|||
|
||||
void WriteLine()
|
||||
{
|
||||
_fs.Write(PLATFORM_NEWLINE, String::SizeOf(PLATFORM_NEWLINE));
|
||||
_stream->Write(PLATFORM_NEWLINE, String::SizeOf(PLATFORM_NEWLINE));
|
||||
}
|
||||
|
||||
void WriteLine(const std::string &line)
|
||||
{
|
||||
_fs.Write(line.c_str(), line.size());
|
||||
_stream->Write(line.c_str(), line.size());
|
||||
WriteLine();
|
||||
}
|
||||
};
|
||||
|
@ -102,7 +102,7 @@ void IIniWriter::WriteString(const std::string &name, const utf8 * value)
|
|||
WriteString(name, String::ToStd(value));
|
||||
}
|
||||
|
||||
IIniWriter * CreateIniWriter(const std::string &path)
|
||||
IIniWriter * CreateIniWriter(IStream * stream)
|
||||
{
|
||||
return new IniWriter(path);
|
||||
return new IniWriter(stream);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "../common.h"
|
||||
#include "ConfigEnum.hpp"
|
||||
|
||||
interface IStream;
|
||||
|
||||
interface IIniWriter
|
||||
{
|
||||
virtual ~IIniWriter() = default;
|
||||
|
@ -47,4 +49,4 @@ interface IIniWriter
|
|||
void WriteString(const std::string &name, const utf8 * value);
|
||||
};
|
||||
|
||||
IIniWriter * CreateIniWriter(const std::string &path);
|
||||
IIniWriter * CreateIniWriter(IStream * stream);
|
||||
|
|
Loading…
Reference in New Issue