Removed exceptions

This commit is contained in:
Jack Andersen 2015-07-25 16:44:44 -10:00
parent 9e7e0979bd
commit 7fafe3ce0c
8 changed files with 36 additions and 36 deletions

@ -1 +1 @@
Subproject commit 085920205b71a0a5a9bf710de5794cc136051b2d Subproject commit c61ff288b90a6b4c833d01f62196eb0534bf2860

View File

@ -52,7 +52,8 @@ int main(int argc, char* argv[])
if (!dataPart) if (!dataPart)
return -1; return -1;
dataPart->extractToDirectory(outDir, force); if (!dataPart->extractToDirectory(outDir, force))
return -1;
} }
else if (!strcasecmp(argv[1], _S("make"))) else if (!strcasecmp(argv[1], _S("make")))
{ {

View File

@ -107,7 +107,7 @@ public:
{ {
if (m_kind != NODE_FILE) 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<IPartReadStream>(); return std::unique_ptr<IPartReadStream>();
} }
return m_parent.beginReadStream(m_discOffset + offset); return m_parent.beginReadStream(m_discOffset + offset);
@ -116,7 +116,7 @@ public:
{ {
if (m_kind != NODE_FILE) 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[]>(); return std::unique_ptr<uint8_t[]>();
} }
uint8_t* buf = new uint8_t[m_discLength]; uint8_t* buf = new uint8_t[m_discLength];
@ -163,7 +163,7 @@ public:
return end(); return end();
} }
void extractToDirectory(const SystemString& basePath, bool force=false) const; bool extractToDirectory(const SystemString& basePath, bool force=false) const;
}; };
protected: protected:
uint64_t m_dolOff; uint64_t m_dolOff;
@ -194,7 +194,7 @@ public:
{return beginReadStream(0x2440 + offset);} {return beginReadStream(0x2440 + offset);}
inline const Node& getFSTRoot() const {return m_nodes[0];} inline const Node& getFSTRoot() const {return m_nodes[0];}
inline Node& getFSTRoot() {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 uint64_t getDOLSize() const {return m_dolSz;}
inline std::unique_ptr<uint8_t[]> getDOLBuf() const inline std::unique_ptr<uint8_t[]> getDOLBuf() const

View File

@ -57,7 +57,7 @@ void DiscBase::IPartition::parseDOL(IPartReadStream& s)
m_dolSz = dolSize; 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()); SystemStringView nameView(getName());
SystemString path = basePath + _S("/") + nameView.sys_str(); 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) if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
{ {
SystemUTF8View pathView(path); LogModule.report(LogVisor::Error, _S("unable to mkdir '%s'"), path.c_str());
throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'"); return false;
} }
for (Node& subnode : *this) for (Node& subnode : *this)
subnode.extractToDirectory(path, force); if (!subnode.extractToDirectory(path, force))
return false;
} }
else if (m_kind == NODE_FILE) else if (m_kind == NODE_FILE)
{ {
@ -81,15 +82,16 @@ void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
ws->copyFromDisc(*rs.get(), m_discLength); 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; Sstat theStat;
if (Mkdir(path.c_str(), 0755) && errno != EEXIST) if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
{ {
SystemUTF8View pathView(path); LogModule.report(LogVisor::Error, _S("unable to mkdir '%s'"), path.c_str());
throw std::runtime_error("unable to mkdir '" + pathView.utf8_str() + "'"); return false;
} }
/* Extract Apploader */ /* Extract Apploader */
@ -109,7 +111,7 @@ void DiscBase::IPartition::extractToDirectory(const SystemString& path, bool for
} }
/* Extract Filesystem */ /* Extract Filesystem */
m_nodes[0].extractToDirectory(path, force); return m_nodes[0].extractToDirectory(path, force);
} }
} }

View File

@ -1,5 +1,4 @@
#include <stdio.h> #include <stdio.h>
#include <stdexcept>
#include "NOD/Util.hpp" #include "NOD/Util.hpp"
#include "NOD/IDiscIO.hpp" #include "NOD/IDiscIO.hpp"

View File

@ -1,5 +1,4 @@
#include <stdio.h> #include <stdio.h>
#include <stdexcept>
#include "NOD/Util.hpp" #include "NOD/Util.hpp"
#include "NOD/IDiscIO.hpp" #include "NOD/IDiscIO.hpp"

View File

@ -388,7 +388,7 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio)
else if (part.partType == PartInfo::Part::PART_CHANNEL) else if (part.partType == PartInfo::Part::PART_CHANNEL)
kind = IPartition::PART_CHANNEL; kind = IPartition::PART_CHANNEL;
else 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)); m_partitions.emplace_back(new PartitionWii(*this, kind, part.partDataOff << 2));
} }
} }

View File

@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdexcept>
#include "NOD/Util.hpp" #include "NOD/Util.hpp"
#include "NOD/IFileIO.hpp" #include "NOD/IFileIO.hpp"
@ -50,13 +49,7 @@ public:
fp = fopen(path.c_str(), "wb"); fp = fopen(path.c_str(), "wb");
#endif #endif
if (!fp) if (!fp)
{ LogModule.report(LogVisor::Error, _S("unable to open '%s' for writing"), path.c_str());
#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
}
} }
~WriteStream() {fclose(fp);} ~WriteStream() {fclose(fp);}
uint64_t write(void* buf, uint64_t length) uint64_t write(void* buf, uint64_t length)
@ -69,9 +62,15 @@ public:
uint64_t thisSz = MIN(0x7c00, length); uint64_t thisSz = MIN(0x7c00, length);
uint64_t readSz = discio.read(buf, thisSz); uint64_t readSz = discio.read(buf, thisSz);
if (thisSz != readSz) 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) 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; length -= thisSz;
read += thisSz; read += thisSz;
} }
@ -93,13 +92,7 @@ public:
fp = fopen(path.c_str(), "rb"); fp = fopen(path.c_str(), "rb");
#endif #endif
if (!fp) if (!fp)
{ LogModule.report(LogVisor::Error, _S("unable to open '%s' for reading"), path.c_str());
#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
}
} }
~ReadStream() {fclose(fp);} ~ReadStream() {fclose(fp);}
uint64_t read(void* buf, uint64_t length) uint64_t read(void* buf, uint64_t length)
@ -111,9 +104,15 @@ public:
{ {
uint64_t thisSz = MIN(0x7c00, length); uint64_t thisSz = MIN(0x7c00, length);
if (fread(buf, 1, thisSz, fp) != thisSz) 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) 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; length -= thisSz;
written += thisSz; written += thisSz;
} }