summaryrefslogtreecommitdiff
path: root/Source/Core/Common/SettingsHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/Common/SettingsHandler.cpp')
-rw-r--r--Source/Core/Common/SettingsHandler.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp
index 9b5d91e4f5..743e6de269 100644
--- a/Source/Core/Common/SettingsHandler.cpp
+++ b/Source/Core/Common/SettingsHandler.cpp
@@ -18,6 +18,7 @@
#endif
#include "Common/CommonTypes.h"
+#include "Common/FileUtil.h"
#include "Common/SettingsHandler.h"
#include "Common/Timer.h"
@@ -26,9 +27,30 @@ SettingsHandler::SettingsHandler()
Reset();
}
+bool SettingsHandler::Open(const std::string& settings_file_path)
+{
+ Reset();
+
+ File::IOFile file{settings_file_path, "rb"};
+ if (!file.ReadBytes(m_buffer.data(), m_buffer.size()))
+ return false;
+
+ Decrypt();
+ return true;
+}
+
+bool SettingsHandler::Save(const std::string& destination_file_path) 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());
+}
+
const u8* SettingsHandler::GetData() const
{
- return m_buffer;
+ return m_buffer.data();
}
const std::string SettingsHandler::GetValue(const std::string& key)
@@ -62,10 +84,10 @@ const std::string SettingsHandler::GetValue(const std::string& key)
void SettingsHandler::Decrypt()
{
- const u8* str = m_buffer;
+ const u8* str = m_buffer.data();
while (*str != 0)
{
- if (m_position >= SETTINGS_SIZE)
+ if (m_position >= m_buffer.size())
return;
decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
m_position++;
@@ -79,7 +101,7 @@ void SettingsHandler::Reset()
decoded = "";
m_position = 0;
m_key = INITIAL_SEED;
- memset(m_buffer, 0, SETTINGS_SIZE);
+ m_buffer = {};
}
void SettingsHandler::AddSetting(const std::string& key, const std::string& value)
@@ -102,7 +124,7 @@ void SettingsHandler::AddSetting(const std::string& key, const std::string& valu
void SettingsHandler::WriteByte(u8 b)
{
- if (m_position >= SETTINGS_SIZE)
+ if (m_position >= m_buffer.size())
return;
m_buffer[m_position] = b ^ m_key;