This commit is contained in:
6
support/3rd_party/include/utils/file.hpp
vendored
6
support/3rd_party/include/utils/file.hpp
vendored
@ -116,7 +116,7 @@ private:
|
|||||||
[[nodiscard]] auto is_file(std::wstring_view path) -> bool;
|
[[nodiscard]] auto is_file(std::wstring_view path) -> bool;
|
||||||
|
|
||||||
#if defined(PROJECT_ENABLE_JSON)
|
#if defined(PROJECT_ENABLE_JSON)
|
||||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto
|
||||||
read_json_file(std::string_view path, nlohmann::json &data,
|
read_json_file(std::string_view path, nlohmann::json &data,
|
||||||
std::optional<std::string_view> password = std::nullopt) -> bool;
|
std::optional<std::string_view> password = std::nullopt) -> bool;
|
||||||
@ -132,7 +132,7 @@ read_json_file(std::string_view path, nlohmann::json &data,
|
|||||||
[[nodiscard]] auto write_json_file(
|
[[nodiscard]] auto write_json_file(
|
||||||
std::wstring_view path, const nlohmann::json &data,
|
std::wstring_view path, const nlohmann::json &data,
|
||||||
std::optional<std::wstring_view> password = std::nullopt) -> bool;
|
std::optional<std::wstring_view> password = std::nullopt) -> bool;
|
||||||
#else // !defined(PROJECT_ENABLE_LIBSODIUM)
|
#else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
[[nodiscard]] auto read_json_file(std::string_view path,
|
[[nodiscard]] auto read_json_file(std::string_view path,
|
||||||
nlohmann::json &data) -> bool;
|
nlohmann::json &data) -> bool;
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ read_json_file(std::string_view path, nlohmann::json &data,
|
|||||||
|
|
||||||
[[nodiscard]] auto write_json_file(std::wstring_view path,
|
[[nodiscard]] auto write_json_file(std::wstring_view path,
|
||||||
const nlohmann::json &data) -> bool;
|
const nlohmann::json &data) -> bool;
|
||||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
#endif // defined(PROJECT_ENABLE_JSON)
|
#endif // defined(PROJECT_ENABLE_JSON)
|
||||||
} // namespace repertory::utils::file
|
} // namespace repertory::utils::file
|
||||||
|
|
||||||
|
24
support/3rd_party/src/utils/file.cpp
vendored
24
support/3rd_party/src/utils/file.cpp
vendored
@ -242,12 +242,12 @@ auto is_file(std::wstring_view path) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PROJECT_ENABLE_JSON)
|
#if defined(PROJECT_ENABLE_JSON)
|
||||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
auto read_json_file(std::string_view path, nlohmann::json &data,
|
auto read_json_file(std::string_view path, nlohmann::json &data,
|
||||||
std::optional<std::string_view> password) -> bool {
|
std::optional<std::string_view> password) -> bool {
|
||||||
#else // !defined(PROJECT_ENABLE_LIBSODIUM)
|
#else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
|
auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
|
||||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
static constexpr const std::string_view function_name{
|
static constexpr const std::string_view function_name{
|
||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
};
|
};
|
||||||
@ -272,13 +272,13 @@ auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
|
|||||||
stream << file_stream.rdbuf();
|
stream << file_stream.rdbuf();
|
||||||
|
|
||||||
auto json_text = stream.str();
|
auto json_text = stream.str();
|
||||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
if (password.has_value()) {
|
if (password.has_value()) {
|
||||||
auto decrypted_data =
|
auto decrypted_data =
|
||||||
utils::encryption::decrypt_data(json_text, *password);
|
utils::encryption::decrypt_data(json_text, *password);
|
||||||
json_text = {decrypted_data.begin(), decrypted_data.end()};
|
json_text = {decrypted_data.begin(), decrypted_data.end()};
|
||||||
}
|
}
|
||||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
if (not json_text.empty()) {
|
if (not json_text.empty()) {
|
||||||
data = nlohmann::json::parse(json_text.c_str());
|
data = nlohmann::json::parse(json_text.c_str());
|
||||||
}
|
}
|
||||||
@ -301,13 +301,13 @@ auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
auto write_json_file(std::string_view path, const nlohmann::json &data,
|
auto write_json_file(std::string_view path, const nlohmann::json &data,
|
||||||
std::optional<std::string_view> password) -> bool {
|
std::optional<std::string_view> password) -> bool {
|
||||||
#else // !defined(PROJECT_ENABLE_LIBSODIUM)
|
#else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
auto write_json_file(std::string_view path,
|
auto write_json_file(std::string_view path,
|
||||||
const nlohmann::json &data) -> bool {
|
const nlohmann::json &data) -> bool {
|
||||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
static constexpr const std::string_view function_name{
|
static constexpr const std::string_view function_name{
|
||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
};
|
};
|
||||||
@ -319,7 +319,7 @@ auto write_json_file(std::string_view path,
|
|||||||
file.get_error_code().message());
|
file.get_error_code().message());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
if (password.has_value()) {
|
if (password.has_value()) {
|
||||||
return file.write(utils::encryption::encrypt_data(data.dump(), *password),
|
return file.write(utils::encryption::encrypt_data(data.dump(), *password),
|
||||||
0U);
|
0U);
|
||||||
@ -336,7 +336,7 @@ auto write_json_file(std::string_view path,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PROJECT_ENABLE_LIBSODIUM)
|
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
auto read_json_file(std::wstring_view path, nlohmann::json &data,
|
auto read_json_file(std::wstring_view path, nlohmann::json &data,
|
||||||
std::optional<std::wstring_view> password) -> bool {
|
std::optional<std::wstring_view> password) -> bool {
|
||||||
if (password.has_value()) {
|
if (password.has_value()) {
|
||||||
@ -356,7 +356,7 @@ auto write_json_file(std::wstring_view path, const nlohmann::json &data,
|
|||||||
|
|
||||||
return write_json_file(utils::string::to_utf8(path), data, std::nullopt);
|
return write_json_file(utils::string::to_utf8(path), data, std::nullopt);
|
||||||
}
|
}
|
||||||
#else // !defined(PROJECT_ENABLE_LIBSODIUM)
|
#else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
auto read_json_file(std::wstring_view path, nlohmann::json &data) -> bool {
|
auto read_json_file(std::wstring_view path, nlohmann::json &data) -> bool {
|
||||||
return read_json_file(utils::string::to_utf8(path), data);
|
return read_json_file(utils::string::to_utf8(path), data);
|
||||||
}
|
}
|
||||||
@ -365,6 +365,6 @@ auto write_json_file(std::wstring_view path,
|
|||||||
const nlohmann::json &data) -> bool {
|
const nlohmann::json &data) -> bool {
|
||||||
return write_json_file(utils::string::to_utf8(path), data);
|
return write_json_file(utils::string::to_utf8(path), data);
|
||||||
}
|
}
|
||||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||||
#endif // defined(PROJECT_ENABLE_JSON)
|
#endif // defined(PROJECT_ENABLE_JSON)
|
||||||
} // namespace repertory::utils::file
|
} // namespace repertory::utils::file
|
||||||
|
Reference in New Issue
Block a user