Wii partition seek bug fix and buffering API

This commit is contained in:
Jack Andersen 2015-07-12 20:28:26 -10:00
parent f30a9302b6
commit 01f269e8e2
2 changed files with 29 additions and 1 deletions

View File

@ -101,6 +101,7 @@ public:
m_name(name) {} m_name(name) {}
inline Kind getKind() const {return m_kind;} inline Kind getKind() const {return m_kind;}
inline const std::string& getName() const {return m_name;} inline const std::string& getName() const {return m_name;}
inline uint64_t size() const {return m_discLength;}
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset=0) const std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset=0) const
{ {
if (m_kind != NODE_FILE) if (m_kind != NODE_FILE)
@ -110,6 +111,17 @@ public:
} }
return m_parent.beginReadStream(m_discOffset + offset); return m_parent.beginReadStream(m_discOffset + offset);
} }
std::unique_ptr<uint8_t[]> getBuf() const
{
if (m_kind != NODE_FILE)
{
throw std::runtime_error("unable to buffer a non-file");
return std::unique_ptr<uint8_t[]>();
}
uint8_t* buf = new uint8_t[m_discLength];
beginReadStream()->read(buf, m_discLength);
return std::unique_ptr<uint8_t[]>(buf);
}
inline std::vector<Node>::iterator rawBegin() const {return m_childrenBegin;} inline std::vector<Node>::iterator rawBegin() const {return m_childrenBegin;}
inline std::vector<Node>::iterator rawEnd() const {return m_childrenEnd;} inline std::vector<Node>::iterator rawEnd() const {return m_childrenEnd;}
@ -121,6 +133,7 @@ public:
: m_it(it) {} : m_it(it) {}
public: public:
inline bool operator!=(const DirectoryIterator& other) {return m_it != other.m_it;} inline bool operator!=(const DirectoryIterator& other) {return m_it != other.m_it;}
inline bool operator==(const DirectoryIterator& other) {return m_it == other.m_it;}
inline DirectoryIterator& operator++() inline DirectoryIterator& operator++()
{ {
if (m_it->m_kind == NODE_DIRECTORY) if (m_it->m_kind == NODE_DIRECTORY)
@ -130,9 +143,24 @@ public:
return *this; return *this;
} }
inline Node& operator*() {return *m_it;} inline Node& operator*() {return *m_it;}
inline Node* operator->() {return &*m_it;}
}; };
inline DirectoryIterator begin() const {return DirectoryIterator(m_childrenBegin);} inline DirectoryIterator begin() const {return DirectoryIterator(m_childrenBegin);}
inline DirectoryIterator end() const {return DirectoryIterator(m_childrenEnd);} inline DirectoryIterator end() const {return DirectoryIterator(m_childrenEnd);}
inline DirectoryIterator find(const std::string& name) const
{
if (m_kind == NODE_DIRECTORY)
{
DirectoryIterator it=begin();
for (; it != end() ; ++it)
{
if (!it->getName().compare(name))
return it;
}
return it;
}
return end();
}
void extractToDirectory(const SystemString& basePath, bool force=false); void extractToDirectory(const SystemString& basePath, bool force=false);
}; };

View File

@ -291,9 +291,9 @@ public:
else else
return; return;
size_t block = m_offset / 0x7c00; size_t block = m_offset / 0x7c00;
m_dio->seek(m_baseOffset + block * 0x8000);
if (block != m_curBlock) if (block != m_curBlock)
{ {
m_dio->seek(m_baseOffset + block * 0x8000);
decryptBlock(); decryptBlock();
m_curBlock = block; m_curBlock = block;
} }