mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 07:21:14 +01:00
properly open/close the file to avoid rapid open/close cycles
ES_OPENCONTENT and ES_CLOSECONTENT now call Open and Close respectively, as the old code did.
This commit is contained in:
parent
8a6d9e1e0b
commit
a449ef4e11
@ -220,7 +220,7 @@ u32 CWII_IPC_HLE_Device_es::OpenTitleContent(u32 CFD, u64 TitleID, u16 Index)
|
||||
Access.m_Size = pContent->m_Size;
|
||||
Access.m_TitleID = TitleID;
|
||||
|
||||
|
||||
pContent->m_Data->Open();
|
||||
|
||||
m_ContentAccessMap[CFD] = Access;
|
||||
return CFD;
|
||||
@ -425,6 +425,14 @@ IPCCommandResult CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
|
||||
return GetDefaultReply();
|
||||
}
|
||||
|
||||
const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(itr->second.m_TitleID);
|
||||
// ContentLoader should never be invalid; we shouldn't be here if ES_OPENCONTENT failed before.
|
||||
if (ContentLoader.IsValid())
|
||||
{
|
||||
const DiscIO::SNANDContent* pContent = ContentLoader.GetContentByIndex(itr->second.m_Index);
|
||||
pContent->m_Data->Close();
|
||||
}
|
||||
|
||||
m_ContentAccessMap.erase(itr);
|
||||
|
||||
Memory::Write_U32(0, _CommandAddress + 0x4);
|
||||
|
@ -91,34 +91,49 @@ std::string CSharedContent::AddSharedContent(const u8* hash)
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
void CNANDContentDataFile::EnsureOpen()
|
||||
{
|
||||
if (!m_file)
|
||||
m_file = std::make_unique<File::IOFile>(m_filename, "rb");
|
||||
else if (!m_file->IsOpen())
|
||||
m_file->Open(m_filename, "rb");
|
||||
}
|
||||
void CNANDContentDataFile::Open()
|
||||
{
|
||||
EnsureOpen();
|
||||
}
|
||||
const std::vector<u8> CNANDContentDataFile::Get()
|
||||
{
|
||||
std::vector<u8> result;
|
||||
File::IOFile file(m_filename, "rb");
|
||||
if (!file.IsGood())
|
||||
EnsureOpen();
|
||||
if (!m_file->IsGood())
|
||||
return result;
|
||||
|
||||
u64 size = file.GetSize();
|
||||
u64 size = m_file->GetSize();
|
||||
if (size == 0)
|
||||
return result;
|
||||
|
||||
result.resize(size);
|
||||
file.ReadBytes(result.data(), result.size());
|
||||
m_file->ReadBytes(result.data(), result.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CNANDContentDataFile::GetRange(u32 start, u32 size, u8* buffer)
|
||||
{
|
||||
File::IOFile file(m_filename, "rb");
|
||||
if (!file.IsGood())
|
||||
EnsureOpen();
|
||||
if (!m_file->IsGood())
|
||||
return false;
|
||||
|
||||
if (!file.Seek(start, SEEK_SET))
|
||||
if (!m_file->Seek(start, SEEK_SET))
|
||||
return false;
|
||||
|
||||
return file.ReadBytes(buffer, static_cast<size_t>(size));
|
||||
return m_file->ReadBytes(buffer, static_cast<size_t>(size));
|
||||
}
|
||||
void CNANDContentDataFile::Close()
|
||||
{
|
||||
if (m_file && m_file->IsOpen())
|
||||
m_file->Close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,8 +20,10 @@ bool AddTicket(u64 title_id, const std::vector<u8>& ticket);
|
||||
class CNANDContentData
|
||||
{
|
||||
public:
|
||||
virtual void Open() { };
|
||||
virtual const std::vector<u8> Get() = 0;
|
||||
virtual bool GetRange(u32 start, u32 size, u8* buffer) = 0;
|
||||
virtual void Close() { };
|
||||
};
|
||||
|
||||
class CNANDContentDataFile final : public CNANDContentData
|
||||
@ -29,10 +31,15 @@ class CNANDContentDataFile final : public CNANDContentData
|
||||
public:
|
||||
CNANDContentDataFile(const std::string& filename) : m_filename(filename) { };
|
||||
|
||||
void Open() override;
|
||||
const std::vector<u8> Get() override;
|
||||
bool GetRange(u32 start, u32 size, u8* buffer) override;
|
||||
void Close() override;
|
||||
private:
|
||||
void EnsureOpen();
|
||||
|
||||
const std::string m_filename;
|
||||
std::unique_ptr<File::IOFile> m_file;
|
||||
};
|
||||
class CNANDContentDataBuffer final : public CNANDContentData
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user