From 8e7b420e04cdeb7352f5f66f99af02bb85f6d506 Mon Sep 17 00:00:00 2001 From: Isidor Zeuner Date: Fri, 28 Jul 2023 22:57:09 +0200 Subject: [PATCH] adapt to current file stream API from voxel-io --- src/io.cpp | 13 +++++++------ src/obj2voxel.cpp | 9 +++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/io.cpp b/src/io.cpp index 4d233a8..498d95d 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -10,6 +10,7 @@ #include "voxelio/format/vox.hpp" #include "voxelio/format/xyzrgb.hpp" +#include "voxelio/fstream.hpp" #include "voxelio/filetype.hpp" #include "voxelio/log.hpp" #include "voxelio/stream.hpp" @@ -44,8 +45,8 @@ void writeTriangleAsBinaryToDebugStl(Triangle triangle) void dumpDebugStl(const std::string &path) { u8 buffer[80]{}; - std::optional stlDump = FileOutputStream::open(path); - VXIO_ASSERT(stlDump.has_value()); + std::optional stlDump = FileOutputStream(path, OpenMode::WRITE); + VXIO_ASSERT(stlDump->good()); stlDump->write(buffer, sizeof(buffer)); VXIO_ASSERT_DIVISIBLE(globalDebugStl.size(), 50u); stlDump->writeLittle(static_cast(globalDebugStl.size() / 50)); @@ -394,8 +395,8 @@ std::unique_ptr ITriangleStream::fromObjFile(const std::string std::unique_ptr ITriangleStream::fromStlFile(const std::string &inFile) noexcept { - std::optional stream = FileInputStream::open(inFile); - if (not stream.has_value()) { + std::optional stream = FileInputStream(inFile, OpenMode::READ); + if (not stream->good()) { VXIO_LOG(ERROR, "Failed to open STL file: \"" + inFile + "\""); return nullptr; } @@ -438,8 +439,8 @@ std::optional loadTexture(const std::string &name, const std::string &m { std::string sanitizedName = name; std::replace(sanitizedName.begin(), sanitizedName.end(), '\\', '/'); - std::optional stream = FileInputStream::open(sanitizedName, OpenMode::BINARY); - if (not stream.has_value()) { + std::optional stream = FileInputStream(sanitizedName, OpenMode::BINARY); + if (not stream->good()) { VXIO_LOG(WARNING, "Failed to open texture file \"" + sanitizedName + "\" of material \"" + material + '"'); return std::nullopt; } diff --git a/src/obj2voxel.cpp b/src/obj2voxel.cpp index a5cc53a..7ad1775 100644 --- a/src/obj2voxel.cpp +++ b/src/obj2voxel.cpp @@ -6,6 +6,7 @@ #include "voxelization.hpp" #include "voxelio/format/png.hpp" +#include "voxelio/fstream.hpp" #include "voxelio/stringify.hpp" #include @@ -556,8 +557,8 @@ std::unique_ptr openOutput(obj2voxel_instance &instance) } case IoType::FILE: { - std::optional stream = FileOutputStream::open(output.file.path, OpenMode::BINARY); - if (not stream.has_value()) { + std::optional stream = FileOutputStream(output.file.path, OpenMode::BINARY); + if (not stream->good()) { return nullptr; } @@ -873,8 +874,8 @@ bool obj2voxel_texture_load_from_file(obj2voxel_texture *texture, const char *fi return false; } - std::optional fileStream = FileInputStream::open(file, OpenMode::BINARY); - if (not fileStream.has_value()) { + std::optional fileStream = FileInputStream(file, OpenMode::BINARY); + if (not fileStream->good()) { return false; } std::string error;