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

49 lines
1.2 KiB
C++
Raw Permalink Normal View History

2022-09-29 08:27:50 -04:00
#include "McDumpDevice.h"
2022-09-30 16:55:25 -04:00
#include <cassert>
#include <cstring>
2023-07-06 11:45:07 -04:00
#include "maybe_unused.h"
2022-09-29 08:27:50 -04:00
#include "MemStream.h"
using namespace Iop;
using namespace Iop::Ioman;
CMcDumpDevice::CMcDumpDevice(DumpContent content)
: m_content(std::move(content))
, m_contentReader(m_content.data(), m_content.size())
, m_dumpReader(m_contentReader)
{
}
Framework::CStream* CMcDumpDevice::GetFile(uint32 flags, const char* path)
{
assert(flags == OPEN_FLAG_RDONLY);
//We don't support subdirs here
2022-10-29 11:33:08 -04:00
if(*path == '/') path++;
2023-07-06 11:45:07 -04:00
FRAMEWORK_MAYBE_UNUSED auto next = strchr(path, '/');
2022-09-29 08:27:50 -04:00
assert(!next);
auto directory = m_dumpReader.ReadRootDirectory();
for(const auto& dirEntry : directory)
{
if(dirEntry.mode & CMcDumpReader::DF_DIRECTORY) continue;
if(!strcmp(dirEntry.name, path))
{
//Got a match
auto fileContents = m_dumpReader.ReadFile(dirEntry.cluster, dirEntry.length);
assert(fileContents.size() == dirEntry.length);
auto stream = new Framework::CMemStream();
stream->Write(fileContents.data(), fileContents.size());
stream->Seek(0, Framework::STREAM_SEEK_SET);
return stream;
}
}
return nullptr;
}
DirectoryIteratorPtr CMcDumpDevice::GetDirectory(const char*)
{
return DirectoryIteratorPtr();
}