7#include "cmake_install.hpp"
8#include "../utility/utility.hpp"
9#include "../metadata/metadata.hpp"
10#include "../macros.hpp"
17#include <system_error>
25hi_warning_ignore_msvc(4702);
31hi_export_module(hikogui.path.path_location : intf);
33hi_export
namespace hi {
36template<
typename Context>
37concept path_range = std::ranges::input_range<Context> and
38 std::convertible_to<std::ranges::range_value_t<std::remove_cvref_t<Context>>, std::filesystem::path> and
39 not std::convertible_to<Context, std::filesystem::path>;
48template<path_range Locations>
49[[nodiscard]]
inline generator<std::filesystem::path>
50find_path(Locations&& locations, std::filesystem::path
const& ref)
noexcept
52 if (ref.is_absolute()) {
53 if (std::filesystem::exists(ref)) {
58 for (
auto const& base : locations) {
59 auto const path = base / ref;
60 if (std::filesystem::exists(path)) {
74[[nodiscard]]
inline generator<std::filesystem::path>
75find_path(std::filesystem::path
const& location, std::filesystem::path
const& ref)
noexcept
77 if (ref.is_absolute()) {
78 if (std::filesystem::exists(ref)) {
83 auto const path = location / ref;
84 if (std::filesystem::exists(path)) {
98template<path_range Locations>
99[[nodiscard]]
inline std::filesystem::path
get_path(Locations&& locations, std::filesystem::path
const& ref)
101 for (
auto const& path :
find_path(locations, ref)) {
105 throw io_error(std::format(
"Could not find '{}' in search-path: {}", ref.string(), to_string(locations)));
116[[nodiscard]]
inline std::filesystem::path
get_path(std::filesystem::path
const& location, std::filesystem::path
const& ref)
118 for (
auto const& path :
find_path(location, ref)) {
122 throw io_error(std::format(
"Could not find '{}' in: {}", ref.string(), location.string()));
133[[nodiscard]]
inline std::filesystem::path
134get_path(std::expected<std::filesystem::path, std::error_code>
const& location, std::filesystem::path
const& ref)
138 std::format(
"Could not find '{}' because of an error at the location: {}", ref.string(), location.error().message()));
141 for (
auto const& path :
find_path(*location, ref)) {
145 throw io_error(std::format(
"Could not find '{}' in: {}", ref.string(), location->string()));
153template<path_range Locations>
154[[nodiscard]]
inline std::string to_string(Locations&& locations)
noexcept
157 for (
auto const& path : locations) {
169[[nodiscard]] std::expected<std::filesystem::path, std::error_code>
executable_file() noexcept;
178 path->remove_filename();
186[[nodiscard]] std::expected<std::filesystem::path, std::error_code>
data_dir() noexcept;
191[[nodiscard]]
std::expected<
std::filesystem::path,
std::error_code>
log_dir() noexcept;
196[[nodiscard]] inline generator<
std::filesystem::path>
resource_dirs() noexcept;
221 static auto r = []() -> std::optional<std::filesystem::path> {
223 if (not executable_dir_) {
229 return tmp->source_dir;
236 return tmp->source_dir;
245[[nodiscard]]
inline std::filesystem::path library_source_dir() noexcept
247 auto path = std::filesystem::path{__FILE__};
248 path.replace_filename(
"../../..");
249 return path.lexically_normal();
252[[nodiscard]]
inline std::filesystem::path library_test_data_dir() noexcept
254 return hi::library_source_dir() /
"tests" /
"data";
generator< std::filesystem::path > find_path(Locations &&locations, std::filesystem::path const &ref) noexcept
Find a path.
Definition path_location_intf.hpp:50
std::expected< std::filesystem::path, std::error_code > log_dir() noexcept
Get the full path to the directory where the application should store its log files.
Definition path_location_win32_impl.hpp:53
generator< std::filesystem::path > resource_dirs() noexcept
The directories to search for resource files.
Definition path_location_win32_impl.hpp:63
std::expected< std::filesystem::path, std::error_code > executable_dir() noexcept
Get the full path to the directory when this executable is located.
Definition path_location_intf.hpp:174
generator< std::filesystem::path > theme_files() noexcept
The directories to search for theme files of the application.
std::expected< std::filesystem::path, std::error_code > executable_file() noexcept
Get the full path to this executable.
Definition path_location_win32_impl.hpp:25
generator< std::filesystem::path > font_files() noexcept
The directories to search for font files of both the application and system.
generator< std::filesystem::path > system_font_dirs() noexcept
The directories to search for system font files.
Definition path_location_win32_impl.hpp:98
std::optional< std::filesystem::path > source_dir() noexcept
Get the full path to source code of this executable.
Definition path_location_intf.hpp:219
std::filesystem::path get_path(Locations &&locations, std::filesystem::path const &ref)
Get a path.
Definition path_location_intf.hpp:99
std::expected< std::filesystem::path, std::error_code > data_dir() noexcept
Get the full path to the directory where the application should store its data.
Definition path_location_win32_impl.hpp:38
The HikoGUI namespace.
Definition array_generic.hpp:20
std::optional< cmake_install > parse_cmake_install(std::filesystem::path path) noexcept
Parse a cmake_install.cmake file.
Definition cmake_install.hpp:28
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Exception thrown during I/O on an error.
Definition exception_intf.hpp:173
Definition path_location_intf.hpp:37