IOS/NCD: Migrate to new filesystem interface

A followup for the migration work started in 8317a66
This commit is contained in:
Léo Lam 2018-03-11 18:28:36 +01:00
parent 89713c5889
commit fb1d075330
3 changed files with 34 additions and 31 deletions

View file

@ -21,6 +21,7 @@ namespace Device
{
NetNCDManage::NetNCDManage(Kernel& ios, const std::string& device_name) : Device(ios, device_name)
{
config.ReadConfig(ios.GetFS().get());
}
IPCCommandResult NetNCDManage::IOCtlV(const IOCtlVRequest& request)
@ -51,14 +52,14 @@ IPCCommandResult NetNCDManage::IOCtlV(const IOCtlVRequest& request)
case IOCTLV_NCD_READCONFIG:
INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_READCONFIG");
config.ReadConfig();
config.ReadConfig(m_ios.GetFS().get());
config.WriteToMem(request.io_vectors.at(0).address);
break;
case IOCTLV_NCD_WRITECONFIG:
INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_WRITECONFIG");
config.ReadFromMem(request.in_vectors.at(0).address);
config.WriteConfig();
config.WriteConfig(m_ios.GetFS().get());
break;
case IOCTLV_NCD_GETLINKSTATUS:

View file

@ -8,10 +8,10 @@
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Core/HW/Memmap.h"
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/IOS.h"
namespace IOS
{
@ -19,36 +19,34 @@ namespace HLE
{
namespace Net
{
WiiNetConfig::WiiNetConfig()
{
m_path = File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_SYSCONF_DIR "/net/02/config.dat";
ReadConfig();
}
static const std::string CONFIG_PATH = "/shared2/sys/net/02/config.dat";
void WiiNetConfig::ReadConfig()
{
if (!File::IOFile(m_path, "rb").ReadBytes(&m_data, sizeof(m_data)))
ResetConfig();
}
WiiNetConfig::WiiNetConfig() = default;
void WiiNetConfig::WriteConfig() const
void WiiNetConfig::ReadConfig(FS::FileSystem* fs)
{
if (!File::Exists(m_path))
{
if (!File::CreateFullPath(File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_SYSCONF_DIR
"/net/02/"))
{
ERROR_LOG(IOS_NET, "Failed to create directory for network config file");
}
const auto file = fs->OpenFile(PID_NCD, PID_NCD, CONFIG_PATH, FS::Mode::Read);
if (file && file->Read(&m_data, 1))
return;
}
File::IOFile(m_path, "wb").WriteBytes(&m_data, sizeof(m_data));
ResetConfig(fs);
}
void WiiNetConfig::ResetConfig()
void WiiNetConfig::WriteConfig(FS::FileSystem* fs) const
{
if (File::Exists(m_path))
File::Delete(m_path);
fs->CreateFullPath(PID_NCD, PID_NCD, CONFIG_PATH, 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite,
FS::Mode::ReadWrite);
fs->CreateFile(PID_NCD, PID_NCD, CONFIG_PATH, 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite,
FS::Mode::ReadWrite);
const auto file = fs->OpenFile(PID_NCD, PID_NCD, CONFIG_PATH, FS::Mode::Write);
if (!file || !file->Write(&m_data, 1))
ERROR_LOG(IOS_NET, "Failed to write config");
}
void WiiNetConfig::ResetConfig(FS::FileSystem* fs)
{
fs->Delete(PID_NCD, PID_NCD, CONFIG_PATH);
memset(&m_data, 0, sizeof(m_data));
m_data.connType = ConfigData::IF_WIRED;
@ -56,7 +54,7 @@ void WiiNetConfig::ResetConfig()
ConnectionSettings::WIRED_IF | ConnectionSettings::DNS_DHCP | ConnectionSettings::IP_DHCP |
ConnectionSettings::CONNECTION_TEST_OK | ConnectionSettings::CONNECTION_SELECTED;
WriteConfig();
WriteConfig(fs);
}
void WiiNetConfig::WriteToMem(const u32 address) const

View file

@ -11,6 +11,11 @@ namespace IOS
{
namespace HLE
{
namespace FS
{
class FileSystem;
}
namespace Net
{
#pragma pack(push, 1)
@ -105,9 +110,9 @@ class WiiNetConfig final
public:
WiiNetConfig();
void ReadConfig();
void WriteConfig() const;
void ResetConfig();
void ReadConfig(FS::FileSystem* fs);
void WriteConfig(FS::FileSystem* fs) const;
void ResetConfig(FS::FileSystem* fs);
void WriteToMem(u32 address) const;
void ReadFromMem(u32 address);
@ -135,7 +140,6 @@ private:
};
#pragma pack(pop)
std::string m_path;
ConfigData m_data;
};
} // namespace Net