Merge pull request #6807 from leoetlino/boot

Boot: Migrate to new filesystem interface
This commit is contained in:
Léo Lam
2018-05-11 10:41:00 +02:00
committed by GitHub
8 changed files with 124 additions and 84 deletions

View File

@ -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,33 +27,24 @@ SettingsHandler::SettingsHandler()
Reset();
}
bool SettingsHandler::Open(const std::string& settings_file_path)
SettingsHandler::SettingsHandler(Buffer&& buffer)
{
SetBytes(std::move(buffer));
}
const SettingsHandler::Buffer& SettingsHandler::GetBytes() const
{
return m_buffer;
}
void SettingsHandler::SetBytes(SettingsHandler::Buffer&& buffer)
{
Reset();
File::IOFile file{settings_file_path, "rb"};
if (!file.ReadBytes(m_buffer.data(), m_buffer.size()))
return false;
m_buffer = std::move(buffer);
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.data();
}
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 + "=";

View File

@ -21,15 +21,15 @@ public:
INITIAL_SEED = 0x73B5DBFA
};
using Buffer = std::array<u8, SETTINGS_SIZE>;
SettingsHandler();
bool Open(const std::string& settings_file_path);
bool Save(const std::string& destination_file_path) const;
explicit SettingsHandler(Buffer&& buffer);
void AddSetting(const std::string& key, const std::string& value);
const u8* GetData() const;
const std::string GetValue(const std::string& key);
const Buffer& GetBytes() const;
void SetBytes(Buffer&& buffer);
std::string GetValue(const std::string& key) const;
void Decrypt();
void Reset();