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.
This commit is contained in:
parent
6e9d0ff6de
commit
09d2afa91f
|
@ -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)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -21,14 +21,14 @@ 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 Buffer& GetBytes() const;
|
||||
void SetBytes(Buffer&& buffer);
|
||||
const std::string GetValue(const std::string& key);
|
||||
|
||||
void Decrypt();
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/IOS/ES/ES.h"
|
||||
#include "Core/IOS/ES/Formats.h"
|
||||
#include "Core/IOS/FS/FileSystem.h"
|
||||
#include "Core/IOS/IOS.h"
|
||||
#include "Core/IOS/Uids.h"
|
||||
#include "Core/PowerPC/PowerPC.h"
|
||||
|
||||
#include "DiscIO/Enums.h"
|
||||
|
@ -225,15 +227,22 @@ bool CBoot::SetupWiiMemory()
|
|||
|
||||
SettingsHandler gen;
|
||||
std::string serno;
|
||||
const std::string settings_file_path(
|
||||
Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + "/" WII_SETTING);
|
||||
if (File::Exists(settings_file_path) && gen.Open(settings_file_path))
|
||||
{
|
||||
serno = gen.GetValue("SERNO");
|
||||
gen.Reset();
|
||||
const std::string settings_file_path(Common::GetTitleDataPath(Titles::SYSTEM_MENU) +
|
||||
"/" WII_SETTING);
|
||||
|
||||
File::Delete(settings_file_path);
|
||||
const auto fs = IOS::HLE::GetIOS()->GetFS();
|
||||
{
|
||||
SettingsHandler::Buffer data;
|
||||
const auto file = fs->OpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, settings_file_path,
|
||||
IOS::HLE::FS::Mode::Read);
|
||||
if (file && file->Read(data.data(), data.size()))
|
||||
{
|
||||
gen.SetBytes(std::move(data));
|
||||
serno = gen.GetValue("SERNO");
|
||||
gen.Reset();
|
||||
}
|
||||
}
|
||||
fs->Delete(IOS::SYSMENU_UID, IOS::SYSMENU_GID, settings_file_path);
|
||||
|
||||
if (serno.empty() || serno == "000000000")
|
||||
{
|
||||
|
@ -258,14 +267,17 @@ bool CBoot::SetupWiiMemory()
|
|||
gen.AddSetting("VIDEO", region_setting.video);
|
||||
gen.AddSetting("GAME", region_setting.game);
|
||||
|
||||
if (!gen.Save(settings_file_path))
|
||||
constexpr IOS::HLE::FS::Mode rw_mode = IOS::HLE::FS::Mode::ReadWrite;
|
||||
const auto settings_file = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID,
|
||||
settings_file_path, rw_mode, rw_mode, rw_mode);
|
||||
if (!settings_file || !settings_file->Write(gen.GetBytes().data(), gen.GetBytes().size()))
|
||||
{
|
||||
PanicAlertT("SetupWiiMemory: Can't create setting.txt file");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write the 256 byte setting.txt to memory.
|
||||
Memory::CopyToEmu(0x3800, gen.GetData(), SettingsHandler::SETTINGS_SIZE);
|
||||
Memory::CopyToEmu(0x3800, gen.GetBytes().data(), gen.GetBytes().size());
|
||||
|
||||
INFO_LOG(BOOT, "Setup Wii Memory...");
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
#include "Core/CommonTitles.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/IOS/FS/FileSystem.h"
|
||||
#include "Core/IOS/Network/Socket.h"
|
||||
#include "Core/IOS/Uids.h"
|
||||
|
||||
namespace IOS
|
||||
{
|
||||
|
@ -82,20 +84,23 @@ IPCCommandResult NetKDRequest::IOCtl(const IOCtlRequest& request)
|
|||
INFO_LOG(IOS_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_GENERATED_USER_ID");
|
||||
if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_INITIAL)
|
||||
{
|
||||
const std::string settings_file_path(
|
||||
Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) +
|
||||
"/" WII_SETTING);
|
||||
SettingsHandler gen;
|
||||
const std::string settings_file_path =
|
||||
Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/" WII_SETTING;
|
||||
std::string area, model;
|
||||
bool got_settings = false;
|
||||
|
||||
if (File::Exists(settings_file_path) && gen.Open(settings_file_path))
|
||||
const auto fs = m_ios.GetFS();
|
||||
if (const auto file = fs->OpenFile(PID_KD, PID_KD, settings_file_path, FS::Mode::Read))
|
||||
{
|
||||
area = gen.GetValue("AREA");
|
||||
model = gen.GetValue("MODEL");
|
||||
got_settings = true;
|
||||
SettingsHandler::Buffer data;
|
||||
if (file->Read(data.data(), data.size()))
|
||||
{
|
||||
const SettingsHandler gen{std::move(data)};
|
||||
area = gen.GetValue("AREA");
|
||||
model = gen.GetValue("MODEL");
|
||||
}
|
||||
}
|
||||
if (got_settings)
|
||||
|
||||
if (!area.empty() && !model.empty())
|
||||
{
|
||||
u8 area_code = GetAreaCode(area);
|
||||
u8 id_ctr = config.IdGen();
|
||||
|
|
Loading…
Reference in New Issue