Permalink
Browse files

IOS/NCD: Migrate to new filesystem interface

A followup for the migration work started in 8317a66
  • Loading branch information...
leoetlino committed Mar 11, 2018
1 parent 89713c5 commit fb1d075330b75b6763d66448e24612eeee73a72d
@@ -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:
@@ -8,55 +8,53 @@
#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
{
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;
}
ResetConfig(fs);
}
File::IOFile(m_path, "wb").WriteBytes(&m_data, sizeof(m_data));
void WiiNetConfig::WriteConfig(FS::FileSystem* fs) const
{
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()
void WiiNetConfig::ResetConfig(FS::FileSystem* fs)
{
if (File::Exists(m_path))
File::Delete(m_path);
fs->Delete(PID_NCD, PID_NCD, CONFIG_PATH);
memset(&m_data, 0, sizeof(m_data));
m_data.connType = ConfigData::IF_WIRED;
m_data.connection[0].flags =
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
@@ -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 @@ class WiiNetConfig final
};
#pragma pack(pop)
std::string m_path;
ConfigData m_data;
};
} // namespace Net

0 comments on commit fb1d075

Please sign in to comment.