From 36cdb4a544341e45155ff750c5f67ece71348a52 Mon Sep 17 00:00:00 2001 From: Niel Lebeck Date: Mon, 22 Apr 2024 21:51:09 -0700 Subject: Eliminate SettingsHandler's `SetBytes` and `Reset` methods Also make the `Decrypt` method private. As far as I can tell, the only motivation for exposing the `SetBytes` and `Reset` methods is to allow `CBoot::SetupWiiMemory` to use the same `SettingsHandler` instance to read settings data and then write it back. It seems cleaner to just use two separate instances, and require a given `SettingsHandler` instance to be used for either writing data to a buffer or reading data from a buffer, but not both. A natural next step is to split the `SettingsHandler` class into two classes, one for writing data and one for reading data. I've deferred that change for a future PR. --- Source/Core/Common/SettingsHandler.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index e737a97620..b5c32a2099 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -17,14 +17,14 @@ namespace Common { -SettingsHandler::SettingsHandler() +SettingsHandler::SettingsHandler() : m_buffer{}, m_position{0}, m_key{INITIAL_SEED}, decoded{""} { - Reset(); } -SettingsHandler::SettingsHandler(const Buffer& buffer) +SettingsHandler::SettingsHandler(const Buffer& buffer) : SettingsHandler() { - SetBytes(buffer); + m_buffer = buffer; + Decrypt(); } const SettingsHandler::Buffer& SettingsHandler::GetBytes() const @@ -32,13 +32,6 @@ const SettingsHandler::Buffer& SettingsHandler::GetBytes() const return m_buffer; } -void SettingsHandler::SetBytes(const Buffer& buffer) -{ - Reset(); - m_buffer = buffer; - Decrypt(); -} - std::string SettingsHandler::GetValue(std::string_view key) const { constexpr char delim[] = "\n"; @@ -84,14 +77,6 @@ void SettingsHandler::Decrypt() std::erase(decoded, '\x0d'); } -void SettingsHandler::Reset() -{ - decoded = ""; - m_position = 0; - m_key = INITIAL_SEED; - m_buffer = {}; -} - void SettingsHandler::AddSetting(std::string_view key, std::string_view value) { WriteLine(fmt::format("{}={}\r\n", key, value)); -- cgit v1.2.3