From 865aab3c75b2b941d81a60300c576811f4fad87d Mon Sep 17 00:00:00 2001 From: lltcggie Date: Sat, 26 Dec 2015 18:45:30 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=8C=E4=B8=80=E9=83=A8=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/waifu2x.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index ee0061e..0177497 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -190,7 +190,16 @@ static bool writeFile(boost::iostreams::stream static bool writeFile(const boost::filesystem::path &path, std::vector &buf) { - boost::iostreams::stream os(path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + boost::iostreams::stream os; + + try + { + os.open(path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + } + catch (...) + { + return false; + } return writeFile(os, buf); } @@ -215,14 +224,32 @@ static bool readFile(boost::iostreams::stream static bool readFile(const boost::filesystem::path &path, std::vector &buf) { - boost::iostreams::stream is(path, std::ios_base::in | std::ios_base::binary); + boost::iostreams::stream is; + + try + { + is.open(path, std::ios_base::in | std::ios_base::binary); + } + catch (...) + { + return false; + } return readFile(is, buf); } static Waifu2x::eWaifu2xError readProtoText(const boost::filesystem::path &path, ::google::protobuf::Message* proto) { - boost::iostreams::stream is(path, std::ios_base::in); + boost::iostreams::stream is; + + try + { + is.open(path, std::ios_base::in); + } + catch (...) + { + return Waifu2x::eWaifu2xError_FailedOpenModelFile; + } if (!is) return Waifu2x::eWaifu2xError_FailedOpenModelFile; @@ -274,7 +301,16 @@ static Waifu2x::eWaifu2xError readProtoBinary(const boost::filesystem::path &pat static Waifu2x::eWaifu2xError writeProtoBinary(const ::google::protobuf::Message& proto, const boost::filesystem::path &path) { - boost::iostreams::stream os(path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + boost::iostreams::stream os; + + try + { + os.open(path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + } + catch (...) + { + return Waifu2x::eWaifu2xError_FailedOpenModelFile; + } if (!os) return Waifu2x::eWaifu2xError_FailedWriteModelFile; @@ -721,6 +757,16 @@ Waifu2x::eWaifu2xError Waifu2x::LoadParameterFromJson(boost::shared_ptr is(param_path, std::ios_base::in | std::ios_base::binary); + + try + { + is.open(param_path, std::ios_base::in | std::ios_base::binary); + } + catch (...) + { + return Waifu2x::eWaifu2xError_FailedOpenModelFile; + } + if(!is) return eWaifu2xError_FailedOpenModelFile; @@ -1267,7 +1313,17 @@ Waifu2x::eWaifu2xError Waifu2x::WriteMat(const cv::Mat &im, const boost::filesys } } - boost::iostreams::stream os(output_file, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + boost::iostreams::stream os; + + try + { + os.open(output_file, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + } + catch (...) + { + return Waifu2x::eWaifu2xError_FailedOpenOutputFile; + } + if(!os) return eWaifu2xError_FailedOpenOutputFile;