/* Copyright <2018-2024> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef REPERTORY_INCLUDE_UTILS_FILE_HPP_ #define REPERTORY_INCLUDE_UTILS_FILE_HPP_ #include "utils/config.hpp" #include "utils/path.hpp" namespace repertory::utils::file { #if defined(PROJECT_ENABLE_LIBDSM) [[nodiscard]] auto smb_create_and_validate_relative_path(std::string_view smb_path, std::string_view rel_path) -> std::string; [[nodiscard]] auto smb_create_relative_path(std::string_view smb_path) -> std::string; [[nodiscard]] auto smb_create_search_path(std::string_view smb_path) -> std::string; [[nodiscard]] auto smb_create_smb_path(std::string_view smb_path, std::string_view rel_path) -> std::string; [[nodiscard]] auto smb_get_parent_path(std::string_view smb_path) -> std::string; [[nodiscard]] auto smb_get_root_path(std::string_view smb_path) -> std::string; [[nodiscard]] auto smb_get_unc_path(std::string_view smb_path) -> std::string; [[nodiscard]] auto smb_get_uri_path(std::string_view smb_path) -> std::string; [[nodiscard]] auto smb_get_uri_path(std::string_view smb_path, std::string_view user, std::string_view password) -> std::string; [[nodiscard]] auto smb_parent_is_same(std::string_view smb_path1, std::string_view smb_path2) -> bool; #endif // defined(PROJECT_ENABLE_LIBDSM) struct i_fs_item { using fs_item_t = std::unique_ptr; enum class time_types { access, creation, modified, write, }; virtual ~i_fs_item() = default; [[nodiscard]] virtual auto exists() const -> bool = 0; [[nodiscard]] virtual auto get_path() const -> std::string = 0; [[nodiscard]] virtual auto get_time(time_types type) const -> std::uint64_t = 0; [[nodiscard]] virtual auto is_directory_item() const -> bool = 0; [[nodiscard]] virtual auto move_to(std::string_view new_path) -> bool = 0; [[nodiscard]] virtual auto move_to(std::wstring_view new_path) -> bool { return move_to(utils::string::to_utf8(new_path)); } [[nodiscard]] virtual auto remove() -> bool = 0; public: [[nodiscard]] virtual operator bool() const = 0; protected: i_fs_item() noexcept = default; i_fs_item(const i_fs_item &) noexcept = default; i_fs_item(i_fs_item &&) noexcept = default; auto operator=(i_fs_item &&) noexcept -> i_fs_item & = default; auto operator=(const i_fs_item &) noexcept -> i_fs_item & = default; }; struct i_file : public i_fs_item { using fs_file_t = std::unique_ptr; virtual ~i_file() = default; virtual void close() = 0; virtual void flush() const = 0; [[nodiscard]] virtual auto get_handle() const -> native_handle = 0; [[nodiscard]] virtual auto get_read_buffer_size() const -> std::uint32_t = 0; [[nodiscard]] auto is_directory_item() const -> bool override { return false; } [[nodiscard]] virtual auto is_read_only() const -> bool = 0; [[nodiscard]] virtual auto read(data_buffer &data, std::uint64_t offset, std::size_t *total_read = nullptr) -> bool { return read(data.data(), data.size(), offset, total_read); } [[nodiscard]] virtual auto read(unsigned char *data, std::size_t to_read, std::uint64_t offset, std::size_t *total_read = nullptr) -> bool = 0; [[nodiscard]] virtual auto read_all(data_buffer &data, std::uint64_t offset, std::size_t *total_read = nullptr) -> bool; virtual auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t = 0; [[nodiscard]] virtual auto size() const -> std::uint64_t = 0; [[nodiscard]] virtual auto truncate() -> bool { return truncate(0U); } [[nodiscard]] virtual auto truncate(std::size_t size) -> bool = 0; [[nodiscard]] virtual auto write(const data_buffer &data, std::uint64_t offset, std::size_t *total_written = nullptr) -> bool { return write(data.data(), data.size(), offset, total_written); } [[nodiscard]] virtual auto write(const unsigned char *data, std::size_t to_write, std::size_t offset, std::size_t *total_written = nullptr) -> bool = 0; protected: i_file() noexcept = default; i_file(const i_file &) noexcept = default; i_file(i_file &&) noexcept = default; auto operator=(i_file &&) noexcept -> i_file & = default; auto operator=(const i_file &) noexcept -> i_file & = default; }; class file final : public i_file { public: // [[nodiscard]] static auto // attach_file(native_handle handle, // bool read_only = false) -> fs_file_t; [[nodiscard]] static auto open_file(std::string_view path, bool read_only = false) -> fs_file_t; [[nodiscard]] static auto open_file(std::wstring_view path, bool read_only = false) -> fs_file_t { return open_file(utils::string::to_utf8(path), read_only); } [[nodiscard]] static auto open_or_create_file(std::string_view path, bool read_only = false) -> fs_file_t; [[nodiscard]] static auto open_or_create_file(std::wstring_view path, bool read_only = false) -> fs_file_t { return open_or_create_file(utils::string::to_utf8(path), read_only); } public: file() noexcept = default; file(std::string_view path) : file_(nullptr), path_(utils::path::absolute(path)) {} file(std::wstring_view path) : file_(nullptr), path_(utils::path::absolute(utils::string::to_utf8(path))) {} private: file(file_t file_ptr, std::string_view path, bool read_only) : file_(std::move(file_ptr)), path_(path), read_only_(read_only) {} public: file(const file &) = delete; file(file &&move_file) noexcept : file_(std::move(move_file.file_)), path_(std::move(move_file.path_)), read_only_(move_file.read_only_) #if defined(_WIN32) , mtx_(std::move(move_file.mtx_)) #endif // defined(_WIN32) { } ~file() override { close(); } private: file_t file_; std::string path_; bool read_only_{false}; #if defined(_WIN32) mutable std::unique_ptr mtx_{ new std::recursive_mutex(), }; #endif // defined(_WIN32) private: std::atomic_uint32_t read_buffer_size{65536U}; private: void open(); public: void close() override; [[nodiscard]] auto exists() const -> bool override; void flush() const override; [[nodiscard]] auto get_handle() const -> native_handle override; [[nodiscard]] auto get_path() const -> std::string override { return path_; } [[nodiscard]] auto get_read_buffer_size() const -> std::uint32_t override { return read_buffer_size; } [[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override; [[nodiscard]] auto is_read_only() const -> bool override { return read_only_; }; [[nodiscard]] auto move_to(std::string_view new_path) -> bool override; [[nodiscard]] auto read(unsigned char *data, std::size_t to_read, std::uint64_t offset, std::size_t *total_read = nullptr) -> bool override; [[nodiscard]] auto remove() -> bool override; auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override { read_buffer_size = size; return read_buffer_size; } [[nodiscard]] auto size() const -> std::uint64_t override; [[nodiscard]] auto truncate(std::size_t size) -> bool override; [[nodiscard]] auto write(const unsigned char *data, std::size_t to_write, std::size_t offset, std::size_t *total_written = nullptr) -> bool override; public: auto operator=(const file &) noexcept -> file & = delete; auto operator=(file &&move_file) noexcept -> file & { if (&move_file != this) { file_ = std::move(move_file.file_); path_ = std::move(move_file.path_); read_only_ = move_file.read_only_; #if defined(_WIN32) mtx_ = std::move(move_file.mtx_); #endif // defined(_WIN32) } return *this; } [[nodiscard]] operator bool() const override { return file_ != nullptr; } }; #if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) class enc_file final : public i_file { public: [[nodiscard]] static auto attach_file(fs_file_t file) -> fs_file_t; public: enc_file() noexcept = default; protected: enc_file(fs_file_t file); public: enc_file(const enc_file &) = delete; enc_file(enc_file &&move_file) noexcept : file_(std::move(move_file.file_)) {} ~enc_file() override { close(); } private: fs_file_t file_; public: void close() override; [[nodiscard]] auto exists() const -> bool override { return file_->exists(); } void flush() const override; [[nodiscard]] auto get_handle() const -> native_handle override { return file_->get_handle(); } [[nodiscard]] auto get_path() const -> std::string override { return file_->get_path(); } [[nodiscard]] auto get_read_buffer_size() const -> std::uint32_t override { return file_->get_read_buffer_size(); } [[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override; [[nodiscard]] auto is_read_only() const -> bool override { return file_->is_read_only(); }; [[nodiscard]] auto move_to(std::string_view new_path) -> bool override; [[nodiscard]] auto read(unsigned char *data, std::size_t to_read, std::uint64_t offset, std::size_t *total_read = nullptr) -> bool override; [[nodiscard]] auto remove() -> bool override; auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override { return file_->set_read_buffer_size(size); } [[nodiscard]] auto size() const -> std::uint64_t override; [[nodiscard]] auto truncate(std::size_t size) -> bool override; [[nodiscard]] auto write(const unsigned char *data, std::size_t to_write, std::size_t offset, std::size_t *total_written = nullptr) -> bool override; public: [[nodiscard]] operator bool() const override { return static_cast(*file_); } auto operator=(const file &) noexcept -> enc_file & = delete; auto operator=(enc_file &&move_file) noexcept -> enc_file & { if (&move_file != this) { file_ = std::move(move_file.file_); } return *this; } }; #endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) class thread_file final : public i_file { public: // [[nodiscard]] static auto // attach_file(native_handle handle, // bool read_only = false) -> fs_file_t; [[nodiscard]] static auto attach_file(fs_file_t file) -> fs_file_t; [[nodiscard]] static auto open_file(std::string_view path, bool read_only = false) -> fs_file_t; [[nodiscard]] static auto open_file(std::wstring_view path, bool read_only = false) -> fs_file_t { return open_file(utils::string::to_utf8(path), read_only); } [[nodiscard]] static auto open_or_create_file(std::string_view path, bool read_only = false) -> fs_file_t; [[nodiscard]] static auto open_or_create_file(std::wstring_view path, bool read_only = false) -> fs_file_t { return open_or_create_file(utils::string::to_utf8(path), read_only); } public: thread_file() noexcept = default; thread_file(std::string_view path) : file_(new file(path)) {} thread_file(std::wstring_view path) : file_(new file(utils::string::to_utf8(path))) {} protected: thread_file(fs_file_t file); public: thread_file(const thread_file &) = delete; thread_file(thread_file &&move_file) noexcept : file_(std::move(move_file.file_)) {} ~thread_file() override { close(); } private: fs_file_t file_; public: void close() override; [[nodiscard]] auto exists() const -> bool override { return file_->exists(); } void flush() const override; [[nodiscard]] auto get_handle() const -> native_handle override { return file_->get_handle(); } [[nodiscard]] auto get_path() const -> std::string override { return file_->get_path(); } [[nodiscard]] auto get_read_buffer_size() const -> std::uint32_t override { return file_->get_read_buffer_size(); } [[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override; [[nodiscard]] auto is_read_only() const -> bool override { return file_->is_read_only(); }; [[nodiscard]] auto move_to(std::string_view new_path) -> bool override; [[nodiscard]] auto read(unsigned char *data, std::size_t to_read, std::uint64_t offset, std::size_t *total_read = nullptr) -> bool override; [[nodiscard]] auto remove() -> bool override; auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override { return file_->set_read_buffer_size(size); } [[nodiscard]] auto size() const -> std::uint64_t override; [[nodiscard]] auto truncate(std::size_t size) -> bool override; [[nodiscard]] auto write(const unsigned char *data, std::size_t to_write, std::size_t offset, std::size_t *total_written = nullptr) -> bool override; public: [[nodiscard]] operator bool() const override { return static_cast(*file_); } auto operator=(const file &) noexcept -> thread_file & = delete; auto operator=(thread_file &&move_file) noexcept -> thread_file & { if (&move_file != this) { file_ = std::move(move_file.file_); } return *this; } }; struct i_directory : public i_fs_item { using fs_directory_t = std::unique_ptr; using fs_file_t = i_file::fs_file_t; virtual ~i_directory() = default; [[nodiscard]] virtual auto count(bool recursive = false) const -> std::uint64_t = 0; [[nodiscard]] virtual auto create_directory(std::string_view path) const -> fs_directory_t = 0; [[nodiscard]] virtual auto create_file(std::string_view file_name, bool read_only) const -> fs_file_t = 0; [[nodiscard]] auto is_directory_item() const -> bool override { return true; } [[nodiscard]] virtual auto get_directory(std::string_view path) const -> fs_directory_t = 0; [[nodiscard]] virtual auto get_directories() const -> std::vector = 0; [[nodiscard]] virtual auto get_file(std::string_view path) const -> fs_file_t = 0; [[nodiscard]] virtual auto get_files() const -> std::vector = 0; [[nodiscard]] virtual auto get_items() const -> std::vector = 0; [[nodiscard]] virtual auto remove_recursively() -> bool = 0; [[nodiscard]] virtual auto size(bool recursive = false) const -> std::uint64_t = 0; protected: i_directory() noexcept = default; i_directory(const i_directory &) noexcept = default; i_directory(i_directory &&) noexcept = default; auto operator=(i_directory &&) noexcept -> i_directory & = default; auto operator=(const i_directory &) noexcept -> i_directory & = default; }; class directory final : public i_directory { public: using directory_t = std::unique_ptr; directory() noexcept = default; directory(std::string_view path) : path_(utils::path::absolute(path)) {} directory(std::wstring_view path) : path_(utils::path::absolute(utils::string::to_utf8(path))) {} directory(const directory &) noexcept = delete; directory(directory &&move_dir) noexcept = default; ~directory() override = default; private: std::string path_; public: [[nodiscard]] auto count(bool recursive = false) const -> std::uint64_t override; [[nodiscard]] auto create_directory(std::string_view path) const -> fs_directory_t override; [[nodiscard]] auto create_file(std::string_view file_name, bool read_only) const -> fs_file_t override; [[nodiscard]] auto exists() const -> bool override; [[nodiscard]] auto get_directory(std::string_view path) const -> fs_directory_t override; [[nodiscard]] auto get_directories() const -> std::vector override; [[nodiscard]] auto get_file(std::string_view path) const -> fs_file_t override; [[nodiscard]] auto get_files() const -> std::vector override; [[nodiscard]] auto get_items() const -> std::vector override; [[nodiscard]] auto get_path() const -> std::string override { return path_; } [[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override; [[nodiscard]] auto move_to(std::string_view new_path) -> bool override; [[nodiscard]] auto remove() -> bool override; [[nodiscard]] auto remove_recursively() -> bool override; [[nodiscard]] auto size(bool recursive = false) const -> std::uint64_t override; public: auto operator=(const directory &) noexcept -> directory & = delete; auto operator=(directory &&move_dir) noexcept -> directory & = default; [[nodiscard]] operator bool() const override { return exists(); } }; #if defined(PROJECT_ENABLE_LIBDSM) #define SMB_MOD_RW2 \ (SMB_MOD_READ | SMB_MOD_WRITE | SMB_MOD_READ_EXT | SMB_MOD_WRITE_EXT | \ SMB_MOD_READ_ATTR | SMB_MOD_WRITE_ATTR | SMB_MOD_READ_CTL) class smb_file final : public i_file { public: smb_file() = default; smb_file(std::uint64_t access_time, std::uint64_t creation_time, std::optional fd, std::uint64_t modified_time, std::string path, smb_session_t session, std::string_view share_name, smb_tid tid, std::uint64_t size, std::uint64_t write_time) : access_time_(access_time), creation_time_(creation_time), fd_(std::move(fd)), modified_time_(modified_time), path_(std::move(path)), session_(std::move(session)), share_name_(share_name), size_(size), tid_(tid), write_time_(write_time) {} smb_file(const smb_file &) = delete; smb_file(smb_file &&f) noexcept : access_time_(f.access_time_), creation_time_(f.creation_time_), fd_(std::move(f.fd_)), modified_time_(f.modified_time_), path_(std::move(f.path_)), read_buffer_size(f.get_read_buffer_size()), read_only_(f.read_only_), session_(std::move(f.session_)), share_name_(std::move(f.share_name_)), size_(f.size_), tid_(f.tid_), write_time_(f.write_time_) {} ~smb_file() override { close(); } private: std::uint64_t access_time_; std::uint64_t creation_time_; std::optional fd_; std::uint64_t modified_time_; std::string path_; std::atomic_uint32_t read_buffer_size{65536U}; bool read_only_; smb_session_t session_; std::string share_name_; std::uint64_t size_; smb_tid tid_; std::uint64_t write_time_; public: void close() override; [[nodiscard]] auto exists() const -> bool override; void flush() const override; [[nodiscard]] auto get_handle() const -> native_handle override { return INVALID_HANDLE_VALUE; } [[nodiscard]] auto get_path() const -> std::string override { return path_; } [[nodiscard]] auto get_read_buffer_size() const -> std::uint32_t override { return read_buffer_size; } [[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override { switch (type) { case time_types::access: return access_time_; case time_types::creation: return creation_time_; case time_types::modified: return modified_time_; case time_types::write: return write_time_; } } [[nodiscard]] auto get_unc_path() const -> std::string { return smb_get_unc_path(path_); } [[nodiscard]] auto get_uri_path() const -> std::string { return smb_get_uri_path(path_); } [[nodiscard]] auto get_uri_path(std::string_view user, std::string_view password) const -> std::string { return smb_get_uri_path(path_, user, password); } [[nodiscard]] auto is_read_only() const -> bool override { return read_only_; }; [[nodiscard]] auto move_to(std::string_view new_path) -> bool override; [[nodiscard]] auto open(bool read_only) -> bool; [[nodiscard]] auto read(unsigned char *data, std::size_t to_read, std::uint64_t offset, std::size_t *total_read = nullptr) -> bool override; [[nodiscard]] auto remove() -> bool override; auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override { read_buffer_size = size; return read_buffer_size; } [[nodiscard]] auto size() const -> std::uint64_t override { return size_; } [[nodiscard]] auto truncate(std::size_t size) -> bool override; [[nodiscard]] auto write(const unsigned char *data, std::size_t to_write, std::size_t offset, std::size_t *total_written = nullptr) -> bool override; public: auto operator=(const smb_file &) noexcept -> smb_file & = delete; auto operator=(smb_file &&move_file) noexcept -> smb_file & { if (this != &move_file) { access_time_ = move_file.access_time_; creation_time_ = move_file.creation_time_; fd_ = std::move(move_file.fd_); modified_time_ = move_file.modified_time_; path_ = std::move(move_file.path_); read_buffer_size = move_file.get_read_buffer_size(); read_only_ = move_file.read_only_; session_ = std::move(move_file.session_); share_name_ = std::move(move_file.share_name_); size_ = move_file.size_; tid_ = move_file.tid_; write_time_ = move_file.write_time_; } return *this; } [[nodiscard]] operator bool() const override { return fd_.has_value(); } }; class smb_directory final : public i_directory { public: using smb_directory_t = std::unique_ptr; [[nodiscard]] static auto open(std::string_view host, std::string_view user, std::string_view password, std::string_view share_name) -> smb_directory_t; [[nodiscard]] static auto open(std::wstring_view host, std::wstring_view user, std::wstring_view password, std::wstring_view share_name) -> smb_directory_t; public: smb_directory() noexcept = default; smb_directory(const smb_directory &) noexcept = delete; smb_directory(smb_directory &&) noexcept = default; ~smb_directory() override = default; private: smb_directory(std::string path, smb_session_t session, std::string_view share_name, smb_tid tid) : path_(std::move(path)), session_(std::move(session)), share_name_(share_name), tid_(tid) {} private: std::string path_{}; smb_session_t session_{}; std::string share_name_{}; smb_tid tid_{}; public: [[nodiscard]] auto count(bool recursive = false) const -> std::uint64_t override; [[nodiscard]] auto create_directory(std::string_view path) const -> fs_directory_t override; [[nodiscard]] auto create_file(std::string_view file_name, bool read_only) const -> fs_file_t override; [[nodiscard]] auto exists() const -> bool override; [[nodiscard]] auto get_directory(std::string_view path) const -> fs_directory_t override; [[nodiscard]] auto get_directories() const -> std::vector override; [[nodiscard]] auto get_file(std::string_view path) const -> fs_file_t override; [[nodiscard]] auto get_files() const -> std::vector override; [[nodiscard]] auto get_items() const -> std::vector override; [[nodiscard]] auto get_path() const -> std::string override { return path_; } [[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override; [[nodiscard]] auto get_unc_path() const -> std::string { return smb_get_unc_path(path_); } [[nodiscard]] auto get_uri_path() const -> std::string { return smb_get_uri_path(path_); } [[nodiscard]] auto get_uri_path(std::string_view user, std::string_view password) const -> std::string { return smb_get_uri_path(path_, user, password); } [[nodiscard]] auto move_to(std::string_view new_path) -> bool override; [[nodiscard]] auto remove() -> bool override; [[nodiscard]] auto remove_recursively() -> bool override; [[nodiscard]] auto size(bool recursive = false) const -> std::uint64_t override; public: auto operator=(const smb_directory &) noexcept -> smb_directory & = delete; auto operator=(smb_directory &&move_dir) noexcept -> smb_directory & = default; [[nodiscard]] operator bool() const override { return session_ != nullptr; } }; #endif // defined(PROJECT_ENABLE_LIBDSM) [[nodiscard]] auto create_directories(std::string_view path) -> bool; [[nodiscard]] auto create_directories(std::wstring_view path) -> bool; [[nodiscard]] auto directory_exists_in_path(std::string_view path, std::string_view sub_directory) -> bool; [[nodiscard]] auto directory_exists_in_path(std::wstring_view path, std::wstring_view sub_directory) -> bool; [[nodiscard]] auto get_file_size(std::string_view path, std::uint64_t &file_size) -> bool; [[nodiscard]] auto get_file_size(std::wstring_view path, std::uint64_t &file_size) -> bool; [[nodiscard]] auto file_exists_in_path(std::string_view path, std::string_view file_name) -> bool; [[nodiscard]] auto file_exists_in_path(std::wstring_view path, std::wstring_view file_name) -> bool; [[nodiscard]] auto is_directory(std::string_view path) -> bool; [[nodiscard]] auto is_directory(std::wstring_view path) -> bool; [[nodiscard]] auto is_file(std::string_view path) -> bool; [[nodiscard]] auto is_file(std::wstring_view path) -> bool; [[nodiscard]] auto remove_directory(std::string_view path, bool recursive = false) -> bool; [[nodiscard]] auto remove_directory(std::wstring_view path, bool recursive = false) -> bool; #if defined(PROJECT_ENABLE_JSON) #if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) [[nodiscard]] auto read_json_file(std::string_view path, nlohmann::json &data, std::optional password = std::nullopt) -> bool; [[nodiscard]] auto read_json_file( std::wstring_view path, nlohmann::json &data, std::optional password = std::nullopt) -> bool; [[nodiscard]] auto write_json_file( std::string_view path, const nlohmann::json &data, std::optional password = std::nullopt) -> bool; [[nodiscard]] auto write_json_file( std::wstring_view path, const nlohmann::json &data, std::optional password = std::nullopt) -> bool; #else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) [[nodiscard]] auto read_json_file(std::string_view path, nlohmann::json &data) -> bool; [[nodiscard]] auto read_json_file(std::wstring_view path, nlohmann::json &data) -> bool; [[nodiscard]] auto write_json_file(std::string_view path, const nlohmann::json &data) -> bool; [[nodiscard]] auto write_json_file(std::wstring_view path, const nlohmann::json &data) -> bool; #endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST) #endif // defined(PROJECT_ENABLE_JSON) template inline auto directory_exists_in_path_t( std::basic_string_view path, std::basic_string_view sub_directory) -> bool { return is_directory(utils::path::combine(path, {sub_directory})); } template inline auto file_exists_in_path_t( std::basic_string_view path, std::basic_string_view file_name) -> bool { return is_file(utils::path::combine(path, {file_name})); } } // namespace repertory::utils::file #endif // REPERTORY_INCLUDE_UTILS_FILE_HPP_