diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 1528b9681c..503a473ca2 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -665,17 +665,17 @@ void fs::file::xfail() const fmt::throw_exception("Unexpected fs::error %s", g_tls_error); } -bool fs::file::open(const std::string& path, bs_t mode) +fs::file::file(const std::string& path, bs_t mode) { if (auto device = get_virtual_device(path)) { if (auto&& _file = device->open(path, mode)) { m_file = std::move(_file); - return true; + return; } - return false; + return; } #ifdef _WIN32 @@ -695,7 +695,7 @@ bool fs::file::open(const std::string& path, bs_t mode) if (test(mode & fs::excl)) { g_tls_error = error::inval; - return false; + return; } disp = test(mode & fs::trunc) ? TRUNCATE_EXISTING : OPEN_EXISTING; @@ -706,7 +706,7 @@ bool fs::file::open(const std::string& path, bs_t mode) if (handle == INVALID_HANDLE_VALUE) { g_tls_error = to_error(GetLastError()); - return false; + return; } class windows_file final : public file_base @@ -827,7 +827,7 @@ bool fs::file::open(const std::string& path, bs_t mode) if (fd == -1) { g_tls_error = to_error(errno); - return false; + return; } class unix_file final : public file_base @@ -913,8 +913,6 @@ bool fs::file::open(const std::string& path, bs_t mode) m_file = std::make_unique(fd); #endif - - return true; } fs::file::file(const void* ptr, std::size_t size) diff --git a/Utilities/File.h b/Utilities/File.h index f05405309d..e85050c0c6 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -156,17 +156,19 @@ namespace fs file() = default; // Open file with specified mode - explicit file(const std::string& path, bs_t mode = ::fs::read) - { - open(path, mode); - } - - // Open file with specified mode - bool open(const std::string& path, bs_t mode = ::fs::read); + explicit file(const std::string& path, bs_t mode = ::fs::read); // Open memory for read explicit file(const void* ptr, std::size_t size); + // Open file with specified args (forward to constructor) + template + bool open(Args&&... args) + { + *this = fs::file(std::forward(args)...); + return m_file.operator bool(); + } + // Check whether the handle is valid (opened file) explicit operator bool() const {