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

View File

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

View File

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