From 01f269e8e2a55d8b64e1e277d9a1f87f6877c446 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 12 Jul 2015 20:28:26 -1000 Subject: [PATCH] Wii partition seek bug fix and buffering API --- include/NOD/DiscBase.hpp | 28 ++++++++++++++++++++++++++++ lib/DiscWii.cpp | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/NOD/DiscBase.hpp b/include/NOD/DiscBase.hpp index 1494692..61650c2 100644 --- a/include/NOD/DiscBase.hpp +++ b/include/NOD/DiscBase.hpp @@ -101,6 +101,7 @@ public: m_name(name) {} inline Kind getKind() const {return m_kind;} inline const std::string& getName() const {return m_name;} + inline uint64_t size() const {return m_discLength;} std::unique_ptr beginReadStream(uint64_t offset=0) const { if (m_kind != NODE_FILE) @@ -110,6 +111,17 @@ public: } return m_parent.beginReadStream(m_discOffset + offset); } + std::unique_ptr getBuf() const + { + if (m_kind != NODE_FILE) + { + throw std::runtime_error("unable to buffer a non-file"); + return std::unique_ptr(); + } + uint8_t* buf = new uint8_t[m_discLength]; + beginReadStream()->read(buf, m_discLength); + return std::unique_ptr(buf); + } inline std::vector::iterator rawBegin() const {return m_childrenBegin;} inline std::vector::iterator rawEnd() const {return m_childrenEnd;} @@ -121,6 +133,7 @@ public: : m_it(it) {} 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 DirectoryIterator& operator++() { if (m_it->m_kind == NODE_DIRECTORY) @@ -130,9 +143,24 @@ public: return *this; } inline Node& operator*() {return *m_it;} + inline Node* operator->() {return &*m_it;} }; inline DirectoryIterator begin() const {return DirectoryIterator(m_childrenBegin);} 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); }; diff --git a/lib/DiscWii.cpp b/lib/DiscWii.cpp index 81d14de..6ff8efe 100644 --- a/lib/DiscWii.cpp +++ b/lib/DiscWii.cpp @@ -291,9 +291,9 @@ public: else return; size_t block = m_offset / 0x7c00; - m_dio->seek(m_baseOffset + block * 0x8000); if (block != m_curBlock) { + m_dio->seek(m_baseOffset + block * 0x8000); decryptBlock(); m_curBlock = block; }