From 7fafe3ce0c14f9e244bb47572f5448e82b597a68 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 25 Jul 2015 16:44:44 -1000 Subject: [PATCH] Removed exceptions --- LogVisor | 2 +- driver/main.cpp | 3 ++- include/NOD/DiscBase.hpp | 8 ++++---- lib/DiscBase.cpp | 18 ++++++++++-------- lib/DiscIOISO.cpp | 1 - lib/DiscIOWBFS.cpp | 1 - lib/DiscWii.cpp | 2 +- lib/FileIOFILE.cpp | 37 ++++++++++++++++++------------------- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/LogVisor b/LogVisor index 0859202..c61ff28 160000 --- a/LogVisor +++ b/LogVisor @@ -1 +1 @@ -Subproject commit 085920205b71a0a5a9bf710de5794cc136051b2d +Subproject commit c61ff288b90a6b4c833d01f62196eb0534bf2860 diff --git a/driver/main.cpp b/driver/main.cpp index 5139711..60d9bf3 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -52,7 +52,8 @@ int main(int argc, char* argv[]) if (!dataPart) return -1; - dataPart->extractToDirectory(outDir, force); + if (!dataPart->extractToDirectory(outDir, force)) + return -1; } else if (!strcasecmp(argv[1], _S("make"))) { diff --git a/include/NOD/DiscBase.hpp b/include/NOD/DiscBase.hpp index 678903f..29d9b08 100644 --- a/include/NOD/DiscBase.hpp +++ b/include/NOD/DiscBase.hpp @@ -107,7 +107,7 @@ public: { if (m_kind != NODE_FILE) { - throw std::runtime_error("unable to stream a non-file"); + LogModule.report(LogVisor::Error, "unable to stream a non-file %s", m_name.c_str()); return std::unique_ptr(); } return m_parent.beginReadStream(m_discOffset + offset); @@ -116,7 +116,7 @@ public: { if (m_kind != NODE_FILE) { - throw std::runtime_error("unable to buffer a non-file"); + LogModule.report(LogVisor::Error, "unable to buffer a non-file %s", m_name.c_str()); return std::unique_ptr(); } uint8_t* buf = new uint8_t[m_discLength]; @@ -163,7 +163,7 @@ public: return end(); } - void extractToDirectory(const SystemString& basePath, bool force=false) const; + bool extractToDirectory(const SystemString& basePath, bool force=false) const; }; protected: uint64_t m_dolOff; @@ -194,7 +194,7 @@ public: {return beginReadStream(0x2440 + offset);} inline const Node& getFSTRoot() const {return m_nodes[0];} inline Node& getFSTRoot() {return m_nodes[0];} - void extractToDirectory(const SystemString& path, bool force=false); + bool extractToDirectory(const SystemString& path, bool force=false); inline uint64_t getDOLSize() const {return m_dolSz;} inline std::unique_ptr getDOLBuf() const diff --git a/lib/DiscBase.cpp b/lib/DiscBase.cpp index 6eb6dbb..c1ac373 100644 --- a/lib/DiscBase.cpp +++ b/lib/DiscBase.cpp @@ -57,7 +57,7 @@ void DiscBase::IPartition::parseDOL(IPartReadStream& s) m_dolSz = dolSize; } -void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath, bool force) const +bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath, bool force) const { SystemStringView nameView(getName()); SystemString path = basePath + _S("/") + nameView.sys_str(); @@ -65,11 +65,12 @@ void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath { if (Mkdir(path.c_str(), 0755) && errno != EEXIST) { - SystemUTF8View pathView(path); - throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'"); + LogModule.report(LogVisor::Error, _S("unable to mkdir '%s'"), path.c_str()); + return false; } for (Node& subnode : *this) - subnode.extractToDirectory(path, force); + if (!subnode.extractToDirectory(path, force)) + return false; } else if (m_kind == NODE_FILE) { @@ -81,15 +82,16 @@ void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath ws->copyFromDisc(*rs.get(), m_discLength); } } + return true; } -void DiscBase::IPartition::extractToDirectory(const SystemString& path, bool force) +bool DiscBase::IPartition::extractToDirectory(const SystemString& path, bool force) { Sstat theStat; if (Mkdir(path.c_str(), 0755) && errno != EEXIST) { - SystemUTF8View pathView(path); - throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'"); + LogModule.report(LogVisor::Error, _S("unable to mkdir '%s'"), path.c_str()); + return false; } /* Extract Apploader */ @@ -109,7 +111,7 @@ void DiscBase::IPartition::extractToDirectory(const SystemString& path, bool for } /* Extract Filesystem */ - m_nodes[0].extractToDirectory(path, force); + return m_nodes[0].extractToDirectory(path, force); } } diff --git a/lib/DiscIOISO.cpp b/lib/DiscIOISO.cpp index 15ca169..59e7e0f 100644 --- a/lib/DiscIOISO.cpp +++ b/lib/DiscIOISO.cpp @@ -1,5 +1,4 @@ #include -#include #include "NOD/Util.hpp" #include "NOD/IDiscIO.hpp" diff --git a/lib/DiscIOWBFS.cpp b/lib/DiscIOWBFS.cpp index cfddd88..0202dd5 100644 --- a/lib/DiscIOWBFS.cpp +++ b/lib/DiscIOWBFS.cpp @@ -1,5 +1,4 @@ #include -#include #include "NOD/Util.hpp" #include "NOD/IDiscIO.hpp" diff --git a/lib/DiscWii.cpp b/lib/DiscWii.cpp index f4fda4c..735c541 100644 --- a/lib/DiscWii.cpp +++ b/lib/DiscWii.cpp @@ -388,7 +388,7 @@ DiscWii::DiscWii(std::unique_ptr&& dio) else if (part.partType == PartInfo::Part::PART_CHANNEL) kind = IPartition::PART_CHANNEL; else - throw std::runtime_error("Invalid partition type"); + LogModule.report(LogVisor::FatalError, "invalid partition type %s", part.partType); m_partitions.emplace_back(new PartitionWii(*this, kind, part.partDataOff << 2)); } } diff --git a/lib/FileIOFILE.cpp b/lib/FileIOFILE.cpp index 73c3359..7a4250d 100644 --- a/lib/FileIOFILE.cpp +++ b/lib/FileIOFILE.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "NOD/Util.hpp" #include "NOD/IFileIO.hpp" @@ -50,13 +49,7 @@ public: fp = fopen(path.c_str(), "wb"); #endif if (!fp) - { -#if NOD_UCS2 - throw std::runtime_error("Unable to open '" + WideToUTF8(path) + "' for writing"); -#else - throw std::runtime_error("Unable to open '" + path + "' for writing"); -#endif - } + LogModule.report(LogVisor::Error, _S("unable to open '%s' for writing"), path.c_str()); } ~WriteStream() {fclose(fp);} uint64_t write(void* buf, uint64_t length) @@ -69,9 +62,15 @@ public: uint64_t thisSz = MIN(0x7c00, length); uint64_t readSz = discio.read(buf, thisSz); if (thisSz != readSz) - throw std::runtime_error("unable to read enough from disc"); + { + LogModule.report(LogVisor::Error, "unable to read enough from disc"); + return read; + } if (fwrite(buf, 1, readSz, fp) != readSz) - throw std::runtime_error("unable to write in file"); + { + LogModule.report(LogVisor::Error, "unable to write in file"); + return read; + } length -= thisSz; read += thisSz; } @@ -93,13 +92,7 @@ public: fp = fopen(path.c_str(), "rb"); #endif if (!fp) - { -#if NOD_UCS2 - throw std::runtime_error("Unable to open '" + WideToUTF8(path) + "' for reading"); -#else - throw std::runtime_error("Unable to open '" + path + "' for reading"); -#endif - } + LogModule.report(LogVisor::Error, _S("unable to open '%s' for reading"), path.c_str()); } ~ReadStream() {fclose(fp);} uint64_t read(void* buf, uint64_t length) @@ -111,9 +104,15 @@ public: { uint64_t thisSz = MIN(0x7c00, length); if (fread(buf, 1, thisSz, fp) != thisSz) - throw std::runtime_error("unable to read enough from file"); + { + LogModule.report(LogVisor::Error, "unable to read enough from file"); + return written; + } if (discio.write(buf, thisSz) != thisSz) - throw std::runtime_error("unable to write enough to disc"); + { + LogModule.report(LogVisor::Error, "unable to write enough to disc"); + return written; + } length -= thisSz; written += thisSz; }