updated build system
This commit is contained in:
@ -307,8 +307,15 @@ using unique_mutex_lock = std::unique_lock<std::mutex>;
|
||||
using unique_recur_mutex_lock = std::unique_lock<std::recursive_mutex>;
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
inline constexpr const auto max_path_length = std::size_t{32767U};
|
||||
#else // !defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
inline constexpr const auto max_path_length = std::size_t{MAX_PATH};
|
||||
#endif // defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
|
||||
using native_handle = HANDLE;
|
||||
#else // !defined(_WIN32)
|
||||
inline constexpr const auto max_path_length = std::size_t{PATH_MAX};
|
||||
using native_handle = int;
|
||||
#if !defined(INVALID_HANDLE_VALUE)
|
||||
#define INVALID_HANDLE_VALUE (-1)
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
utils::encryption::hash_256_t key_;
|
||||
stop_type &stop_requested_;
|
||||
size_t error_return_;
|
||||
utils::file::file source_file_;
|
||||
std::unique_ptr<utils::file::i_file> source_file_;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::size_t, data_buffer> chunk_buffers_;
|
||||
|
@ -24,104 +24,362 @@
|
||||
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include "utils/path.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace repertory::utils::file {
|
||||
class file final {
|
||||
struct 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]] 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(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 = 0;
|
||||
|
||||
[[nodiscard]] virtual auto remove() -> bool = 0;
|
||||
|
||||
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(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;
|
||||
|
||||
[[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]] static auto attach_file(native_handle handle,
|
||||
bool read_only = false) -> file;
|
||||
[[nodiscard]] virtual operator bool() const = 0;
|
||||
|
||||
[[nodiscard]] static auto open_file(std::filesystem::path path,
|
||||
bool read_only = false) -> file;
|
||||
protected:
|
||||
i_file() noexcept = default;
|
||||
|
||||
[[nodiscard]] static auto open_or_create_file(std::filesystem::path path,
|
||||
bool read_only = false) -> file;
|
||||
i_file(const i_file &) noexcept = delete;
|
||||
|
||||
i_file(i_file &&) noexcept = delete;
|
||||
|
||||
auto operator=(i_file &&) noexcept -> i_file & = delete;
|
||||
|
||||
auto operator=(const i_file &) noexcept -> i_file & = delete;
|
||||
};
|
||||
|
||||
class file final : public i_file {
|
||||
public:
|
||||
[[nodiscard]] static auto
|
||||
attach_file(native_handle handle,
|
||||
bool read_only = false) -> std::unique_ptr<i_file>;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_file(std::string_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file>;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_file(std::wstring_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file> {
|
||||
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>;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_or_create_file(std::wstring_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file> {
|
||||
return open_or_create_file(utils::string::to_utf8(path), read_only);
|
||||
}
|
||||
|
||||
public:
|
||||
file() noexcept = default;
|
||||
|
||||
protected:
|
||||
file(file_t file_ptr, std::filesystem::path path)
|
||||
: file_(std::move(file_ptr)), path_(std::move(path)) {}
|
||||
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_))
|
||||
path_(std::move(move_file.path_)),
|
||||
read_only_(move_file.read_only_)
|
||||
#if defined(_WIN32)
|
||||
,
|
||||
mtx_()
|
||||
mtx_(std::move(move_file.mtx_))
|
||||
#endif // defined(_WIN32)
|
||||
{
|
||||
}
|
||||
|
||||
~file() { close(); }
|
||||
~file() override { close(); }
|
||||
|
||||
private:
|
||||
file_t file_;
|
||||
std::string path_;
|
||||
bool read_only_{false};
|
||||
#if defined(_WIN32)
|
||||
mutable std::unique_ptr<std::recursive_mutex> 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 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 {
|
||||
read_buffer_size = size;
|
||||
return read_buffer_size;
|
||||
}
|
||||
|
||||
[[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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private:
|
||||
file_t file_{nullptr};
|
||||
std::filesystem::path path_;
|
||||
#if defined(_WIN32)
|
||||
mutable std::recursive_mutex mtx_{};
|
||||
#endif // defined(_WIN32)
|
||||
[[nodiscard]] operator bool() const override { return file_ != nullptr; }
|
||||
};
|
||||
|
||||
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>;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_file(std::string_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file>;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_file(std::wstring_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file> {
|
||||
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>;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
open_or_create_file(std::wstring_view path,
|
||||
bool read_only = false) -> std::unique_ptr<i_file> {
|
||||
return open_or_create_file(utils::string::to_utf8(path), read_only);
|
||||
}
|
||||
|
||||
public:
|
||||
void close();
|
||||
thread_file() noexcept = default;
|
||||
|
||||
void flush();
|
||||
thread_file(std::string_view path) : file_(new file(path)) {}
|
||||
|
||||
[[nodiscard]] auto get_handle() const -> native_handle;
|
||||
thread_file(std::wstring_view path)
|
||||
: file_(new file(utils::string::to_utf8(path))) {}
|
||||
|
||||
[[nodiscard]] auto get_path() const -> std::filesystem::path { return path_; }
|
||||
protected:
|
||||
thread_file(std::unique_ptr<i_file> file);
|
||||
|
||||
[[nodiscard]] auto move_to(std::filesystem::path new_path) -> bool;
|
||||
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:
|
||||
std::unique_ptr<i_file> 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 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;
|
||||
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;
|
||||
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;
|
||||
[[nodiscard]] auto
|
||||
read_all(data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_read = nullptr) -> bool override;
|
||||
|
||||
[[nodiscard]] auto remove() -> bool;
|
||||
[[nodiscard]] auto remove() -> bool override;
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t;
|
||||
auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override {
|
||||
return file_->set_read_buffer_size(size);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto truncate() -> bool { return truncate(0U); }
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool;
|
||||
[[nodiscard]] auto truncate() -> bool override { return truncate(0U); }
|
||||
|
||||
[[nodiscard]] auto write(const data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_written = nullptr) -> bool;
|
||||
[[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;
|
||||
[[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;
|
||||
|
||||
public:
|
||||
[[nodiscard]] operator bool() const { return file_ != nullptr; }
|
||||
[[nodiscard]] operator bool() const override {
|
||||
return static_cast<bool>(*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;
|
||||
}
|
||||
};
|
||||
|
||||
[[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;
|
||||
@ -130,6 +388,12 @@ public:
|
||||
|
||||
[[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
|
||||
@ -161,6 +425,21 @@ read_json_file(std::string_view path, nlohmann::json &data,
|
||||
const nlohmann::json &data) -> bool;
|
||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||
#endif // defined(PROJECT_ENABLE_JSON)
|
||||
|
||||
template <typename string_t>
|
||||
inline auto directory_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> sub_directory)
|
||||
-> bool {
|
||||
return is_directory(utils::path::combine(path, {sub_directory}));
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
inline auto file_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> file_name) -> bool {
|
||||
return is_file(utils::path::combine(path, {file_name}));
|
||||
}
|
||||
} // namespace repertory::utils::file
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_FILE_HPP_
|
||||
|
@ -30,8 +30,12 @@ inline constexpr const std::string_view backslash{"\\"};
|
||||
inline constexpr const std::wstring_view backslash_w{L"\\"};
|
||||
inline constexpr const std::string_view dot{"."};
|
||||
inline constexpr const std::wstring_view dot_w{L"."};
|
||||
inline constexpr const std::string_view dot_backslash{".\\"};
|
||||
inline constexpr const std::wstring_view dot_backslash_w{L".\\"};
|
||||
inline constexpr const std::string_view dot_slash{"./"};
|
||||
inline constexpr const std::wstring_view dot_slash_w{L"./"};
|
||||
inline constexpr const std::string_view long_notation{"\\\\?\\"};
|
||||
inline constexpr const std::wstring_view long_notation_w{L"\\\\?\\"};
|
||||
inline constexpr const std::string_view slash{"/"};
|
||||
inline constexpr const std::wstring_view slash_w{L"/"};
|
||||
#if defined(_WIN32)
|
||||
@ -62,53 +66,6 @@ get_backslash<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return backslash_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto get_dot() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot<char>() -> std::basic_string_view<char> {
|
||||
return dot;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return dot_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_slash() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_slash<char>() -> std::basic_string_view<char> {
|
||||
return dot_slash;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_slash<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return dot_slash_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_slash() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_slash<char>() -> std::basic_string_view<char> {
|
||||
return slash;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_slash<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return slash_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_directory_seperator() -> std::basic_string_view<char_t>;
|
||||
@ -141,16 +98,98 @@ get_not_directory_seperator<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return not_directory_seperator_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto get_dot() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot<char>() -> std::basic_string_view<char> {
|
||||
return dot;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return dot_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_backslash() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_backslash<char>() -> std::basic_string_view<char> {
|
||||
return dot_backslash;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_backslash<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return dot_backslash_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_slash() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_slash<char>() -> std::basic_string_view<char> {
|
||||
return dot_slash;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_dot_slash<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return dot_slash_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_long_notation() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_long_notation<char>() -> std::basic_string_view<char> {
|
||||
return long_notation;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_long_notation<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return long_notation_w;
|
||||
}
|
||||
|
||||
template <typename char_t>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_slash() -> std::basic_string_view<char_t>;
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_slash<char>() -> std::basic_string_view<char> {
|
||||
return slash;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline constexpr auto
|
||||
get_slash<wchar_t>() -> std::basic_string_view<wchar_t> {
|
||||
return slash_w;
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
[[nodiscard]] inline auto get_current_path() -> string_t;
|
||||
|
||||
[[nodiscard]] auto absolute(std::string_view path) -> std::string;
|
||||
|
||||
[[nodiscard]] auto absolute(std::wstring_view path) -> std::wstring;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
combine(std::string path,
|
||||
combine(std::string_view path,
|
||||
const std::vector<std::string_view> &paths) -> std::string;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
combine(std::wstring path,
|
||||
combine(std::wstring_view path,
|
||||
const std::vector<std::wstring_view> &paths) -> std::wstring;
|
||||
|
||||
[[nodiscard]] auto inline create_api_path(std::string_view path) -> std::string;
|
||||
@ -158,27 +197,12 @@ combine(std::wstring path,
|
||||
[[nodiscard]] auto inline create_api_path(std::wstring_view path)
|
||||
-> std::wstring;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
file_exists_in_path(std::string_view path, std::string_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto finalize(std::string_view path) -> std::string;
|
||||
|
||||
[[nodiscard]] inline auto finalize(std::wstring_view path) -> std::wstring;
|
||||
|
||||
[[nodiscard]] auto
|
||||
find_program_in_path(const std::string &name_without_extension) -> std::string;
|
||||
[[nodiscard]] auto find_program_in_path(
|
||||
const std::string_view &name_without_extension) -> std::string;
|
||||
|
||||
[[nodiscard]] auto
|
||||
find_program_in_path(std::wstring_view name_without_extension) -> std::wstring;
|
||||
@ -208,10 +232,6 @@ get_parent_api_path(std::wstring_view path) -> std::wstring;
|
||||
|
||||
[[nodiscard]] auto make_file_uri(std::wstring_view path) -> std::wstring;
|
||||
|
||||
[[nodiscard]] auto remove_file_name(std::string_view path) -> std::string;
|
||||
|
||||
[[nodiscard]] auto remove_file_name(std::wstring_view path) -> std::wstring;
|
||||
|
||||
[[nodiscard]] auto strip_to_file_name(std::string path) -> std::string;
|
||||
|
||||
[[nodiscard]] auto strip_to_file_name(std::wstring path) -> std::wstring;
|
||||
@ -222,31 +242,30 @@ get_parent_api_path(std::wstring_view path) -> std::wstring;
|
||||
|
||||
template <typename string_t>
|
||||
[[nodiscard]] inline auto combine_t(
|
||||
string_t path,
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
const std::vector<std::basic_string_view<typename string_t::value_type>>
|
||||
&paths) -> string_t {
|
||||
path = std::accumulate(
|
||||
paths.begin(), paths.end(), path, [](auto next_path, auto &&path_part) {
|
||||
if (next_path.empty()) {
|
||||
return string_t{path_part};
|
||||
}
|
||||
auto dir_sep_t =
|
||||
string_t{get_directory_seperator<typename string_t::value_type>()};
|
||||
return absolute(
|
||||
std::accumulate(paths.begin(), paths.end(),
|
||||
std::basic_string<typename string_t::value_type>{path},
|
||||
[&dir_sep_t](auto next_path, auto &&path_part) {
|
||||
if (next_path.empty()) {
|
||||
return string_t{path_part};
|
||||
}
|
||||
|
||||
return next_path +
|
||||
string_t{
|
||||
get_directory_seperator<typename string_t::value_type>()} +
|
||||
string_t{path_part};
|
||||
});
|
||||
|
||||
return absolute(path);
|
||||
return next_path + dir_sep_t + string_t{path_part};
|
||||
}));
|
||||
}
|
||||
|
||||
inline auto combine(std::string path,
|
||||
inline auto combine(std::string_view path,
|
||||
const std::vector<std::string_view> &paths) -> std::string {
|
||||
return combine_t<std::string>(path, paths);
|
||||
}
|
||||
|
||||
inline auto
|
||||
combine(std::wstring path,
|
||||
combine(std::wstring_view path,
|
||||
const std::vector<std::wstring_view> &paths) -> std::wstring {
|
||||
return combine_t<std::wstring>(path, paths);
|
||||
}
|
||||
@ -255,12 +274,20 @@ template <typename string_t>
|
||||
[[nodiscard]] inline auto create_api_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path) -> string_t {
|
||||
auto backslash_t = get_backslash<typename string_t::value_type>();
|
||||
auto dot_t = get_dot<typename string_t::value_type>();
|
||||
auto dot_backslash_t = get_dot_backslash<typename string_t::value_type>();
|
||||
auto dot_slash_t = get_dot_slash<typename string_t::value_type>();
|
||||
auto dot_t = get_dot<typename string_t::value_type>();
|
||||
auto slash_t = get_slash<typename string_t::value_type>();
|
||||
|
||||
#if defined(_WIN32)
|
||||
auto long_notation_t = get_long_notation<typename string_t::value_type>();
|
||||
if (utils::string::begins_with(path, long_notation_t)) {
|
||||
path = path.substr(long_notation_t.size());
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (path.empty() || path == backslash_t || path == dot_t ||
|
||||
path == dot_slash_t || path == slash_t) {
|
||||
path == dot_slash_t || path == slash_t || path == dot_backslash_t) {
|
||||
return string_t{slash_t};
|
||||
}
|
||||
|
||||
@ -292,50 +319,52 @@ inline auto create_api_path(std::wstring_view path) -> std::wstring {
|
||||
return create_api_path_t<std::wstring>(path);
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
[[nodiscard]] inline auto directory_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> sub_directory)
|
||||
-> bool {
|
||||
return std::filesystem::is_directory(
|
||||
std::filesystem::path(path).append(sub_directory));
|
||||
}
|
||||
|
||||
inline auto directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::string>(path, sub_directory);
|
||||
}
|
||||
|
||||
inline auto directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::wstring>(path, sub_directory);
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
[[nodiscard]] inline auto file_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> file_name) -> bool {
|
||||
return std::filesystem::is_regular_file(
|
||||
std::filesystem::path(path).append(file_name));
|
||||
}
|
||||
|
||||
inline auto file_exists_in_path(std::string_view path,
|
||||
std::string_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::string>(path, file_name);
|
||||
}
|
||||
|
||||
inline auto file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::wstring>(path, file_name);
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
[[nodiscard]] inline auto finalize_t(
|
||||
std::basic_string_view<typename string_t::value_type> path) -> string_t {
|
||||
string_t dir_sep_t{get_directory_seperator<typename string_t::value_type>()};
|
||||
string_t fmt_path{path};
|
||||
format_path(fmt_path,
|
||||
get_directory_seperator<typename string_t::value_type>(),
|
||||
if (fmt_path.empty()) {
|
||||
return fmt_path;
|
||||
}
|
||||
|
||||
format_path(fmt_path, dir_sep_t,
|
||||
get_not_directory_seperator<typename string_t::value_type>());
|
||||
|
||||
#if defined(_WIN32)
|
||||
auto dot_t = get_dot<typename string_t::value_type>();
|
||||
auto dot_sep_t = string_t{dot_t} + dir_sep_t;
|
||||
if (fmt_path == dot_t || fmt_path == dot_sep_t) {
|
||||
return get_current_path<string_t>();
|
||||
}
|
||||
|
||||
if (fmt_path == dir_sep_t) {
|
||||
#if defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
return get_current_path<string_t>().substr(0U, long_notation.size() + 2U);
|
||||
#else // !defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
return get_current_path<string_t>().substr(0U, 2U);
|
||||
#endif // defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
}
|
||||
|
||||
if (utils::string::begins_with(fmt_path, dir_sep_t)) {
|
||||
#if defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
return get_current_path<string_t>().substr(0U, long_notation.size() + 2U) +
|
||||
fmt_path;
|
||||
#else // !defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
return get_current_path<string_t>().substr(0U, 2U) + fmt_path;
|
||||
#endif // defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
}
|
||||
|
||||
if (utils::string::begins_with(fmt_path, dot_sep_t)) {
|
||||
return get_current_path<string_t>() + dir_sep_t + fmt_path.substr(2U);
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
return string_t{get_long_notation<typename string_t::value_type>()} +
|
||||
fmt_path;
|
||||
#endif // defined(PROJECT_ENABLE_WIN32_LONG_PATH_NAMES)
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
return fmt_path;
|
||||
}
|
||||
|
||||
@ -355,6 +384,13 @@ format_path(string_t &path,
|
||||
-> string_t & {
|
||||
utils::string::replace(path, not_sep, sep);
|
||||
|
||||
#if defined(_WIN32)
|
||||
auto long_notation_t = get_long_notation<typename string_t::value_type>();
|
||||
if (utils::string::begins_with(path, long_notation_t)) {
|
||||
path = path.substr(long_notation_t.size());
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
string_t double_sep(2U, sep.at(0U));
|
||||
while (utils::string::contains(path, double_sep)) {
|
||||
utils::string::replace(path, double_sep, sep);
|
||||
@ -373,6 +409,24 @@ format_path(string_t &path,
|
||||
return path;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline auto get_current_path<std::string>() -> std::string {
|
||||
#if defined(_WIN32)
|
||||
std::string path;
|
||||
path.resize(repertory::max_path_length + 1);
|
||||
::GetCurrentDirectoryA(static_cast<DWORD>(path.size()), path.data());
|
||||
path = path.c_str();
|
||||
return finalize(path);
|
||||
#else // !defined(_WIN32)
|
||||
return finalize(std::filesystem::current_path().string());
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline auto get_current_path<std::wstring>() -> std::wstring {
|
||||
return utils::string::from_utf8(get_current_path<std::string>());
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
[[nodiscard]] inline auto get_parent_api_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path) -> string_t {
|
||||
@ -383,12 +437,12 @@ template <typename string_t>
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = path.substr(0, path.rfind('/') + 1);
|
||||
ret = path.substr(0, path.rfind(slash_t) + 1);
|
||||
if (ret == slash_t) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return utils::string::right_trim(ret, '/');
|
||||
return utils::string::right_trim(ret, slash_t.at(0U));
|
||||
}
|
||||
|
||||
inline auto get_parent_api_path(std::string_view path) -> std::string {
|
||||
|
Reference in New Issue
Block a user