updated build system
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory::utils::collection {
|
||||
@@ -69,24 +70,75 @@ inline auto includes(const col_t &collection,
|
||||
collection.end();
|
||||
}
|
||||
|
||||
template <typename val_t, typename string_t>
|
||||
[[nodiscard]] inline auto
|
||||
from_hex_string_t(std::basic_string_view<typename string_t::value_type> str,
|
||||
val_t &val) -> bool {
|
||||
template <typename val_t>
|
||||
[[nodiscard]] inline auto from_hex_string_t(std::string_view str,
|
||||
val_t &val) -> bool {
|
||||
static constexpr const auto base16{16};
|
||||
|
||||
val.clear();
|
||||
if (not(str.length() % 2U)) {
|
||||
for (std::size_t i = 0U; i < str.length(); i += 2U) {
|
||||
val.emplace_back(static_cast<typename val_t::value_type>(
|
||||
std::strtol(string_t{str.substr(i, 2U)}.c_str(), nullptr, base16)));
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
val.clear();
|
||||
|
||||
std::string fmt_val{str};
|
||||
utils::string::trim(fmt_val);
|
||||
if (fmt_val.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fmt_val = utils::string::to_lower(fmt_val);
|
||||
if (utils::string::begins_with(fmt_val, "0x")) {
|
||||
fmt_val = fmt_val.substr(2U);
|
||||
}
|
||||
|
||||
if (fmt_val.empty()) {
|
||||
throw std::runtime_error("hex string is invalid|" + std::string{str});
|
||||
}
|
||||
|
||||
if (fmt_val.length() % 2U) {
|
||||
fmt_val = '0' + fmt_val;
|
||||
}
|
||||
|
||||
auto iter = std::find_if_not(
|
||||
fmt_val.begin(), fmt_val.end(), [](auto cur_char) -> bool {
|
||||
auto check = static_cast<std::uint32_t>(cur_char);
|
||||
return ((check >= 48U && check <= 57U) ||
|
||||
(check >= 97U && check <= 102U));
|
||||
});
|
||||
if (iter != fmt_val.end()) {
|
||||
auto invalid_idx{std::distance(fmt_val.begin(), iter)};
|
||||
throw std::range_error(
|
||||
"invalid character in hex string|" + std::to_string(invalid_idx) +
|
||||
'|' + std::string(1U, str.at(invalid_idx)) + '|' + std::string{str});
|
||||
}
|
||||
|
||||
val.resize(fmt_val.length() / 2U);
|
||||
for (std::size_t idx = 0U; idx < fmt_val.length(); idx += 2U) {
|
||||
val.at(idx / 2U) = static_cast<typename val_t::value_type>(
|
||||
std::strtoul(fmt_val.substr(idx, 2U).c_str(), nullptr, base16));
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
val.clear();
|
||||
return false;
|
||||
}
|
||||
template <typename val_t>
|
||||
inline auto from_hex_string(std::string_view str, val_t &val) -> bool {
|
||||
return from_hex_string_t<val_t>(str, val);
|
||||
}
|
||||
|
||||
template <typename val_t>
|
||||
inline auto from_hex_string(std::wstring_view str, val_t &val) -> bool {
|
||||
return from_hex_string_t<val_t>(utils::string::to_utf8(str), val);
|
||||
}
|
||||
|
||||
template <typename col_t>
|
||||
inline auto remove_element(col_t &collection,
|
||||
@@ -96,16 +148,6 @@ inline auto remove_element(col_t &collection,
|
||||
return collection;
|
||||
}
|
||||
|
||||
template <typename val_t>
|
||||
inline auto from_hex_string(std::string_view str, val_t &val) -> bool {
|
||||
return from_hex_string_t<val_t, std::string>(str, val);
|
||||
}
|
||||
|
||||
template <typename val_t>
|
||||
inline auto from_hex_string(std::wstring_view str, val_t &val) -> bool {
|
||||
return from_hex_string_t<val_t, std::wstring>(str, val);
|
||||
}
|
||||
|
||||
template <typename col_t>
|
||||
inline auto to_hex_string(const col_t &collection) -> std::string {
|
||||
static_assert(sizeof(typename col_t::value_type) == 1U,
|
||||
|
||||
@@ -165,6 +165,50 @@ extern "C" {
|
||||
#endif // defined(__cplusplus)
|
||||
#endif // defined(PROJECT_ENABLE_FZF)
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBDSM)
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif // defined(__cplusplus)
|
||||
#include "bdsm/bdsm.h"
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
struct netbios_ns_deleter final {
|
||||
void operator()(netbios_ns *ns) {
|
||||
if (ns != nullptr) {
|
||||
netbios_ns_destroy(ns);
|
||||
}
|
||||
}
|
||||
};
|
||||
using netbios_ns_t = std::unique_ptr<netbios_ns, netbios_ns_deleter>;
|
||||
|
||||
inline const auto smb_session_deleter = [](smb_session *session) {
|
||||
if (session != nullptr) {
|
||||
smb_session_destroy(session);
|
||||
}
|
||||
};
|
||||
using smb_session_t = std::shared_ptr<smb_session>;
|
||||
|
||||
struct smb_stat_deleter final {
|
||||
void operator()(smb_stat st) {
|
||||
if (st != nullptr) {
|
||||
smb_stat_destroy(st);
|
||||
}
|
||||
}
|
||||
};
|
||||
using smb_stat_t = std::unique_ptr<smb_file, smb_stat_deleter>;
|
||||
|
||||
struct smb_stat_list_deleter final {
|
||||
void operator()(smb_file *list) {
|
||||
if (list != nullptr) {
|
||||
smb_stat_list_destroy(list);
|
||||
}
|
||||
}
|
||||
};
|
||||
using smb_stat_list_t = std::unique_ptr<smb_file, smb_stat_list_deleter>;
|
||||
#endif // defined(__cplusplus)
|
||||
#endif // defined(PROJECT_ENABLE_LIBDSM)
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBEVENT)
|
||||
#include "event2/buffer.h"
|
||||
#include "event2/bufferevent.h"
|
||||
@@ -173,20 +217,68 @@ extern "C" {
|
||||
#include "event2/util.h"
|
||||
#endif // defined(PROJECT_ENABLE_LIBEVENT)
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
||||
#include "sodium.h"
|
||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
||||
|
||||
#if defined(PROJECT_ENABLE_SDL)
|
||||
#include "SDL.h"
|
||||
#include "SDL_gamecontroller.h"
|
||||
#include "SDL_joystick.h"
|
||||
#endif // defined(PROJECT_ENABLE_SDL)
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
||||
#include "sodium.h"
|
||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
||||
|
||||
#if defined(PROJECT_ENABLE_SQLITE)
|
||||
#include "sqlite3.h"
|
||||
#endif // defined(PROJECT_ENABLE_SQLITE)
|
||||
|
||||
#if defined(PROJECT_ENABLE_VLC)
|
||||
#include <vlc/vlc.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
[[nodiscard]] inline auto get_libvlc_error_msg() -> std::string {
|
||||
const auto *msg = libvlc_errmsg();
|
||||
return msg == nullptr ? "none" : msg;
|
||||
}
|
||||
|
||||
struct vlc_deleter final {
|
||||
void operator()(libvlc_instance_t *inst) {
|
||||
if (inst != nullptr) {
|
||||
libvlc_release(inst);
|
||||
}
|
||||
}
|
||||
};
|
||||
using vlc_t = std::unique_ptr<libvlc_instance_t, vlc_deleter>;
|
||||
|
||||
struct vlc_media_deleter final {
|
||||
void operator()(libvlc_media_t *media) {
|
||||
if (media != nullptr) {
|
||||
libvlc_media_release(media);
|
||||
}
|
||||
}
|
||||
};
|
||||
using vlc_media_t = std::unique_ptr<libvlc_media_t, vlc_media_deleter>;
|
||||
|
||||
struct vlc_media_list_deleter final {
|
||||
void operator()(libvlc_media_list_t *media_list) {
|
||||
if (media_list != nullptr) {
|
||||
libvlc_media_list_release(media_list);
|
||||
}
|
||||
}
|
||||
};
|
||||
using vlc_media_list_t =
|
||||
std::unique_ptr<libvlc_media_list_t, vlc_media_list_deleter>;
|
||||
|
||||
struct vlc_string_deleter final {
|
||||
void operator()(char *str) {
|
||||
if (str != nullptr) {
|
||||
libvlc_free(str);
|
||||
}
|
||||
}
|
||||
};
|
||||
using vlc_string_t = std::unique_ptr<char, vlc_string_deleter>;
|
||||
#endif // defined(__cplusplus)
|
||||
#endif // defined(PROJECT_ENABLE_VLC)
|
||||
|
||||
#if !defined(fstat64)
|
||||
#define fstat64 fstat
|
||||
#endif // !defined(fstat64)
|
||||
|
||||
@@ -34,7 +34,7 @@ class encrypting_reader final {
|
||||
public:
|
||||
encrypting_reader(std::string_view file_name, std::string_view source_path,
|
||||
stop_type &stop_requested, std::string_view token,
|
||||
std::optional<std::string_view> relative_parent_path,
|
||||
std::optional<std::string> relative_parent_path,
|
||||
std::size_t error_return = 0U);
|
||||
|
||||
encrypting_reader(std::string_view encrypted_file_path,
|
||||
|
||||
@@ -46,6 +46,12 @@ inline auto generate_key(
|
||||
default_create_hash<hash_t>()) -> hash_t;
|
||||
|
||||
#if defined(PROJECT_ENABLE_BOOST)
|
||||
[[nodiscard]] auto decrypt_file_name(std::string_view encryption_token,
|
||||
std::string &file_name) -> bool;
|
||||
|
||||
[[nodiscard]] auto decrypt_file_path(std::string_view encryption_token,
|
||||
std::string &file_path) -> bool;
|
||||
|
||||
template <typename result_t, typename arr_t, std::size_t arr_size>
|
||||
[[nodiscard]] inline auto decrypt_data(const std::array<arr_t, arr_size> &key,
|
||||
const unsigned char *buffer,
|
||||
|
||||
@@ -25,31 +25,106 @@
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include "utils/path.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace repertory::utils::file {
|
||||
struct i_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<i_fs_item>;
|
||||
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<i_file>;
|
||||
|
||||
virtual ~i_file() = default;
|
||||
|
||||
virtual void close() = 0;
|
||||
|
||||
[[nodiscard]] virtual auto exists() const -> bool = 0;
|
||||
|
||||
virtual void flush() const = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_handle() const -> native_handle = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_path() const -> std::string = 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 move_to(std::string_view new_path) -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
read(data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_read = nullptr) -> 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,
|
||||
@@ -57,64 +132,59 @@ struct i_file {
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
read_all(data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_read = nullptr) -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto remove() -> bool = 0;
|
||||
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 = 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 = 0;
|
||||
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;
|
||||
|
||||
public:
|
||||
[[nodiscard]] virtual operator bool() const = 0;
|
||||
|
||||
protected:
|
||||
i_file() noexcept = default;
|
||||
|
||||
i_file(const i_file &) noexcept = delete;
|
||||
i_file(const i_file &) noexcept = default;
|
||||
|
||||
i_file(i_file &&) noexcept = delete;
|
||||
i_file(i_file &&) noexcept = default;
|
||||
|
||||
auto operator=(i_file &&) noexcept -> i_file & = delete;
|
||||
auto operator=(i_file &&) noexcept -> i_file & = default;
|
||||
|
||||
auto operator=(const i_file &) noexcept -> i_file & = delete;
|
||||
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) -> std::unique_ptr<i_file>;
|
||||
// bool read_only = false) -> fs_file_t;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_file(std::string_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file>;
|
||||
[[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) -> std::unique_ptr<i_file> {
|
||||
[[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) -> std::unique_ptr<i_file>;
|
||||
bool read_only = false) -> fs_file_t;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_or_create_file(std::wstring_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file> {
|
||||
bool read_only = false) -> fs_file_t {
|
||||
return open_or_create_file(utils::string::to_utf8(path), read_only);
|
||||
}
|
||||
|
||||
@@ -179,23 +249,18 @@ public:
|
||||
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(data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_read = nullptr) -> 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
|
||||
read_all(data_buffer &data, 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 {
|
||||
@@ -205,14 +270,8 @@ public:
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto truncate() -> bool override { return truncate(0U); }
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
write(const data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_written = nullptr) -> 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;
|
||||
@@ -240,25 +299,25 @@ class thread_file final : public i_file {
|
||||
public:
|
||||
// [[nodiscard]] static auto
|
||||
// attach_file(native_handle handle,
|
||||
// bool read_only = false) -> std::unique_ptr<i_file>;
|
||||
// bool read_only = false) -> fs_file_t;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_file(std::string_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file>;
|
||||
[[nodiscard]] static auto attach_file(fs_file_t file) -> fs_file_t;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_file(std::wstring_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file> {
|
||||
[[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) -> std::unique_ptr<i_file>;
|
||||
bool read_only = false) -> fs_file_t;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_or_create_file(std::wstring_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file> {
|
||||
bool read_only = false) -> fs_file_t {
|
||||
return open_or_create_file(utils::string::to_utf8(path), read_only);
|
||||
}
|
||||
|
||||
@@ -271,7 +330,7 @@ public:
|
||||
: file_(new file(utils::string::to_utf8(path))) {}
|
||||
|
||||
protected:
|
||||
thread_file(std::unique_ptr<i_file> file);
|
||||
thread_file(fs_file_t file);
|
||||
|
||||
public:
|
||||
thread_file(const thread_file &) = delete;
|
||||
@@ -282,7 +341,7 @@ public:
|
||||
~thread_file() override { close(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<i_file> file_;
|
||||
fs_file_t file_;
|
||||
|
||||
public:
|
||||
void close() override;
|
||||
@@ -303,23 +362,18 @@ public:
|
||||
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(data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_read = nullptr) -> 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
|
||||
read_all(data_buffer &data, 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 {
|
||||
@@ -328,14 +382,8 @@ public:
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto truncate() -> bool override { return truncate(0U); }
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
write(const data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_written = nullptr) -> 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;
|
||||
@@ -356,6 +404,372 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct i_directory : public i_fs_item {
|
||||
using fs_directory_t = std::unique_ptr<i_directory>;
|
||||
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<fs_directory_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
get_file(std::string_view path) const -> fs_file_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_files() const -> std::vector<fs_file_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_items() const -> std::vector<fs_item_t> = 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>;
|
||||
|
||||
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<fs_directory_t> override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_file(std::string_view path) const -> fs_file_t override;
|
||||
|
||||
[[nodiscard]] auto get_files() const -> std::vector<fs_file_t> override;
|
||||
|
||||
[[nodiscard]] auto get_items() const -> std::vector<fs_item_t> 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<smb_fd> 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<smb_fd> 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<smb_directory>;
|
||||
|
||||
[[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<fs_directory_t> override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_file(std::string_view path) const -> fs_file_t override;
|
||||
|
||||
[[nodiscard]] auto get_files() const -> std::vector<fs_file_t> override;
|
||||
|
||||
[[nodiscard]] auto get_items() const -> std::vector<fs_item_t> 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;
|
||||
|
||||
Reference in New Issue
Block a user