From 09d2afa91f7781c84c25e989d916957200e63eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 9 May 2018 20:40:56 +0200 Subject: SettingsHandler: Migrate to new filesystem interface Change SettingsHandler to take a buffer instead of assuming that the setting file to read is always on the host filesystem for more flexibility and make it possible to use the new filesystem interface. --- Source/Core/Common/SettingsHandler.cpp | 27 ++++++++------------------- 1 file changed, 8 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 8a0240939b..7663959a20 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -19,8 +19,6 @@ #endif #include "Common/CommonTypes.h" -#include "Common/File.h" -#include "Common/FileUtil.h" #include "Common/SettingsHandler.h" #include "Common/Timer.h" @@ -29,30 +27,21 @@ SettingsHandler::SettingsHandler() Reset(); } -bool SettingsHandler::Open(const std::string& settings_file_path) +SettingsHandler::SettingsHandler(Buffer&& buffer) { - Reset(); - - File::IOFile file{settings_file_path, "rb"}; - if (!file.ReadBytes(m_buffer.data(), m_buffer.size())) - return false; - - Decrypt(); - return true; + SetBytes(std::move(buffer)); } -bool SettingsHandler::Save(const std::string& destination_file_path) const +const SettingsHandler::Buffer& SettingsHandler::GetBytes() const { - if (!File::CreateFullPath(destination_file_path)) - return false; - - File::IOFile file{destination_file_path, "wb"}; - return file.WriteBytes(m_buffer.data(), m_buffer.size()); + return m_buffer; } -const u8* SettingsHandler::GetData() const +void SettingsHandler::SetBytes(SettingsHandler::Buffer&& buffer) { - return m_buffer.data(); + Reset(); + m_buffer = std::move(buffer); + Decrypt(); } const std::string SettingsHandler::GetValue(const std::string& key) -- cgit v1.2.3 From 722d31124ca4a958d658b3c8d2d5dba1cb637ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 10 May 2018 20:34:20 +0200 Subject: SettingsHandler: Fix const correctness --- Source/Core/Common/SettingsHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/SettingsHandler.cpp') diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index 7663959a20..6ce08f6579 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -44,7 +44,7 @@ void SettingsHandler::SetBytes(SettingsHandler::Buffer&& buffer) Decrypt(); } -const std::string SettingsHandler::GetValue(const std::string& key) +std::string SettingsHandler::GetValue(const std::string& key) const { std::string delim = std::string("\r\n"); std::string toFind = delim + key + "="; -- cgit v1.2.3