reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit dc88a6998363dffce5c11f92bc80d3485fd06234
parent 71b1c40d3ccefe9e3f7b152d94e3d9894861f897
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 27 Feb 2017 14:28:38 -0500

archive: tiny bit of code cleanup

Diffstat:
Msrc/archive.cpp | 15+++++++--------
Msrc/archive.hpp | 4++--
Msrc/filesystem.cpp | 7+++++++
Msrc/filesystem.hpp | 1+
4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/archive.cpp b/src/archive.cpp @@ -34,14 +34,14 @@ #include <zlib/unzip.h> #include <zlib/ioapi.h> -using namespace std; using namespace boost; +using namespace std; static const Path ARCHIVE_TOC = Path("toc"); static const size_t BUFFER_SIZE = 4096; #ifdef _WIN32 -static void *wide_fopen(voidpf opaque, const void *filename, int mode) +static void *wide_fopen(voidpf, const void *filename, int mode) { const wchar_t *fopen_mode = nullptr; @@ -227,7 +227,7 @@ int ArchiveReader::extractFile(const Path &path) throw reapack_error(format("%s: %s") % path.join() % FS::lastError()); } -int ArchiveReader::extractFile(const Path &path, ostream &stream) +int ArchiveReader::extractFile(const Path &path, ostream &stream) noexcept { int status = unzLocateFile(m_zip, path.join('/').c_str(), false); if(status != UNZ_OK) @@ -307,17 +307,16 @@ ArchiveWriter::~ArchiveWriter() int ArchiveWriter::addFile(const Path &path) { - ifstream stream(make_autostring(Path::prefixRoot(path).join()), ios_base::binary); + ifstream stream; - if(stream) + if(FS::open(stream, path)) return addFile(path, stream); else - throw reapack_error(FS::lastError().c_str()); + throw reapack_error(format("%s: %s") % path.join() % FS::lastError()); } -int ArchiveWriter::addFile(const Path &path, istream &stream) +int ArchiveWriter::addFile(const Path &path, istream &stream) noexcept { - const int status = zipOpenNewFileInZip(m_zip, path.join('/').c_str(), nullptr, nullptr, 0, nullptr, 0, nullptr, Z_DEFLATED, Z_DEFAULT_COMPRESSION); diff --git a/src/archive.hpp b/src/archive.hpp @@ -36,7 +36,7 @@ public: ArchiveReader(const auto_string &path); ~ArchiveReader(); int extractFile(const Path &); - int extractFile(const Path &, std::ostream &); + int extractFile(const Path &, std::ostream &) noexcept; private: zipFile m_zip; @@ -47,7 +47,7 @@ public: ArchiveWriter(const auto_string &path); ~ArchiveWriter(); int addFile(const Path &fn); - int addFile(const Path &fn, std::istream &); + int addFile(const Path &fn, std::istream &) noexcept; private: zipFile m_zip; diff --git a/src/filesystem.cpp b/src/filesystem.cpp @@ -46,6 +46,13 @@ FILE *FS::open(const Path &path) #endif } +bool FS::open(ifstream &stream, const Path &path) +{ + const Path &fullPath = Path::prefixRoot(path); + stream.open(make_autostring(fullPath.join()), ios_base::binary); + return stream.good(); +} + bool FS::open(ofstream &stream, const Path &path) { mkdir(path.dirname()); diff --git a/src/filesystem.hpp b/src/filesystem.hpp @@ -25,6 +25,7 @@ class TempPath; namespace FS { FILE *open(const Path &); + bool open(std::ifstream &, const Path &); bool open(std::ofstream &, const Path &); bool write(const Path &, const std::string &); bool rename(const TempPath &);