diff --git a/src/openrct2-ui/input/ShortcutManager.cpp b/src/openrct2-ui/input/ShortcutManager.cpp index 4522f336c3..cc12f9c222 100644 --- a/src/openrct2-ui/input/ShortcutManager.cpp +++ b/src/openrct2-ui/input/ShortcutManager.cpp @@ -12,10 +12,10 @@ #include "ShortcutIds.h" #include -#include #include #include #include +#include #include #include #include @@ -246,34 +246,26 @@ std::optional ShortcutManager::ConvertLegacyBinding(uint16_t bind void ShortcutManager::LoadLegacyBindings(const fs::path& path) { constexpr int32_t SUPPORTED_FILE_VERSION = 1; + constexpr int32_t MAX_LEGACY_SHORTCUTS = 85; - auto fs = std::ifstream(path); - if (fs) + auto fs = FileStream(path, FILE_MODE_OPEN); + auto version = fs.ReadValue(); + if (version == SUPPORTED_FILE_VERSION) { - auto br = BinaryReader(&fs); - - uint16_t version{}; - br << version; - - if (version == SUPPORTED_FILE_VERSION) + for (size_t i = 0; i < MAX_LEGACY_SHORTCUTS; i++) { - for (size_t i = 0; i < 85; i++) + auto value = fs.ReadValue(); + auto shortcutId = GetLegacyShortcutId(i); + if (!shortcutId.empty()) { - uint16_t value{}; - br << value; - - auto shortcutId = GetLegacyShortcutId(i); - if (!shortcutId.empty()) + auto shortcut = GetShortcut(shortcutId); + if (shortcut != nullptr) { - auto shortcut = GetShortcut(shortcutId); - if (shortcut != nullptr) + shortcut->Current.clear(); + auto input = ConvertLegacyBinding(value); + if (input) { - shortcut->Current.clear(); - auto input = ConvertLegacyBinding(value); - if (input) - { - shortcut->Current.push_back(std::move(*input)); - } + shortcut->Current.push_back(std::move(*input)); } } } diff --git a/src/openrct2/core/DataSerialiser.h b/src/openrct2/core/DataSerialiser.h index 3a97c35bbd..95622961ae 100644 --- a/src/openrct2/core/DataSerialiser.h +++ b/src/openrct2/core/DataSerialiser.h @@ -12,67 +12,7 @@ #include "DataSerialiserTraits.h" #include "MemoryStream.h" -#include #include -#include - -class BinarySerialiser -{ -private: - std::variant _stream{}; - -public: - BinarySerialiser(std::istream* stream) - : _stream(stream) - { - } - - BinarySerialiser(std::ostream* stream) - : _stream(stream) - { - } - - bool IsReading() const - { - return std::holds_alternative(_stream); - } - - bool IsWriting() const - { - return std::holds_alternative(_stream); - } - - template BinarySerialiser& operator<<(const T& data) - { - if (auto istream = std::get_if(&_stream)) - { - DataSerializerTraits::decode(**istream, const_cast(data)); - } - else if (auto ostream = std::get_if(&_stream)) - { - DataSerializerTraits::encode(**ostream, data); - } - return *this; - } -}; - -class BinaryReader : public BinarySerialiser -{ -public: - BinaryReader(std::istream* stream) - : BinarySerialiser(stream) - { - } -}; - -class BinaryWriter : public BinarySerialiser -{ -public: - BinaryWriter(std::ostream* stream) - : BinarySerialiser(stream) - { - } -}; class DataSerialiser { diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index e8cb94beac..6128404106 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -73,14 +73,6 @@ template struct DataSerializerTraitsIntegral stream->Read(&temp); val = ByteSwapBE(temp); } - static void encode(std::ostream& stream, const T& val) - { - stream.write(reinterpret_cast(&val), sizeof(val)); - } - static void decode(std::istream& stream, T& val) - { - stream.read(reinterpret_cast(&val), sizeof(val)); - } static void log(OpenRCT2::IStream* stream, const T& val) { std::stringstream ss; diff --git a/src/openrct2/core/FileStream.cpp b/src/openrct2/core/FileStream.cpp index 3310c86e53..3a1ff1654b 100644 --- a/src/openrct2/core/FileStream.cpp +++ b/src/openrct2/core/FileStream.cpp @@ -30,6 +30,11 @@ namespace OpenRCT2 { + FileStream::FileStream(const fs::path& path, int32_t fileMode) + : FileStream(path.u8string(), fileMode) + { + } + FileStream::FileStream(const std::string& path, int32_t fileMode) : FileStream(path.c_str(), fileMode) { diff --git a/src/openrct2/core/FileStream.h b/src/openrct2/core/FileStream.h index c002e5bef3..d9fdcffd3d 100644 --- a/src/openrct2/core/FileStream.h +++ b/src/openrct2/core/FileStream.h @@ -10,6 +10,7 @@ #pragma once #include "../common.h" +#include "FileSystem.hpp" #include "IStream.hpp" namespace OpenRCT2 @@ -35,6 +36,7 @@ namespace OpenRCT2 uint64_t _fileSize = 0; public: + FileStream(const fs::path& path, int32_t fileMode); FileStream(const std::string& path, int32_t fileMode); FileStream(const utf8* path, int32_t fileMode); ~FileStream() override;