Play-/Source/iop/ioman/HardDiskDevice.cpp

109 lines
2.5 KiB
C++
Raw Permalink Normal View History

2021-01-02 22:26:46 -05:00
#include "HardDiskDevice.h"
#include <cassert>
2021-01-05 12:35:28 -05:00
#include "AppConfig.h"
#include "PathUtils.h"
2021-01-05 17:25:38 -05:00
#include "PS2VM_Preferences.h"
2021-01-02 22:26:46 -05:00
#include "StringUtils.h"
2023-01-03 21:18:18 -05:00
#include "PathDirectoryDevice.h"
#include "PathDirectoryIterator.h"
2021-01-02 22:26:46 -05:00
using namespace Iop::Ioman;
2021-01-05 12:35:28 -05:00
CHardDiskDevice::CHardDiskDevice()
{
m_basePath = CAppConfig::GetInstance().GetPreferencePath(PREF_PS2_HDD_DIRECTORY);
//Seems that FFXI needs the "__common" partition to exist and also needs the "Your Saves" directory
try
{
Framework::PathUtils::EnsurePathExists(m_basePath / "__common/Your Saves");
}
catch(...)
{
//We failed to create it, let's not crash for nothing
}
2021-01-05 12:35:28 -05:00
}
2021-01-02 22:26:46 -05:00
Framework::CStream* CHardDiskDevice::GetFile(uint32 accessType, const char* devicePath)
{
if(accessType & OPEN_FLAG_CREAT)
2021-01-02 22:26:46 -05:00
{
//Create a new partition
auto createParams = StringUtils::Split(devicePath, ',', true);
assert(createParams.size() == 5);
CreatePartition(createParams);
2021-01-02 22:26:46 -05:00
return new CHardDiskPartition();
}
else
{
auto openParams = StringUtils::Split(devicePath, ',', true);
assert(openParams.size() >= 2);
auto partitionPath = m_basePath / openParams[0];
if(fs::exists(partitionPath))
{
return new CHardDiskPartition();
}
else
{
return nullptr;
}
2021-01-02 22:26:46 -05:00
}
}
DirectoryIteratorPtr CHardDiskDevice::GetDirectory(const char* devicePath)
2021-01-02 22:26:46 -05:00
{
return std::make_unique<CPathDirectoryIterator>(m_basePath);
2021-01-02 22:26:46 -05:00
}
2023-01-03 21:18:18 -05:00
DevicePtr CHardDiskDevice::Mount(const char* devicePath)
{
auto mountParams = StringUtils::Split(devicePath, ',', true);
2021-01-06 13:33:36 -05:00
assert(!mountParams.empty());
auto partitionPath = m_basePath / mountParams[0];
if(!fs::exists(partitionPath))
{
throw std::runtime_error("Partition doesn't exist.");
}
2023-01-03 21:18:18 -05:00
auto mountPath = m_basePath / mountParams[0];
return std::make_shared<CPathDirectoryDevice>(mountPath);
}
void CHardDiskDevice::CreatePartition(const std::vector<std::string>& createParams)
{
auto partitionName = createParams[0];
if(partitionName.empty())
{
throw std::runtime_error("Invalid partition name.");
}
auto partitionPath = m_basePath / partitionName;
fs::create_directory(partitionPath);
}
2021-01-02 22:26:46 -05:00
//-----------------------------------------------
//CHardDiskPartition
void CHardDiskPartition::Seek(int64, Framework::STREAM_SEEK_DIRECTION)
{
//Used by FFX
2021-01-02 22:26:46 -05:00
}
uint64 CHardDiskPartition::Read(void*, uint64)
{
throw new std::runtime_error("Not supported.");
}
uint64 CHardDiskPartition::Write(const void*, uint64 size)
2021-01-02 22:26:46 -05:00
{
//FFX writes to partition (PS2ICON3D?)
return size;
2021-01-02 22:26:46 -05:00
}
uint64 CHardDiskPartition::Tell()
{
return 0;
}
bool CHardDiskPartition::IsEOF()
{
return false;
}